function accoLeft(){
	$('#colGauche').css({left: -2*$('#colGauche').width()+'px'}).show().animate({
		left: $(window).width()/2+'px'
	},2000, 'easeOutBounce');
}
function accoRight(){
	$('#colDroite').css({left: $(window).width()+2*$('#colDroite').width()+'px'}).show().animate({
		left: $(window).width()/2+'px'
	},2000, 'easeOutBounce');
}
function menuAnim(elem){
	elem.css({top: -2*elem.height()-$('#menu ul').position().top+'px'}).show().animate({
		top: 0+'px'
	},1000, 'easeOutBack');
}
function showContent(){
	$('#conteneur').fadeIn(2000);
}
function showBorder(){
	var margin = Math.floor(($(window).height()-570)/2);
	if(margin>5){
		$('h1, #footer').show();
		$('h1').animate({ paddingBottom: Math.round(margin/2)+'px' }, 2000);
		$('#footer').animate({ height: Math.round(margin/2)+'px' }, 2000);
	}
}
function flashLight(){
		$('#flash').fadeIn(300).fadeOut(300);
}
function slowPulse(sense){
	var duree = 10000;
	if(sense==1){
		$('#deco1').animate({ opacity: 0.5 }, duree);
		$('#deco2').animate({ opacity: 0 }, duree);
		setTimeout(slowPulse,duree);
	} else {
		$('#deco1').animate({ opacity: 0 }, duree);
		$('#deco2').animate({ opacity: 0.5 }, duree);
		setTimeout('slowPulse(1)',duree);
	}
}

$(document).ready(function() {
	var margin = Math.max(0,Math.floor(($(window).height()-570)/2));
	$('#ecran').css({
		paddingTop: margin+'px',
		paddingBottom: margin+'px'
	});
	if($('#deco1').length>0) setTimeout(slowPulse,50);
	if(getDomain(document.referrer) != getDomain(document.location.href)){
		$('h1, #footer, #colGauche, #colDroite, #menu li, #conteneur, #flash').hide();
		setTimeout(accoLeft,10);
		setTimeout(accoRight,1000);
		setTimeout('menuAnim($("#menu li").eq(0))',2000);
		setTimeout('menuAnim($("#menu li").eq(1))',2200);
		setTimeout('menuAnim($("#menu li").eq(2))',2400);
		setTimeout('menuAnim($("#menu li").eq(3))',2600);
		setTimeout('menuAnim($("#menu li").eq(4))',2800);
		setTimeout(showContent,3600);
		setTimeout(showBorder,5000);
		//setTimeout(flashLight,6500);
	} else {
		if($(window).height()<590) {
			$('h1, #footer').hide();
		} else {
			$('h1').css({paddingBottom: Math.round(margin/2)+'px'});
			$('#footer').css({height: Math.round(margin/2)+'px'});
		}
		$('#flash').hide();
	}
	
	// animation au redimentionnement
	$(window).resize(function() {
		$('#colGauche, #colDroite').css({left: '50%'});
		if($(window).height()<590) {
			$('h1, #footer').fadeOut('slow');
			$('#ecran').animate({
				paddingTop: '0px',
				paddingBottom: '0px'
			  }, 'slow');
			$('h1').animate({ paddingBottom: '0px' }, 'slow');
			$('#footer').animate({ height: '0px' }, 'slow');
		} else {
			var margin = Math.floor(($(window).height()-570)/2);
			$('h1, #footer').fadeIn('slow');
			$('#ecran').animate({
				paddingTop: margin+'px',
				paddingBottom: margin+'px'
			  }, 'slow');
			$('h1').animate({ paddingBottom: Math.round(margin/2)+'px' }, 'slow');
			$('#footer').animate({ height: Math.round(margin/2)+'px' }, 'slow');
		}
	});

	// carte GoogleMap et autre fancybox
	$('.fancyhref').each(function(num,elem) {
		var titre = $(this).attr('title');
		$(this).removeAttr('title');
		$(this).fancybox({
			'type':'iframe',
			'width':'95%',
			'height':'95%',
			'title': titre
		});
	});
	$(".disabled").removeAttr('title');
	$("[title]").not('.fancyhref').tooltip({
		delay: 0,
		track: true,
	    showURL: false 
	});	
});

function getDomain(url){return url.split('http://').join().split('/')[0];}

