/* MIDDLE OFFICE */

	function openArbo(){
		$("#L1 .folder").css({ background : "url(../image/module/arbo/folder_moins.gif) no-repeat left" });

		$("#L1-1").css({ display : "table-row" });
		$("#L1-1 .folder").css({ background : "url(../image/module/arbo/folder_moins.gif) no-repeat left" });


		$("#L1-1-2").css({ display : "table-row"});
		$("#L1-2").css({ display : "table-row"});

		$("#L1-1-1").css({ display : "table-row"});
		$("#L1-1-1 td").effect("highlight", {}, 2500);
	}

	// Démo focntionnement
	function choixCol(colonne,nbr){
		for(i = 1; i <= nbr; i++){
			if(colonne == i){
				$("#contenu"+i).slideDown("slow");
				$("#col"+i).css({ display: "" });
			}
			else{
				$("#contenu"+i).slideUp("slow");
				$("#col"+i).css({ display: "none" });
			}
		}
	}

	function showAide(){
		$("#aide").slideDown("slow");

		$("#wizard1").slideUp("slow");
		$("#ajoutPage1").slideUp("slow");
		$("#ajoutPage2").slideUp("slow");
		$("#wizard2").slideUp("slow");
		$("#modif").slideUp("slow");

	}

	function showPage1(){
		$("#wizard1").slideDown("slow");
		$("#ajoutPage1").slideDown("slow");

		$("#aide").slideUp("slow");
		$("#ajoutPage2").slideUp("slow");
		$("#wizard2").slideUp("slow");
		$("#modif").slideUp("slow");

	}

	function showPage2(){
		$("#wizard1").slideDown("slow");
		$("#ajoutPage2").slideDown("slow");

		$("#aide").slideUp("slow");
		$("#ajoutPage1").slideUp("slow");
		$("#wizard2").slideUp("slow");
		$("#modif").slideUp("slow");

	}

	function showModif(){
		$("#wizard2").slideDown("slow");
		$("#modif").slideDown("slow");

		$("#aide").slideUp("slow");
		$("#wizard1").slideUp("slow");
		$("#ajoutPage1").slideUp("slow");
		$("#ajoutPage2").slideUp("slow");

	}

/* ACCORDEON CENTER */
	function toggleCenter(elem1,elem2){
		elem1Obj = document.getElementById(elem1);
		elem2Obj = document.getElementById(elem2);
		if (elem1Obj.className == "acc_menuCenter openPortletCenter"){
			elem1Obj.className = "acc_menuCenter";
			elem2Obj.className = "acc_list";
		}
		else if (elem1Obj.className == "acc_menuCenter"){
			elem1Obj.className = "acc_menuCenter openPortletCenter";
			elem2Obj.className = "acc_list openPortletCenter";
		}
	}


/* FONCTION HAUTEUR DU FOOTER */
	function footerHeight(){
		var ecranHeight = document.documentElement.clientHeight;

		if($(".footer").hasClass("accueil") == true ){
			var contenuPixelTop = $('.footer').css("margin-top");
			contenuPixelTop = parseInt(contenuPixelTop.substring(0,(contenuPixelTop.length-2)));
			
			var topTop = $('#pannelRight').css("margin-top");
			topTop = parseInt(topTop.substring(0,(topTop.length-2)));
			var contenuHeight = $('#pannelRight').height()+$('#headerAccueil').height()+topTop;
			if(contenuHeight < 780){ // Si la hauteur de la plus petite que l'animation
				$(".footer").css({marginTop:"780px"});
			}
			else{
				$(".footer").css({marginTop:contenuHeight+"px"});	
			}
			$("#animeAccueil").css({height:$(document).height()+"px"});

		}
		else{
			var contenuHeight = $("#container").height()+$("#header").height();
		}

		//alert(contenuHeight);
		//alert($('#container').height());
		if( contenuHeight < ecranHeight){
			var footerHeight = $(".footer").height();
			var difference = (ecranHeight - contenuHeight);
			if( difference > footerHeight ){
				$(".footer").css({height:difference+"px"});
			}
		}
	}


$(document).ready(function() {
	var tata = false;	
/* MENU DEROULANT */

	$("#mainNavigation ul").hover(function(){
	  tata = true;
	 },function(){
	    tata = false;
	 });

	$("#mainNavigation td").each(function(){
		$(this).hover(function(){
			$(this).children("a").addClass("Over");
			$(this).children("ul").slideDown("fast");

			// Centrer le menu déroulant par rapport au TD
			var largeurTD = $(this).width();
			var largeurUL = $(this).children("ul").width();
			//var pixelNeg = (largeurTD - largeurUL)/2;
			var pixelNeg = -2; //pour corriger le bug du menu déroulant
			$(this).children("ul").css({marginLeft:pixelNeg+"px"});

			$(this).prev().children("ul").fadeOut("fast");
			$(this).prev().children("a").removeClass("Over");
			$(this).siblings().children("ul").fadeOut("fast");
			$(this).siblings().children("a").removeClass("Over");
		},function(){
			if(tata == false){
				$("#mainNavigation ul").fadeOut("fast");
				$("#mainNavigation a").removeClass("Over");
			}
		});
	});
	
	$("#container").mouseover(function(){
		$("#mainNavigation ul").fadeOut("fast");
		$("#mainNavigation a").removeClass("Over");
	});

/* ACCORDEON */
	if($("#contentprint").size()!=0) {
	  $(".acc_listCenter").hide();
	  $(".acc_listCenter.openPortletCenter").show();
	  $(".acc_menuCenter").click(function(){
		$(this).next(".acc_listCenter").slideToggle("slow").siblings(".acc_listCenter:visible").slideUp("slow");
		$(this).toggleClass("openPortletCenter");
		$(this).siblings(".acc_menuCenter").removeClass("openPortletCenter");
	  });
	}

	$("#center_01").addClass("openPortletCenter");
	$("#center_01_list").slideToggle("slow");



/* HAUTEUR DU FOOTER */
	footerHeight();


/*  Alerte  */
		$("#hide_topRight").click(function(){
				$("#alerte:visible").slideUp();
				$("#warning").show();
		});
		$("#warning").click(function(){
				$("#alerte:hidden").slideDown();
				$("#warning").hide();
		});

/* confirmation */
		$("#confirm").click(function(){
				$("#confirm:visible").slideUp()
		});

		$("#buttonValider").click(function(){
				$("#confirm:hidden").slideDown()
		});

/* interrogation */
		$("#interrogation").click(function(){
				$("#interrogation:visible").slideUp()
		});

		$("#buttonValider").click(function(){
				$("#interrogation:hidden").slideDown()
		});
});
