// JavaScript Document

//==============================================================//
//========== Fonction pour le rollover des sous menu ==========//
//============================================================//
var timer
var menuOuvert = ""
var menuOuvertNiv2 = ""
//========================================//
var section_active_niveau1 = "";
var section_active_niveau2 = "";

var page = ""

var urlEntete = window.location
var p = String(urlEntete).split("?")

var strPageCourante

if(p.length > 1){
	var p2 = p[1].split("&")
	
	var param = new Array()
	for(ind in p2)
	{
		var p3= p2[ind].split("=")
		param[p3[0]] = p3[1]
		
		if(p3[0] == "page")
			page = p3[1]
	}	
	strPageCourante = page.split("_")
	section_active_niveau1 = strPageCourante[0]
	section_active_niveau2 = section_active_niveau1 + "_" + strPageCourante[1]
}else{
	section_active_niveau1 = "a0"
	section_active_niveau2 = "a0"
}
//========================================//

function td_out(pQuel)
{
	window.clearTimeout(timer)
	//pQuel.style.backgroundColor = '#18365B';

}
function td_over(pQuel)
{
	window.clearTimeout(timer)
	//pQuel.style.backgroundColor = '#c07a07';

}














//==========================================================//
//========== Fonction pour ouvrir les sous-menus ==========//
//========================================================//
function openSous(pQuel)
{		
	window.clearTimeout(timer)
	
	if (menuOuvertNiv2)
		document.getElementById(menuOuvertNiv2).style.visibility = 'hidden'

	if (menuOuvert)
		document.getElementById(menuOuvert).style.visibility = 'hidden'
	
	if (pQuel)
	{
		document.getElementById(pQuel).style.visibility = 'visible'
		menuOuvert = pQuel
		menuOuvertNiv2 = ""
	}
}

function openSousNiv2(pQuel, menu)
{
	
	//td_over(menu);
	
	window.clearTimeout(timer)

	if (menuOuvertNiv2)
	{
		document.getElementById(menuOuvertNiv2).style.visibility = 'hidden'
	}
	
	if (pQuel)
	{
		document.getElementById(pQuel).style.visibility = 'visible'
		menuOuvertNiv2 = pQuel
	}
}
function fermeSous()
{
	
	fermeSousNiv2();
	
	if (menuOuvert)
		document.getElementById(menuOuvert).style.visibility = 'hidden'
	
	window.clearTimeout(timer)
}
function fermeSousNiv2()
{
	//td_out(menu);
	
	if (menuOuvertNiv2)
		document.getElementById(menuOuvertNiv2).style.visibility = 'hidden'
	
	window.clearTimeout(timer)
}
function timerSousMenu(statut)
{
	switch(statut)
	{
	case 1:
	case "1":
		timer = window.setTimeout('fermeSous();',200)
		break;
	case 0:
	case "0":
		window.clearTimeout(timer)
		break;
	}
}




//==========================================//
//========== Creer les sous menu ==========//
//========================================//
function verifPos()
{
	for(IndSous in menus_deroulants)
	{
		for(ind in menus_deroulants[IndSous])
		{
			var itemMenu = new ItemMenuDeroulant();
			itemMenu.sousItems = menus_deroulants[IndSous][ind].sousItems;
			var arySousItemsMenu = null;
			arySousItemsMenu = itemMenu.sousItems;

			if (arySousItemsMenu)
			{
				//createSousSousMenu(arySousItemsMenu,ind,IndSous);
				var id = ind;
				var pIndSous = IndSous
				//----------//
				var num = Number(id);
				var posTop = 0;
				var bt_name = 'btn_' + pIndSous + '_' + num;
				var element = document.getElementById(bt_name);
				
				/*if(pIndSous=="c2")
				{
					alert("bt_name : " + bt_name + " , element: " + element + " , element.offsetTop : " + element.offsetTop)
				}*/
				
				
				if(element)
				{
					posTop = element.offsetTop;
					
					var mcMenu = "sous_" + IndSous + "_niv2_" + id;
					if(mcMenu)
					{
						document.getElementById(mcMenu).style.marginTop = posTop;
					}
					
				
					
				}
				
			}
			
			
		}
	}
	
	
}

window.onload=verifPos;

function createSous()
{
	//changeImgBanner()

	for(IndSous in menus_deroulants)
	{	
	
		if(menus_deroulants[IndSous].length>0)
		{ 

		document.write("<div id='sous_" + IndSous + "' class='g_sous sous_menu_" + IndSous + "' >")	
		document.write("<div class='sous_float_" + IndSous + "' onmouseover='timerSousMenu(0)' onmouseout='timerSousMenu(1)'>")	
			
			document.write("<ul>");
					for(ind in menus_deroulants[IndSous])
					{
							var itemMenu = new ItemMenuDeroulant();
							itemMenu.texte = menus_deroulants[IndSous][ind].texte;
							itemMenu.lien = menus_deroulants[IndSous][ind].lien;
							itemMenu.estPageCourante = menus_deroulants[IndSous][ind].estPageCourante;
							itemMenu.sousItems = menus_deroulants[IndSous][ind].sousItems;
							
							//////////////////////////
							// Niveau2 (sous-items) //
							//////////////////////////
							var arySousItemsMenu = null;
							arySousItemsMenu = itemMenu.sousItems;

							//-------------//
							var myPage = "";
							var pagNiv1
							var url = itemMenu.lien;
							var mp = String(url).split("?");
							var mp2 = mp[1].split("&");
							
							var mparam = new Array();
							for(ind2 in mp2)
							{
								var mp3= mp2[ind2].split("=");
								mparam[mp3[0]] = mp3[1];
								
								if(mp3[0] == "page")
									myPage = mp3[1];
							}
							//-------------//

							
							pagNiv1 = myPage.split("_")
							var numPageNiv1 = pagNiv1[0].split("c")
							
							//var nameBtn = "btn_" + pagNiv1[0] + "_" + ind;
							var nameBtn = "btn_" + numPageNiv1[1] + "_" + ind;
							
							if (arySousItemsMenu)
							{								
								if(itemMenu.estPageCourante || section_active_niveau2==myPage)
								{
									//document.write("<tr onmouseover='timerSousMenu(0)'><td onmouseover='openSousNiv2(\"sous_" + ind + "_niv2\", this)' onmouseout='fermeSousNiv2(this)'><a class='section_courante_niveau_2' href='" + itemMenu.lien + "'>" + itemMenu.texte + "</a></td></tr>");
									document.write("<li id='" + nameBtn + "'><a onmouseover='openSousNiv2(\"sous_" + IndSous + "_niv2_" + ind + "\", this)'  class='section_courante_niveau_2' href='" + itemMenu.lien + "'><span class='txt'>" + itemMenu.texte + "</span><span class='fleche'></span></a></li>");
								}
								else
								{
									//document.write("<tr onmouseover='timerSousMenu(0)'><td onmouseover='openSousNiv2(\"sous_" + ind + "_niv2\", this)' onmouseout='fermeSousNiv2(this)'><a class='active' href='" + itemMenu.lien + "'>" + itemMenu.texte + "</a></td></tr>");
									document.write("<li id='" + nameBtn + "'><a onmouseover='openSousNiv2(\"sous_" + IndSous + "_niv2_" + ind + "\", this)'  href='" + itemMenu.lien + "'><span class='txt'>" + itemMenu.texte + "</span><span class='fleche'></span></a></li>");
								}
									
								
								//document.write("<tr><td style='height:1px; background-color:#546070;'></td></tr>")
							}
							else
							{
								if(itemMenu.estPageCourante)
								{
									//document.write("<tr onmouseover='timerSousMenu(0)'><td onmouseover='td_over(this)' onmouseout='td_out(this)'><a class='section_courante_niveau_2' href='" + itemMenu.lien + "'>" + itemMenu.texte + "</a></td></tr>");
									document.write("<li id='" + nameBtn + "'><a onmouseover='openSousNiv2(null, this)' class='section_courante_niveau_2' href='" + itemMenu.lien + "'><span class='txt'>" + itemMenu.texte + "</span></a></li>");	
								}
								else
								{
									//document.write("<tr onmouseover='timerSousMenu(0)'><td onmouseover='td_over(this)' onmouseout='td_out(this)'><a class='active' href='" + itemMenu.lien+ "'>" + itemMenu.texte + "</a></td></tr>");
									document.write("<li id='" + nameBtn + "'><a onmouseover='openSousNiv2(null, this)' href='" + itemMenu.lien + "'><span class='txt'>" + itemMenu.texte + "</span></a></li>");
								}
								
								//document.write("<tr><td style='height:1px; background-color:#546070;'></td></tr>")
							}
							//////////////////
							// Fin niveau 2 //
							//////////////////
							
					}
					document.write("</ul>");
				
		document.write("</div>")
		document.write("</div>")
		}
		else
		{
			document.write("<div id='sous_" + IndSous + "' >")
		} 
		//--------//
		for(ind in menus_deroulants[IndSous])
		{
			var itemMenu = new ItemMenuDeroulant();
			itemMenu.sousItems = menus_deroulants[IndSous][ind].sousItems;

			var arySousItemsMenu = null;
			arySousItemsMenu = itemMenu.sousItems;

			if (arySousItemsMenu)
			{
				createSousSousMenu(arySousItemsMenu,ind,IndSous);
			}
		}
		//----------//
	}
}


function createSousSousMenu(pArySousItemsMenu,pInd,pIndSous)
{
	var arySousItemsMenu = pArySousItemsMenu
	var id = pInd
	
	
	var numParent = pIndSous.split("c")
	
	/*if(numParent[1]==5)
		var posLeft = parseFloat(numParent[1])*187	 + parseFloat(numParent[1]- 360)
	else
		var posLeft = parseFloat(numParent[1])*187	 + parseFloat(numParent[1] )*/
		
	//----- Position horizontale du 3eme niveau -----//
	var tbPosLeft = new Array();
	//fra
	tbPosLeft["1"] = 239;
	tbPosLeft["2"] = 336;
	tbPosLeft["3"] = 466;
	tbPosLeft["4"] = 655;
	tbPosLeft["5"] = 414;
	tbPosLeft["11"] = 627;
	//eng
	tbPosLeft["6"] = 239;
	tbPosLeft["7"] = 355;
	tbPosLeft["8"] = 466;
	tbPosLeft["9"] = 655;
	tbPosLeft["10"] = 414;
	tbPosLeft["12"] = 658;
	
	var posLeft = tbPosLeft[pIndSous]
		
		
	//var posTop = (parseFloat(id)-1)*24	
	//----- Position verticale du 3eme niveau -----//
	var num = Number(id);
	var posTop = 0;
	var bt_name = 'btn_' + pIndSous + '_' + num;
	
	var element = document.getElementById(bt_name);
			
	if(element)
	{
		posTop = element.offsetTop;
	}
	
	
	
	
	
	
	document.write("<div id='sous_" + pIndSous + "_niv2_" + id + "' class='sous_niv3' style='margin-top:" + posTop + "px; margin-left:" + posLeft + "px;'>")	
	//document.write("<div id='sous_" + pIndSous + "_niv2_" + id + "' class='sous_niv3' style='margin-left:" + posLeft + "px;'>")	
	
		document.write("<div onmouseover='timerSousMenu(0)' onmouseout='timerSousMenu(1)'>")	
		//document.write("<div onmouseover='timerSousMenu(0)'>")	
			
			document.write("<ul>");
					for(ind in arySousItemsMenu)
					{							
						var itemMenu = new ItemMenuDeroulant();
						itemMenu.texte = arySousItemsMenu[ind].texte;
						itemMenu.lien = arySousItemsMenu[ind].lien;
						itemMenu.estPageCourante = arySousItemsMenu[ind].estPageCourante;
						
						// Niveau3 (sous-items)
						if(itemMenu.estPageCourante)
						{
							document.write("<li><a class='section_courante_niveau_3' href='" + itemMenu.lien + "'><span class='txt'>" + itemMenu.texte + "</span></a></li>");	
						}
						else
						{
							document.write("<li><a href='" + itemMenu.lien + "'><span class='txt'>" + itemMenu.texte + "</span></a></li>");
						}
							
					}
					document.write("</ul>");
				
		document.write("</div>")
		document.write("</div>")
}

