var minuterie_1 = null;
var minuterie_2 = null;
var tabSections = new Array();
var fleche_on = new Image();
fleche_on.src = "../images/menugauche_fleche_rouge.gif";
var fleche_off = new Image();
fleche_off.src = "../images/menugauche_fleche.gif";

function oSection(declancheur, idFleche) {
	this.declancheur = declancheur;
	this.idCalque	= "";
	this.idFleche	= idFleche;
	this.tabPages = new Array();
}

function oPage(titre, lien, cible) {	
	this.titre = titre;
	this.lien = lien;
	this.cible = cible;

	this.declancheur = "";
	this.idCalque	= "";
	this.tabPages = new Array();
}

function oPosition(obj){
	var posX = 0
	var posY = 0
	while(obj.offsetParent != null){
		posX += (obj.offsetLeft) ;
		posY += (obj.offsetTop) ;
		obj = obj.offsetParent ;
	}
	this.posX = posX ;
	this.posY = posY ;
	return this ;
}


function mOverSection_1() {	
	fermerToutesLesSections_1();
	
	var oCalque = document.getElementById(this.idCalque);

	var pos = new oPosition(document.getElementById(this.idDeclancheur));
	oCalque.style.left = pos.posX + 147;
	oCalque.style.top = pos.posY;
	oCalque.style.display = "inline";

	var oFleche = document.getElementById(this.idFleche);
	oFleche.src = fleche_on.src;
}

function mOverSection_2() {	
	fermerToutesLesSections_2();
	
	var oCalque = document.getElementById(this.idCalque);

	var pos = new oPosition(document.getElementById(this.idDeclancheur));
	oCalque.style.left = pos.posX + this.offsetWidth;
	oCalque.style.top = pos.posY;
	oCalque.style.display = "inline";
}

function mOutSection_1() {
	fermerSection_1(this.idCalque, this.idFleche);
}

function mOutSection_2() {	
	fermerSection_2(this.idCalque, this.idFleche, false);
}

function fermerSection_1(idCalque, idFleche) {	
	minuterie_1 = setTimeout("cacherCalque(\""+ idCalque +"\", \""+ idFleche +"\")", 300);
}

function fermerSection_2(idCalque, idFleche, cacherParent) {	
	if(cacherParent) {
		var leCalque2 = document.getElementById(idCalque);
		minuterie_1 = setTimeout("cacherCalque(\""+ leCalque2.idCalqueParent +"\", \""+ idFleche +"\")", 300);
	}
	
	minuterie_2 = setTimeout("cacherCalque(\""+ idCalque +"\", \""+ idFleche +"\")", 300);
}

function annulerTousLesTimeout() {	
	annulerTimeout_1();
	annulerTimeout_2();
}

function annulerTimeout_1() {
	clearTimeout(minuterie_1);
	minuterie_1 = null;
}

function annulerTimeout_2() {
	clearTimeout(minuterie_2);
	minuterie_2 = null;
}

function cacherCalque(idCalque, idFleche) {
	var oCalque = document.getElementById(idCalque);
	oCalque.style.display = "none";

	var oFleche = document.getElementById(idFleche);
	if(oFleche)
		oFleche.src = fleche_off.src;
}

function fermerToutesLesSections_1() {	
	annulerTimeout_1();
	annulerTimeout_2();

	for(var iSection=0; iSection<tabSections.length; iSection++) {
		cacherCalque(tabSections[iSection].idCalque, tabSections[iSection].idFleche);

		for(var iPage=0; iPage<tabSections[iSection].tabPages.length; iPage++) {
			if(tabSections[iSection].tabPages[iPage].tabPages.length > 0)
				cacherCalque(tabSections[iSection].tabPages[iPage].idCalque, tabSections[iSection].idFleche);
		}
	}
}

function fermerToutesLesSections_2() {
	annulerTimeout_2();

	for(var iSection=0; iSection<tabSections.length; iSection++) {
		for(var iPage=0; iPage<tabSections[iSection].tabPages.length; iPage++) {
			if(tabSections[iSection].tabPages[iPage].tabPages.length > 0)
				cacherCalque(tabSections[iSection].tabPages[iPage].idCalque, "");
			
		}
	}
}

function mOverItem(_this) {
	_this.className = "menuItemOver";
}

function mOutItem(_this) {
	_this.className = "menuItemOut";
}

function chargerDoc() {
	if(this.cible != "")
		window.open(this.lien, this.cible);
	else
		window.open(this.lien, "_self");
}


function ecrireMenu() {
	for(var iSection=0; iSection<tabSections.length; iSection++) {
		var laSection = tabSections[iSection];

		laSection.idCalque = 'menu_'+ iSection;

		document.write('<div id="'+ laSection.idCalque +'" class="menuCalque">');

		document.write('<table cellspacing="0" cellpadding="0" border="0"><tr><td class="lmenu">');

		for(var iPage=0; iPage<laSection.tabPages.length; iPage++) {
			var laPage = laSection.tabPages[iPage];
			var idItem = 'item_'+ iSection +'_'+ iPage;
			
			if(laPage.tabPages.length == 0) {
				document.write('<a id="'+ idItem +'" href="'+ laPage.lien +'"'+ (laPage.cible != "" ? ' target="'+ laPage.cible +'"' : '') +'><div>'+ laPage.titre +'</div></a>');
			} else {
				document.write('<a id="'+ idItem +'" href="'+ laPage.lien +'"'+ (laPage.cible != "" ? ' target="'+ laPage.cible +'"' : '') +'><div>'+ laPage.titre +'...</div></a>');
			}
		}

		document.write('</td></tr></table>');
		document.write('</div>');

		for(var iPage=0; iPage<laSection.tabPages.length; iPage++) {
			var laPage = laSection.tabPages[iPage];
			laPage.idCalque = 'menu_'+ iSection +"_"+ iPage;
			
			document.write('<div id="'+ laPage.idCalque +'" class="menuCalque">');
			document.write('<table cellspacing="0" cellpadding="0" border="0"><tr><td class="lmenu">');

			for(var iSousPage=0; iSousPage<laPage.tabPages.length; iSousPage++) {
				var laSousPage = laPage.tabPages[iSousPage];
			
				document.write('<a href="'+ laSousPage.lien +'"'+ (laSousPage.cible != "" ? ' target="'+ laSousPage.cible +'"' : '') +'><div>'+ laSousPage.titre +'</div></a>');
			}

			document.write('</td></tr></table>');
			document.write('</div>');

			if(laPage.tabPages.length > 0) {
				laPage.declancheur = 'item_'+ iSection +'_'+ iPage;

				var oDeclancheur = document.getElementById(laPage.declancheur);
				oDeclancheur.idCalque = laPage.idCalque;
				oDeclancheur.idDeclancheur = laPage.declancheur;
				oDeclancheur.onmouseover = mOverSection_2;
				oDeclancheur.onmouseout = mOutSection_2;

				var leCalque = document.getElementById(laPage.idCalque);
				leCalque.idCalqueParent = laSection.idCalque;
				leCalque.onmouseover = annulerTousLesTimeout;
				leCalque.onmouseout  = new Function('fermerSection_2(\''+ laPage.idCalque +'\', \''+ laSection.idFleche +'\', true)');
			}
		}

		var oDeclancheur = document.getElementById(laSection.declancheur);

		oDeclancheur.idCalque = laSection.idCalque;
		oDeclancheur.idFleche = laSection.idFleche;
		oDeclancheur.idDeclancheur = laSection.declancheur;
		oDeclancheur.onmouseover = mOverSection_1;
		oDeclancheur.onmouseout = mOutSection_1;

		var oFleche = document.getElementById(laSection.idFleche);
		oFleche.idCalque = laSection.idCalque;
		oFleche.idFleche = laSection.idFleche;
		oFleche.idDeclancheur = laSection.declancheur;
		oFleche.onmouseover = mOverSection_1;
		oFleche.onmouseout = mOutSection_1;

		var leCalque = document.getElementById(laSection.idCalque);
		leCalque.onmouseover = annulerTimeout_1;
		leCalque.onmouseout  = new Function('fermerSection_1(\''+ laSection.idCalque +'\', \''+ laSection.idFleche +'\')');
	}
}

document.onclick = fermerToutesLesSections_1;