$(function() { //attend que le DOM soit prêt pour commencer
	$("#ssmenu_vin").hide(); $("#ssmenu_event").hide(); // par défaut on cache les sous menu
	//au roll over déplacement de la barre horiz
	$("#li_acc").mouseenter(function() { cacheSSmenu(); $('#fond_roll').stop().animate({ "left" : "0px" }, "normal"); })
	$("#li_dom").mouseenter(function() { cacheSSmenu(); $('#fond_roll').stop().animate({ "left" : "127px" }, "normal"); })
	$("#li_vin").mouseenter(function() { cacheSSmenu("vin"); $('#fond_roll').stop().animate({ "left" : "252px" }, "normal"); })
	$("#li_vis").mouseenter(function() { cacheSSmenu(); $('#fond_roll').stop().animate({ "left" : "373px" }, "normal"); })
	$("#li_eve").mouseenter(function() { cacheSSmenu("event"); $('#fond_roll').stop().animate({ "left" : "509px" }, "normal"); });
	$("#li_acces").mouseenter(function() { cacheSSmenu(); $('#fond_roll').stop().animate({ "left" : "625px" }, "normal");});
	$("#li_con").mouseenter(function() { cacheSSmenu(); $('#fond_roll').stop().animate({ "left" : "724px" }, "normal");});
	$("#li_bou").mouseenter(function() { cacheSSmenu(); $('#fond_roll').stop().animate({ "left" : "852px" }, "normal");});
	//qd on quitte les sous menus, on les cache
	$("#menu").mouseleave(function() { cacheSSmenu(); });
	//$("#ssmenu_event").mouseleave(function() { cacheSSmenu(); });

	function cacheSSmenu(what) {
		if(what=="vin") {
			if($("#ssmenu_vin").css("display")=="none") $("#ssmenu_vin").slideToggle();
		}
		else if(what=="event") {
			if($("#ssmenu_event").css("display")=="none") $("#ssmenu_event").slideToggle();
		}
		else { $("#ssmenu_event").slideUp(); $("#ssmenu_vin").slideUp(); }
	}
	
	//Accordéon en Accueil
	$("#bout_vins > div:not(:first-child)").css("borderLeft","1px solid #600b0b");
	var tab_N = new Array(0, 87, 174, 261);
	var tab_G = new Array(0, 50, 105, 160);
	var tab_D = new Array(0, 175, 230, 286);
	
	$(".set").mouseenter( function() {
		var whatDiv=parseInt($(this).attr("id").substr(3,1));
		affDiv(whatDiv);
	}) 
	$("#bout_vins").mouseleave( function() {
		for(var i=0; i<=tab_N.length; i++) {
			$("#vin"+i).stop().animate({ left:tab_N[i]+'px' },1000);
		}
	}) 
	
	function affDiv(who) {
		if(who==0) {
			for(var i=0; i<=tab_D.length; i++) {
				$("#vin"+i).stop().animate({ left:tab_D[i]+'px' },1000);
			}
		}
		else if(who==1 || who==2) {
			for(var i=0; i<=who; i++) {
				$("#vin"+i).stop().animate({ left:tab_G[i]+'px' },1000);
			}
			for(var j=who+1; j<=tab_G.length; j++) {
				$("#vin"+j).stop().animate({ left:tab_D[j]+'px' },1000);
			}
		}
		else if(who==3) {
			for(var i=0; i<=tab_G.length; i++) {
				$("#vin"+i).stop().animate({ left:tab_G[i]+'px' },1000);
			}
		}
	}
});
