// Fonctions graphiques du menu dynamique
// Author : yanhl	Date : 19/11/2001
// Location : Frame de gauche


function initializeMenu() {
	if (globalMenu.cover) {
		moveLayer("menu",0,globalMenu.coverHeight);
	}
	callMenu();
}

function callMenu() {
	updateMenu();
	arrageLayersPosition(); setTimeout("arrageLayersPosition()",100);
}

function arrageLayersPosition() {
	yBase = layerHeight("menu")+16;
	if (globalMenu.cover) {
		yBase += globalMenu.coverHeight;
	}
	moveLayer("defaultDescription",0,yBase);
	moveLayer("description",0,yBase);

	moveLayer("jumpMenu",0,yBase+Math.max( layerHeight("description"), layerHeight("defaultDescription")) + 20 );

}


function updateDescription(text) {
	if (text == '') text = '<spacer type="block" width="1" height="1">';
	text =	'<table cellspacing="0" cellpadding="8" border="0" width="150"><tr><td class="description">' + text;
	text += '</td></tr></table>';
	writeHTML("description",text);
	arrageLayersPosition();	setTimeout("arrageLayersPosition()",100);
}

function updateMenu() {
	tmpHTML = "";
	var currentSelected = 'none';
	var description = '<spacer type="block" width="1" height="1">';
	
	for (i=1; i<globalMenu.under.length; i++) {
		link = globalMenu.under[i].link;
		state = globalMenu.under[i].state;
		ext = (state==true) ? "_on" + imgExtension : imgExtension;
		
//		tmpHTML += '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td class="' + ((state==true) ? "fondmenuactif" : "fondmenu") + '">';
		if (link != "#") tmpHTML += '<a href="' + link + '" target="contenu" onclick="menuClose('+i+'); selectMenu(globalMenu.under['+i+']); callMenu(); parent.contenu.location.href=this.href; return false;" ';
		else			 tmpHTML += '<a href="#" onclick="menuClose('+i+'); selectMenu(globalMenu.under['+i+']); callMenu(); return false;" ';

		if (!state) {
			tmpHTML += 'onmouseover="' + globalMenu.under[i].imageName + '.src = ';
			tmpHTML += 'globalMenu.under['+i+'].imgOver.src; ';
			tmpHTML += 'updateDescription(globalMenu.under['+i+'].description); ';
			tmpHTML += 'displayLayer(\'description\'); ';
			tmpHTML += 'hideLayer(\'defaultDescription\'); ';
			tmpHTML += '"';
			tmpHTML += 'onmouseout="' + globalMenu.under[i].imageName + '.src = ';
			tmpHTML += 'globalMenu.under['+i+'].imgNormal.src; ';
			tmpHTML += 'displayLayer(\'defaultDescription\'); ';
			tmpHTML += 'hideLayer(\'description\'); ';
			tmpHTML += '"';
		} else {
			tmpHTML += 'onmouseover="" onmouseout="" '; // résoud un bug de NN4
		}

		tmpHTML += '>';
		tmpHTML += '<img src="' + gfxDirectory + globalMenu.under[i].imageURL + ext + '" border="0" name="' + globalMenu.under[i].imageName + '" height="20">';
		tmpHTML += '</a><br>';
//		tmpHTML += '</td></tr></table>';
		// Sous-menu
		if (state) {
			currentSelected = globalMenu.under[i];
			if (globalMenu.under[i].under.length>0) {
				tmpHTML += '<table cellspacing="0" cellpadding="1" border="0" width="100%">';
				tmpHTML += '<tr height="6"><td colspan="2" class="sousmenu"><spacer type="block" width="1" height="6"></td></tr>';
				for (j=1; j<globalMenu.under[i].under.length; j++) {
					tmpHTML += '<tr><td class="sousmenu" width="20"><spacer type="block" width="20" height="1"></td><td class="sousmenu"><span class="puce">&gt;&nbsp;</span>';
					tmpHTML += '<a href="' + globalMenu.under[i].under[j].link + '" target="contenu" class="sousmenu" ';

					tmpHTML += 'onmouseover="';
					tmpHTML += 'updateDescription(globalMenu.under['+i+'].under['+j+'].description); ';
					tmpHTML += 'displayLayer(\'description\'); ';
					tmpHTML += 'hideLayer(\'defaultDescription\'); ';
					tmpHTML += '"';
					tmpHTML += 'onmouseout="';
					tmpHTML += 'displayLayer(\'defaultDescription\'); ';
					tmpHTML += 'hideLayer(\'description\'); ';
					tmpHTML += '"';

					tmpHTML += '>' + globalMenu.under[i].under[j].name + "</a><br>";
					tmpHTML += '</td></tr>';
				}
				tmpHTML += '<tr height="6"><td colspan="2" class="sousmenu"><spacer type="block" width="1" height="6"></td></tr>';
				tmpHTML += '</table>';
			}
		}
	}


	writeHTML('menu',tmpHTML);

	tmpHTML = '	<table cellspacing="0" cellpadding="8" border="0" width="100%"><tr><td class="description">';
	if (currentSelected != "none") description = currentSelected.description;
	tmpHTML += 'Passez la souris sur les flèches du menu et découvrez le contenu des rubriques.';
	tmpHTML += '</td></tr></table>';
	writeHTML('defaultDescription',tmpHTML);



}
