// JavaScript Document

$(document).ready(function(){
	$('ul#slideshow').hpSlideshow({
			speed: 1000,
			timeout: 5000,
			type: 'sequence',
			containerheight: '360px',
			containerwidth: '950px'
	});
	$('ul#slideshow').goToSlide(0, 'pause');
		
	$('#specialsBtn').bind('mouseenter', function(e) {
		$(this).data('pulse').should_stop = true;
		$(this).find("img").fadeTo(0).css('display','none');
	}).bind('mouseleave', function(e) {
		$(this).at_intervals(pulseBtn, {delay: 5000, name: 'pulse'});
	});
	
	var currentThumb;
	$('.thumb').hover(function(){
		if(currentThumb != ''){
			$(currentThumb).removeClass('showMe').addClass('noShow');
		}
		var newThumb = "." + $(this).attr('name');
		$(newThumb).removeClass('noShow');
		currentThumb = newThumb;	
	}, function(){
		var newThumb = "." + $(this).attr('name');
		$(newThumb).addClass('noShow');
	});

	$('#contentTrigger a').toggle(function() {
		$('.content').show();
		$('.tempContent').hide();
		$(this).text('Click To Hide');
	},function() {
		$('.content').hide();
		$('.tempContent').show();
		$(this).text('Read More');
	});
	
});

function setCookie(cookieName,value,exdays){
	// Set the expiration date
	var dateExpire = new Date();
	dateExpire.setDate(dateExpire.getDate() + exdays);
	// Set the value of the cookie to VALUE; expires = EXDAYS
	var cookieValue = escape(value) + ((exdays==null) ? "" : "; expires="+dateExpire.toUTCString());
	document.cookie=cookieName + "=" + cookieValue;
}

function getCookie(cookieName){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==cookieName){
			return unescape(y);
		}
	}
}

function hideIntro(){
	$(document).ready(function(){
		$('#introBox').addClass('introHide');
		$('#introBox').removeClass('introShow');
		$('ul#slideshow').goToSlide(0,'play');
	});
}

function showIntro(){
	//alert('Here it comes!');
	var thisURL = location.protocol + "//" + location.host + "/";
	params_wideworld = {menu:'false',allowscriptaccess:'always',wmode:'transparent'};
	flashvars_wideworld = {siteid:s,servername:thisURL};
	attributes_wideworld = {};
	swfobject.embedSWF("/sitespecific/FerrariMaseratiofPalmBeach/hpAssets/intro.swf", "intro", "950", "360", "9.0.0",false,flashvars_wideworld,params_wideworld,attributes_wideworld);
}

function checkCookie(){
	var firstTimeVisit=getCookie("firstTimeVisitPalmBeach");
	if (firstTimeVisit != undefined){   
		//alert("don't show intro");
		$(document).ready(function(){
			$('#introBox').remove();
			$('ul#slideshow').goToSlide(0,'play');
		});
	} else {										
		//alert("you get an intro!");
		showIntro();
		setCookie("firstTimeVisitPalmBeach",false,5);  // Set the cookie to false, expires after 5 days.
	}
}

checkCookie();
/*

*/
  

