
var minuterie = null;
var tabSections = new Array();

function oSection(declancheur) {
	this.declancheur = declancheur;
	this.tabPages = new Array();
}

function oPage(titre, lien, cible) {
	this.titre = titre;
	this.lien = lien;
	this.cible = cible;
}

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 ecrireMenu() {

	for(var iSection=0; iSection<tabSections.length; iSection++) {
		var laSection = tabSections[iSection];
		laSection.idDiv = "ms"+ iSection;

		var leDeclancheur = document.getElementById(laSection.declancheur);

		leDeclancheur.onmouseover = ouvrirSection;
		leDeclancheur.onmouseout = fermerSection;
		leDeclancheur.idDiv = laSection.idDiv;

		document.write('<div id="'+ laSection.idDiv +'" style="position:absolute;visibility:hidden;">');
		document.write('<table bordercolor="#F0D684" style="border-color:#F0D684;border-style:solid;border-width:3px;" border="3" cellspacing="0" cellpadding="0"><tr><td><table cellpadding="3" cellspacing="0" border="0">');

		for(var iPage=0; iPage<laSection.tabPages.length; iPage++) {
			var laPage = laSection.tabPages[iPage];
			laPage.idPage = laSection.idDiv +"p"+ iPage;

			document.write("<tr><td id=\""+ laPage.idPage +"\">"+ laPage.titre +"</td></tr>");

			var leTd = document.getElementById(laPage.idPage);
			leTd.onmouseover = leTd.onmouseout = mOverTd;
			leTd.onclick = chargerDoc;

			leTd.cible = laPage.cible;
			leTd.lien = laPage.lien;

			leTd.bgColor = tdBgColorOut;
			leTd.style.color = tdFontColorOut;

			leTd.style.cursor = "pointer";
		}

		document.write('</table></td></tr></table>');
		document.write('</div>');

		var leDiv = document.getElementById(laSection.idDiv);
		leDiv.idDiv = leDiv.id;

		leDiv.onmouseover = annulerTimeout;
		leDiv.onmouseout  = fermerSection;

	}

	positionnerCalques();

}

function positionnerCalques() {
	for(var iSection=0; iSection<tabSections.length; iSection++) {
		var laSection = tabSections[iSection];
		var leDeclancheur = document.getElementById(laSection.declancheur);
		var leDiv = document.getElementById(laSection.idDiv);

		var pos = new oPosition(leDeclancheur);
		leDiv.style.left = pos.posX;
		leDiv.style.top = pos.posY + leDeclancheur.offsetHeight - 2;

	}
}

function chargerDoc() {
	if(this.cible != "")
		window.open(this.lien, this.cible);
	else
		window.open(this.lien, "_self");
}

function mOverTd() {

	if(this.bgColor == tdBgColorOut) {
		this.bgColor = tdBgColorOver;
		this.style.color = tdFontColorOver;
	} else {
		this.bgColor = tdBgColorOut;
		this.style.color = tdFontColorOut;
	}
}

function cacherCalque(idCalque) {
	var leCalque = document.getElementById(idCalque);
	leCalque.style.visibility = "hidden";
}

function annulerTimeout() {
	clearTimeout(minuterie);
	minuterie = null;
}

function ouvrirSection() {
	fermerToutesLesSections();

	var leDiv = document.getElementById(this.idDiv);
	leDiv.style.visibility = "visible";
}

function fermerSection() {
	minuterie = setTimeout("cacherCalque(\""+ this.idDiv +"\")", 300);
}

function fermerToutesLesSections() {
	annulerTimeout();

	for(var iSection=0; iSection<tabSections.length; iSection++) {
		cacherCalque(document.getElementById(tabSections[iSection].idDiv).id);
	}
}

document.onclick = fermerToutesLesSections;
window.onresize = positionnerCalques;