$(document).ready(function() {
	
// the intro page does not show the logo slogan and the navigation
$("#box, .slogan, .logo").hide(0);

// this turns on/off the cookies function. // you can choose to ALWAYS show the animated petal intro, Or to only show it once every 30 days
var cookies = "off" // possible options are:   "off"  , "on"

if (cookies === "on") {

// We get todays date and add 30 days to it
	 var now = new Date();
	 now.setDate(now.getDate()+14); 




// we check if the visitor has visited this website before in the last 14 days.
// if so we show the user the normal non-animated petal photo
	if( $.cookies.get('been_here_before') === 'yes' ) {
		$(startStatic);	
	} 

// we check if the visitor has visited this website before in the last 14 days.
// if NOT so we show the user the "animated" petal show. 
	if( $.cookies.get('been_here_before') === null ) {
		$(launchPetalShow);	
	}

// if user has not visited in the last 30 days we set a cookie that will expire in 14 days
	if( $.cookies.get('been_here_before') === null ) {
		$.cookies.set('been_here_before', 'yes',  { expiresAt: new Date( now ) });	
	}
	// $.cookies.del('been_here_before');
	// alert($.cookies.get('been_here_before'));
	
} else {

	$(launchPetalShow);	

}

function launchPetalShow() {
	$(".animated").show(0);// show the div that contains the slideshow divs
	$('#slider').find('img').batchImageLoad({ // batch load all images so the slideshow will play without interruption
 		loadingCompleteCallback: startIntro // start intro function
 	});
}


// This is the petal show. Every petal div has a photo position asigned to it through css.
// all petals are hidden through css. The petal show only displays if cookie is not present.
function petalShow(){
	var fade_in_time = 3000;
	var fade_in_ending = 1100;
	$("#petal1").fadeIn(fade_in_time);
	
	$("#petal_end_logo").delay(1000).fadeIn(fade_in_ending);
	$("#box").delay(2000).fadeIn(fade_in_ending);
}



// this petal show is for IE. IE doesnt play nice with fade IN. It looks awfull in IE! So we just pop the rosepetals in one by one

function petalShowIE(){
	var waittime= 200
	$("#petal1").show(0, function(){
		$("#petal_end_logo").delay(750).show(0, function(){
			$("#box").delay(750).show(0)
		})
	})
}


// This function does the following: onload there is a spinner spinning. It is waiting all of the images on the intro
// page to finish preloading. As soon as preloading is finished the contents of the intro page will be shown.
// The page loader will fade out and the pedal show will start. The petal show stars after images are preloaded. and 
// contents is visible.

function startIntro() {
	  	$('.curtain').css({'visibility':'visible'}).hide(0).fadeIn(500);
	  	$(".page_loader_intro").fadeOut("normal");
			if($.browser.msie){
	 				$(petalShowIE);
			}else{
 					$(petalShow);
			}
	}


function startStatic() {
	  	$('.curtain').css({'visibility':'visible'}).hide(0).fadeIn(500);
	  	$(".page_loader_intro").hide(0);
		$("#static").delay(300).fadeIn(1000);
			if($.browser.msie){
				$("#box").delay(300).show(0);
			}else{
				$("#box").delay(300).fadeIn(500);
			}
}
	

if($.browser.msie){
}else{
	$('#box li.stay a').click(function(){
	  var url = $(this).attr('href');
	  $('#petal_end_logo').effect('explode', null, 500);

		  $('.curtain').fadeOut('normal', function(){
		    document.location.href = url;
		  });
	  return false;
	});	
}




});

