$.fn.wait = function(time, type) {
	time = time || 1000;
	type = type || "fx";
	return this.queue(type, function() {
	  var self = this;
	  setTimeout(function() {
	      $(self).dequeue();
	  }, time);
	});
};


$(document).ready(function() {
	// ==--- menu	
	// if(document.referrer == "") {
   var checkOrigine = /parcoursalpha/ ;
	if(!document.referrer.match(checkOrigine)) {
		$("div#menu-layout")
			.wait(300)
			.animate({left:'239px'},3200,function() {
					$("#content-overlay").overlay().load();
				});
		$("img#menu-line-img").wait(1500).animate({left:'110px'},3200);
		$("img#content-border-left").wait(300).animate({height:'352px'},1200);
		//==--- vignettes
		$("div.vignette").wait(900).animate({left:0},2400,function() {
				$("div.vignette-img").animate({opacity:1},1200);
				$("div.vignette-img2 img").animate({opacity:1},1200);
		});
	} else {
		$("div#menu-layout").css({left:'239px'});
		$("img#menu-line-img").css({left:'110px'});
		$("img#content-border-left").css({height:'325px'});
		//==--- vignettes
		$("div.vignette").css({left:0});
		$("div.vignette-img").css({opacity:1});
		$("div.vignette-img2 img").css({opacity:1});
	}
	$("div#r1c2").wait(300).animate({opacity:1},2400);
	$("div#r1c2 .text").fadeIn(1200).animate({fontSize:'1.2em'},1200);
	$("div.video").wait(1800).fadeIn(1200);
	$("div.main a.active").click(function(e) { 
		e.preventDefault();
		$(this)
			.children("div.inner")
			.slideUp(3200)
			;
	});
});

// centrer les divs 
$(document).ready(function() {
	$("div#access div.access").each(function() {
		var height1 = $(this).height();
		$(this)
			.find("div")
			.each(function() {
				var height2 = $(this).height();
				$(this).css("margin-top",Number((height1-height2)/2).toString()+"px").fadeIn(600);
			});
	});
});

// Animer access
$(document).ready(function() {
	$("img#access-line-img").wait(600).animate({left:'395px',width:'629px'},1200);
});

// Positionner partner / sitemap 
$(document).ready(function() {
	$("div#partner-title span").slideDown(600);
	$("div#sitemap-title span").slideDown(600);
});







// Gérer les overlays
$(document).ready(function() {
   var checkOrigine = /parcoursalpha/ ;
	if(!document.referrer.match(checkOrigine)) {
	// if(document.referrer == "") {
	$("#content-overlay").overlay({
			api:true
			,speed:1200
			,expose : {
				color: '#000',
				opacity: 0.7,
				closeSpeed: 900,
				closeOnClick: false
			}
			,closeOnClick: false
		});
	}
	$("a.cine").click(function(e) {
		e.preventDefault();
		$("#content-overlay").overlay().load();
	});
});

$(document).ready(function() {
	$("a.inviter").click(function(e){
		e.preventDefault();
		$("div#inviter-overlay").overlay().load();
	});
	$("div#inviter-overlay").overlay({
			api:true
			,speed:1200
			,expose : {
				color: '#000',
				opacity:0.7,
				closeSpeed:900,
				closeOnClick:false
			}
			,closeOnClick: false
			,onClose: function() {
				$("#invit-form").resetForm();
				$("div#invit p.invit-ok").remove();
			}
		});
});

