/***************************
 * SITE-SPECIFIC FUNCTIONS *
 ***************************/
 function showSignup() {
	$('#clickHere').slideUp('fast',function(){
		$('#signup').slideDown('slow');
	});
}
 
/*********************
 * UTILITY FUNCTIONS *
 *********************/
 
function sendMail(user,domain,tld,subject,message) {
	if (!user) user = 'alan';
	if (!domain) domain = 'hifibuysnashville';
	if (!tld) tld = 'com';
	locationstring = 'mailto:' + user + '@' + domain + '.' + tld;
	if (subject) locationstring += '?subject=' + encodeURIComponent(subject);
	if (message) locationstring += '&body=' + encodeURIComponent(message);
	window.location = locationstring;
}

function sendExternalMail(subject,message,cc) {
	locationstring = 'mailto:';
	if (subject) locationstring += "?subject=" + encodeURIComponent(subject);
	if (message) locationstring += "&body=" + encodeURIComponent(message);
	if (cc) locationstring += "&cc=" + encodeURIComponent(cc);
	window.location = locationstring;
}

function openWindow(url,features) {
	var newWin = window.open(url,'popup',features);
	newWin.focus();
}

function closeWindow() {
	if (window.opener) {
		self.close();	
	}
}

function printPage() {
	if (window.print != null) {
		window.print();
	}
	else {
		alert("To print this page, please select Print from your browser's File menu.");
	}
}

function preload() {
	var path = '/images/';
	var images = new Array('');
	var preload = new Array('');
	var j = images.length;
	for (var i=0; i<images.length; i++) {
		preload[j] = new Image;
		preload[j++].src = path + images[i];
	}
}

function makeExternalLinks(){
    $('a, area').filter(function(){
        return this.hostname && this.hostname != location.hostname;
    })
	 .attr({
		target: "_blank", 
		title: "Opens in a new window"
	})
	.not(':has(img)')
	.addClass('external');
}

function handleLinkedFiles() {
	// Open linked files in a new window
	$('a').filter(function() {
        return (/(pdf$)|(doc$)|(ppt$)|(pps$)/i).test( $(this).attr('href'));
	}).attr('target','_blank');
	// Assign a class to link
	$('a[href$=.pdf]').not('a:has(img)').addClass('pdf-link');
}

function makeRollovers(){
	$('a.rollover').each(function() { // preload over states
		var img = new Image();
		var upimage = $(this).find('img').attr('src');
		img.src = upimage.replace('_up','_ov');
	});
	$('a.rollover').hover(
		function(){
			var overimage = $(this).find('img').attr('src').replace('_up','_ov');
			$(this).find('img').attr('src',overimage);
		},
		function(){
			var upimage = $(this).find('img').attr('src').replace('_ov','_up');
			$(this).find('img').attr('src',upimage);
		}
	);
}

function makeActionLinks() {
	$('a.action').append(' &#187;');
}

function init() {
	makeExternalLinks();
	handleLinkedFiles();
	makeRollovers();
	makeActionLinks();
	$('a[href*=sony.com], .sony').attr('title','Sony Showcase').colorbox({innerWidth:640, innerHeight:660, iframe:true, href:'/sony-showcase.php'});
	$('#mfr').change(function(){
		var hyperlink = $(this).val();
		if (/.*sony.*/.test(hyperlink)) {
			$.fn.colorbox({innerWidth:640, innerHeight:660, iframe:true, href:'/sony-showcase.php', open:true});
			$(this).find('option:first').attr('selected', 'selected').parent('select');
		} else {
			openWindow(hyperlink);
			$(this).find('option:first').attr('selected', 'selected').parent('select');
		}
	});
	$('#social-networking a:eq(0)').css('margin-right','20px');
	$('a[href*=sony.com], .sony').attr('title','Sony Showcase').colorbox({innerWidth:640, innerHeight:660, iframe:true, href:'/sony-showcase.php'});
	$('#mfr').change(function(){
		var hyperlink = $(this).val();
		if (/.*sony.*/.test(hyperlink)) {
			$.fn.colorbox({innerWidth:640, innerHeight:660, iframe:true, href:'/sony-showcase.php', open:true});
			$(this).find('option:first').attr('selected', 'selected').parent('select');
			return false;
		} else {
			openWindow(hyperlink);
			$(this).find('option:first').attr('selected', 'selected').parent('select');
		}
	});
}

//swfobject.embedSWF("/flash/nav_v3.swf", "navigation", "248", "277", "7", false, {'currPage':currPage}, null , null);