

var delayTime = 1000;
var fadeTime = 1000;
$(document).ready(function()
{
	$(".animationBA").find("div").hide();
		
	$(window).bind('resize', function() {
		backgroundResize();
	});
	backgroundResize();
	
	// init
	$('#header, #content, #footer').css('opacity','0.01');
	$('html, body').css('overflow','hidden');
	$(".logoIntro").css({'margin-left':(- $('body').width()),'display':'block'});
	$(".carIntro").css({'margin-left':(- ($('body').width() + 250)),'display':'block'});
	
	
	$(".btnSkipIntro").delay(delayTime).fadeIn(500,function() { BtnSkipIntro.init(); });
	$(".logoIntro").delay(delayTime).animate({'margin-left':'-120px'},fadeTime*3, 'linear');
	$(".carIntro").delay(delayTime).animate({'margin-left':'-380px'},fadeTime*3, 'linear', function ()
	{
		$(".carIntro").delay(delayTime+200).fadeOut(fadeTime);
		$(".contentImgResize").delay(delayTime).fadeIn(fadeTime, function ()
		{
			//$(".bandeAnnonce").delay(delayTime*3).fadeOut(fadeTime, function () { $(".bandeAnnonce").remove(); $('#header, #content, #footer').animate({'opacity':1},fadeTime/2); });
			DestroyIntro.start(delayTime);
		});
	});
	
});


/***********************************************************************************/

/**********************  DESTROY INTRO
 * ***********************************/

var DestroyIntro = {
	start:function(_delay) {
		$(".bandeAnnonce").delay(_delay*3).fadeOut(fadeTime, function () { 
			$(".bandeAnnonce").remove(); 
			Site.init();
			$('#header, #content, #footer').animate({'opacity':1},fadeTime/2); 
			$('html, body').removeAttr('style');
		});
	}
}
 

/***********************************************************************************/

/**********************  BOUTON SKIP INTRO
 * ***********************************/
var BtnSkipIntro = {
	init:function() {
		$(".btnSkipIntro").live("click",function() {
			$(".logoIntro").stop();
			$(".carIntro").stop();
			$(".contentImgResize").stop();
			DestroyIntro.start(0);
		});
	}
}



/***********************************************************************************/

/**********************  RESIZE BACKGROUND IMAGE
 * ***********************************/


function backgroundResize()
{
    var imgHeight = Math.round($('body').height());
   // console.log(imgHeight);
	var imgWidth = (imgHeight * 1600) / 900;
	
	if (imgWidth > $('body').width()) {
		var range = Math.round((imgWidth - $('body').width()) / 2);
		$('.contentImgResize img').css('margin', 'auto');
		$('.contentImgResize img').css('marginLeft', '-'+range+'px');
	}
	else {
		imgWidth = Math.round($('body').width());
		imgHeight = (imgWidth * 900) / 1600;
		$('.contentImgResize img').css('margin', 'auto');
		var range = Math.round((imgHeight - ($('body').height())) / 2);
		$('.contentImgResize img').css('marginTop', '-'+range+'px');
	}
	
	$('.contentImgResize img').css('width', imgWidth+'px');
	$('.contentImgResize img').css('height', imgHeight+'px');
	
	if (imgHeight < 700) {
		$('.logoIntro img').css('height',300);
		$('.logoIntro').css('margin-top',-150);
	} else {
		$('.logoIntro img').css('height',400);
		$('.logoIntro').css('margin-top',-200);
	}
}
