//<![CDATA[

function showModal(id) {
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});

	//transition effect		
	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo("slow",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	//Set the popup window to center
	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);

	//transition effect
	$(id).fadeIn(2000); 	
}

function hideModal(id) {
	$('#mask').fadeOut(1000);
	$('#mask').fadeTo("slow", 0);
	
	$(id).fadeOut(2000);
}

$(document).ready( function() {

	// PNGFix!
	$(".pngfix").pngfix();
	
	// Show the navigation
	showNavigation();

	// Setup what's hot
	$('div#whats_hot div.read_more a').click( toggleWhatsHot );
	$('div#whats_hot div.close a').click( toggleWhatsHot );

	// Setup just sayin'
	$('div#just_sayin div.read_more a').click( toggleJustSayin );
	$('div#just_sayin div.close a').click( toggleJustSayin );
	$("div#just_sayin div.close").hide();

	// Set up the on submit modal
	$("#submit_form").submit( function() {
		showModal('#thanks_modal');
		
		// Ajax submit
		//$.post('email.php', $('#submit_form').serialize());
		
		return false;
	})
	
	// Close modal window
	$('#thanks_modal').hide();
	$('#thanks_modal').click( function() {
		hideModal('#thanks_modal')
	})
	
	// Hide products
	$('div.product').hide();
	
	// Set up product close buttons
	$("div.product div.close a").click( function() {
		$("div.product#" + this.name).fadeOut();
	})
	
	
})

// Embed the flash navigaiton
function showNavigation()
{
	var so = new SWFObject('nav.swf', 'nav', '295', '925', '9.0.159.0');
    // so.useExpressInstall('js/expressinstall.swf');
			so.addParam("wmode", "transparent");
			so.addParam("menu", "false");
			so.addParam("salign", "lt");
		so.write('nav');
}

// Function for toggling the just_sayin' copy display state
function toggleJustSayin() {
	// Toggle the show more
	$("div#just_sayin div.more").toggle('slow')
	
	$("div#just_sayin div.read_more").toggle();
	
	$("div#just_sayin div.close").toggle();
}

// Function for toggling the whats-hot copy

function toggleWhatsHot() {
	var visible = ($('#whats_hot div.content').css('width') == '330px');

	// Toggle the buttons
	if(visible) {
		$('div#whats_hot div.close a').show();
		$('div#whats_hot div.read_more a').hide();		
	} else {
		$('div#whats_hot div.close a').hide();
		$('div#whats_hot div.read_more a').show();
	}
	
	
	// $('#whats_hot_copy p.right').toggle('fast');
	
	
	// Expand or collapse the content
	$('div#whats_hot div.content').animate({
		width: (visible) ? '435px' : '330px',
		height: (visible) ? '410px' : '160px'
	}, .5 * 1000);
	
}

var currentProduct;

function showProduct(name)
{
	if(currentProduct) {
		currentProduct.fadeOut();
	}
	
	var obj = $('div.product[name=' + name + ']');
	var y_inc = parseInt( obj.attr('id').split('_')[1] ) - 1;

	obj.css('top', (270 + (100 * y_inc)) + 'px')

	obj.fadeIn();
	obj.animate({ width: '460px', height: '180px' });
	
	currentProduct = obj;
}
//]]
