// Initialisation ---------------------------

var xpos = ".top";

var isFolding = false;
var layUnfold = 0;
var corpLinks;

function initMenu() {
	var i = 1;
	while (i<=layRmax) {
		if (document.all) { 
			eval("option"+i+" = option"+i+"Div.style");
			eval("option"+i+"Div.style.visibility = 'visible'");
		}
		else if (document.layers) { 
			eval("option"+i+" = document.option"+i+"Div");
			eval("document.option"+i+"Div.visibility = 'show'");	
		}
		else if (document.getElementById) { 
			eval("option"+i+" = document.getElementById(\"option"+i+"Div\").style");
			eval("document.getElementById(\"option"+i+"Div\").style.visibility = 'visible'");		
		}
	i++;
	}
}


// Animation des menus ---------------------------------------

//Teste si il faut fermer une rubrique avant d'en ouvrir une nouvelle
function toggle(layerNum) {
	if (!isFolding) {
		if (layUnfold==0) {unfold(layerNum);}
		if (layUnfold!=0 && layUnfold!=layerNum) {fold(layUnfold,layerNum);} 
	}
}

//Fonction d'ouverture des rubriques
function unfold(layerNum) {
	var layLast, rep;
	if (layerNum>layLmax) {rep='/navigation';layLast=layRmax;} else {rep='/navigation';layLast=layLmax;}
	if (eval("parseInt(option"+(layerNum+1)+xpos+")")<=layOrig[layerNum]+layHeight[layerNum]) {
		isFolding = true; i = layerNum + 1;
		while (i<=layLast) {
			eval("option"+i+xpos+"= parseInt(option"+i+xpos+")+10");
			i++;
		}
		setTimeout('unfold('+layerNum+')',30);
	} else { 
		layUnfold=layerNum; 
		isFolding = false; 	
	}	
}		
	
//Fonction de fermeture des rubriques
function fold(layerNum,layToUnfold) {
	var layLast, rep;
	if (layerNum>layLmax) {rep='/navigation';layLast=layRmax;} else {rep='/navigation';layLast=layLmax;}
	if (eval("parseInt(option"+layLast+xpos+")")>layOrig[layLast]) {
		isFolding = true; i = layerNum + 1;
		while (i<=layLast) {
			eval("option"+i+xpos+"= parseInt(option"+i+xpos+")-10");
			i++;
		}
		setTimeout('fold('+layerNum+','+layToUnfold+')',30); 
	} else { 		
		layUnfold = 0; 
		isFolding = false;
		unfold(layToUnfold);
	}	
}

//Fonction rubrique ouverte
function setOpen(layerNum) {
	var layLast, rep, diff;
	if (layerNum>layLmax) {rep='/navigation';layLast=layRmax;} else {rep='/navigation';layLast=layLmax;}
	diff = (layOrig[layerNum]+layHeight[layerNum]-(eval("parseInt(option"+(layerNum+1+xpos)+")")))/10;
	isFolding = true; i = layerNum + 1;
	while (i<=layLast) {
		eval("option"+i+xpos+"= parseInt(option"+i+xpos+")+10*(1+parseInt(diff))");
		i++;	
	}
	layUnfold=layerNum; 
	isFolding = false; 
}



