$(document).ready(function(){
    
    function readCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
    }
    function createCookie(cookieName,cookieValue,nDays) {
	var echeance = new Date();
	var maintenant = echeance.getTime() + (12 * 60 * 60 * 1000);
	echeance.setTime(maintenant);
	document.cookie = cookieName+" ="+cookieValue+"; expires="+echeance.toGMTString();
    }
    
    var active = true;
    var posIntro = 1;
    var introAuto = false; /********** je mets a false car en fait ils ne veulent pas une intro **********/
    var nb_choix = $(".intro_texte div").length;
    var tempsAnimation = 2000;
    var tempsAttente = 6000;
    var selectTableau = new Array();
    selectTableau = ["26|130", "156|110", "266|110", "380|130"];
    
    if(introAuto){ if(readCookie('introcookie') == null || readCookie('introcookie') == "") { $(".intro").fadeIn("slow"); startIntro(); } }
    function startIntro() { createCookie('introcookie','magie',7); timerIntro = setInterval(introAutomatique, tempsAttente); }
    
    function introAutomatique(){
	if(posIntro == nb_choix){
	    clearInterval(timerIntro);
	    $(".intro").fadeOut("slow");
	} else {
	    var posBarre = selectTableau[posIntro].indexOf('|');
	    var longueurDonnee = selectTableau[posIntro].length;
	    $(".intro_select").animate({ left: (selectTableau[posIntro]).substring(0,posBarre), width: (selectTableau[posIntro]).substring(posBarre+1,longueurDonnee) }, 1000);
	    $("#texte_"+posIntro).fadeOut("slow");
	    $("#intro_p"+posIntro).hide();
	    $("#intro_puce_"+posIntro).hide();
	    posIntro++;
	    $("#texte_"+posIntro).fadeIn("slow");
	    $("#intro_puce_"+posIntro).show();
	    $("#intro_p"+posIntro).show();
	}
    }
    
    $(".bt_close").bind("click", function(){ $(".intro").fadeOut("slow"); });
    
    var nbBloc = $(".bloc_zone").length;
    var tailleBloc = 220;
    var tailleMaxBloc = 360;
    
    $(".liste_bloc").width(nbBloc*tailleMaxBloc);
    $(".bloc_texte").find("a").each(function(){
	$(this).mouseenter(function(){ $(this).css({ "text-decoration":"underline" }); });
	$(this).mouseleave(function(){ $(this).css({ "text-decoration":"none" }); });
    });
    
    $(".bloc_event").each(function(){
	$(this).mouseenter(function(){
	    var idBlocText = ($(this).attr("id")).substr(5,6);
	    switch(idBlocText) {
		case "1":
		    $(".bloc_gauche").stop().stop().animate({ width: 420 }, 300);
		    $(".blocs_centre:nth-child(3)").stop().stop().animate({ width: 180 }, 300);
		    $(".bloc_droite").stop().stop().animate({ width: 138 }, 300);
		    $(this).find("h2").css({ "color":"#6ec1ff" });
		break;
		case "2":
		    $(".blocs_centre:nth-child(2)").stop().stop().animate({ width: 360 }, 300);
		    $(".bloc_droite").stop().stop().animate({ width: 138 }, 300);
		    $(this).find("h2").css({ "color":"#6ec1ff" });
		break;
		case "3":
		    $(".bloc_gauche").stop().stop().animate({ width: 140 }, 300);
		    $(".blocs_centre:nth-child(3)").stop().stop().animate({ width: 380 }, 300);
		    $(".blocs_centre:nth-child(2)").stop().stop().animate({ width: 180 }, 300);
		    $(this).find("h2").css({ "color":"#6ec1ff" });
		break;
		case "4":
		    $(".bloc_gauche").stop().stop().animate({ width: 140 }, 300);
		    $(".blocs_centre:nth-child(2)").stop().stop().animate({ width: 180 }, 300);
		    $(".bloc_droite").stop().stop().animate({ width: 420 }, 300);
		    $(".bloc_droite .bloc_texte").stop().stop().animate({ width: 380 }, 300);
		    $(this).find("h2").css({ "color":"#6ec1ff" });
		break;
	    }
	});
	$(this).mouseleave(function(){
	    var idBlocText = ($(this).attr("id")).substr(5,6);
	    switch(idBlocText) {
		case "1":
		    $(".bloc_gauche").stop().stop().animate({ width: 260 }, 300);
		    $(".blocs_centre:nth-child(3)").stop().stop().animate({ width: 219 }, 300);
		    $(".bloc_droite").stop().stop().animate({ width: 259 }, 300);
		    $(".bloc_droite .bloc_texte").stop().stop().animate({ width: 220 }, 300);
		    $(this).find("h2").css({ "color":"#fff" });
		break;
		case "2":
		    $(".blocs_centre:nth-child(2)").stop().stop().animate({ width: 219 }, 300);
		    $(".bloc_droite").stop().stop().animate({ width: 259 }, 300);
		    $(".bloc_droite .bloc_texte").stop().stop().animate({ width: 220 }, 300);
		    $(this).find("h2").css({ "color":"#fff" });
		break;
		case "3":
		    $(".bloc_gauche").stop().stop().animate({ width: 259 }, 300);
		    $(".blocs_centre:nth-child(2)").stop().stop().animate({ width: 219 }, 300);
		    $(".blocs_centre:nth-child(3)").stop().stop().animate({ width: 219 }, 300);
		    $(this).find("h2").css({ "color":"#fff" });
		break;
		case "4":
		    $(".bloc_gauche").stop().stop().animate({ width: 259 }, 300);
		    $(".blocs_centre:nth-child(2)").stop().stop().animate({ width: 219 }, 300);
		    $(".bloc_droite").stop().stop().animate({ width: 259 }, 300);
		    $(".bloc_droite .bloc_texte").stop().stop().animate({ width: 220 }, 300);
		    $(this).find("h2").css({ "color":"#fff" });
		break;
	    }
	});
	$(".bloc_droite .bloc_texte").css({ "width": 220+"px" });
    });
});
