var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;
var imageDir = "/sitedesign/pld/images/";
var homeDir = "/com";

loaded = false;
menuLoaded = false;

// mouse coordinates
xMin = 0;
xMax = 0;
yMin = 0;
yMax = 0;

scrollPos = 0; // IE: handling scrollbar
currentMenu = 0; // selected menu
menuLRef = ""; // NN4: refer to image i layer

// Fix NS4 resize bug
function reDo() {
	if (innerWidth != origWidth || innerHeight != origHeight) {
		location.reload();
	}
}
if (nn4) {
	var origWidth = innerWidth;
	var origHeight = innerHeight;
	onResize = reDo;
}

// init layer-objects
function init() {
	if (nn4) {
		menuL = document.menubar;
		menuC = document.menucontent;
		menuLRef = "menubar.document.";
		document.captureEvents(Event.MOUSEMOVE)
	} else	if (ie4) {
		menuL = document.all.menubar.style;
		menuC = document.all.menucontent.style;
		cursor = "hand";
	} else if (dom) {
		menuL = document.getElementById("menubar").style;
		menuC = document.getElementById("menucontent").style;
		cursor = "pointer";
	}
}

function initMenu(dest) {

	HTML = '<table cellpadding="0" cellspacing="0" border="0">';
	HTML += '<tr><td><img name="im1" src="' + imageDir + 'barre_01.png" border="0"></td>';
	
	for (t=0; t<menu.length; t++) {
		if (t == 0)
			HTML += '<td valign="top" bgcolor=#CCCCCC><img src="' + imageDir + 'dot_trans.gif" width="1" height="1" id="m' + t + '_1" name="m' + t + '_1" border="0"></td><td align="left"><a href="#" class="TopmenuDHTML"  onMouseover="MM_swapImage(\'im01\',\'\',\'' + imageDir + 'barre_02o.png\',1);over(' + t + ');window.status=\''+ menu[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();"><img name="im01" src="' + imageDir + 'barre_02.png" border="0"></a></td>';
		else if (t == 1)
			HTML += '<td valign="top" bgcolor=#EC008C><img src="' + imageDir + 'dot_trans.gif" width="1" height="1" id="m' + t + '_1" name="m' + t + '_1" border="0"></td><td align="left"><a href="#" class="TopmenuDHTML"  onMouseover="MM_swapImage(\'im2\',\'\',\'' + imageDir + 'barre_03o.png\',1);over(' + t + ');window.status=\''+ menu[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();"><img name="im2" src="' + imageDir + 'barre_03.png" border="0"></a></td>';
		else if (t == 2)
			HTML += '<td valign="top" bgcolor=#EC008C><img src="' + imageDir + 'dot_trans.gif" width="1" height="1" id="m' + t + '_1" name="m' + t + '_1" border="0"></td><td align="left"><a href="#" class="TopmenuDHTML"  onMouseover="MM_swapImage(\'im3\',\'\',\'' + imageDir + 'barre_04o.png\',1);over(' + t + ');window.status=\''+ menu[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();"><img name="im3" src="' + imageDir + 'barre_04.png" border="0"></a></td>';
		else if (t == 3)
			HTML += '<td valign="top" bgcolor=#EC008C><img src="' + imageDir + 'dot_trans.gif" width="1" height="1" id="m' + t + '_1" name="m' + t + '_1" border="0"></td><td align="left"><a href="#" class="TopmenuDHTML"  onMouseover="MM_swapImage(\'im4\',\'\',\'' + imageDir + 'barre_05o.png\',1);over(' + t + ');window.status=\''+ menu[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();"><img name="im4" src="' + imageDir + 'barre_05.png" border="0"></a></td>';
		else if (t == 4)
			HTML += '<td valign="top" bgcolor=#EC008C><img src="' + imageDir + 'dot_trans.gif" width="1" height="1" id="m' + t + '_1" name="m' + t + '_1" border="0"></td><td align="left"><a href="#" class="TopmenuDHTML"  onMouseover="MM_swapImage(\'im5\',\'\',\'' + imageDir + 'barre_06o.png\',1);over(' + t + ');window.status=\''+ menu[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();"><img name="im5" src="' + imageDir + 'barre_06.png" border="0"></a></td>';
		else if (t == 5)
			HTML += '<td valign="top" bgcolor=#EC008C><img src="' + imageDir + 'dot_trans.gif" width="1" height="1" id="m' + t + '_1" name="m' + t + '_1" border="0"></td><td align="left"><a href="#" class="TopmenuDHTML"  onMouseover="MM_swapImage(\'im6\',\'\',\'' + imageDir + 'barre_07o.png\',1);over(' + t + ');window.status=\''+ menu[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();"><img name="im6" src="' + imageDir + 'barre_07.png" border="0"></a></td>';
	}
	HTML += '<td valign="top" bgcolor=#EC008C><img src="' + imageDir + 'dot_trans.gif" width="1" height="1" border="0"></td></tr></table>';

	if (nn4) {
		document.menubar.document.open();
		document.menubar.document.write(HTML);
		document.menubar.document.close();
	} else	if (ie4) {
		menubar.innerHTML = HTML;
	} else if (dom) {
		document.getElementById("menubar").innerHTML = HTML;
	}
	menuL.top = ysPos('posGif') + "px";	
	menuL.left = xsPos('posGif') + "px";
	menuL.visibility = "visible";
	menuLoaded = true;
}


function ysPos(what){
	if(ie4)
		return yIE(eval('document.'+what));
	else if(nn4)
		return eval('document.'+what+'.y');
	else if(dom)
		return yIE(document.getElementById(what));
}

function xsPos(what){
	if(ie4)
		return xIE(eval('document.'+what));
	else if(nn4)
		return eval('document.'+what+'.x');
	else if(dom)
		return xIE(document.getElementById(what));
}

function yIE(what){
	if(what.offsetParent)
		return parseInt(what.offsetTop + yIE(what.offsetParent));
	else
		return parseInt(what.offsetTop);
}

function xIE(what){
	if(what.offsetParent)
		return parseInt(what.offsetLeft + xIE(what.offsetParent));
	else
		return parseInt(what.offsetLeft);
}

function xsHeight(what) {
	if(ie4)
		return(parseInt(eval('document.all.' + what + '.scrollHeight')));
	else if(nn4)
		return(eval('document.' + what + '.clip.bottom'));
	else if(dom)
		return(parseInt(eval('document.getElementById("' + what + '").offsetHeight')));
}

function xsWidth(what) {
	if(ie4)
		return(parseInt(eval('document.all.' + what + '.scrollWidth')));
	else if(nn4)
		return(eval('document.' + what + '.clip.right'));
	else if(dom)
		return(parseInt(eval('document.getElementById("' + what + '").offsetWidth')));
}

var menuTimer = null;

mouseY = 0;
mouseX = 0;

// capture mouse movement
function move(e) {
	if(ie4){
		mouseY = event.clientY;
		mouseX = event.clientX;
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}	
	
	if((mouseX < xMin || mouseX > xMax || mouseY < yMin || mouseY > yMax) && currentMenu >=0 && menuLoaded) {
		menuTimer = setTimeout('hideMenu()',300);
	} else {
		clearTimeout(menuTimer);
	}
}

document.onmousemove = move;

function hideMenu() {
	if ((mouseX < xMin || mouseX > xMax || mouseY < yMin || mouseY > yMax) && currentMenu >=0 && menuLoaded) {
		menuC.visibility = "hidden";
		currentMenu = 0;
	}
	restoreImages("im1","im2","im3","im4","im5","im6");

}

if (ie4 || dom) {
	window.onresize = posMenuNav;
}

function posMenuNav() {
	menuL.left = xsPos('posGif') + "px";
}

function makeMenuContent(what) {

	HTML = '';
	if (menu[what][2])
	{
	HTML += '<table cellpadding="0" cellspacing="0" border="0"><tr><td><img src="' + imageDir + 'espace.gif" width="11" height="19"></td><td><font color="#FFFFFF"><a class="TopmenuDHTML" href="' + menu[what][1] + '" onMouseover="window.status=\''+ menu[what][0] +'\';return true;"></a></font></td><td><img src="' + imageDir + 'espace.gif" width="11" height="19"></td></tr></table>';
	HTML += '<table cellpadding="0" cellspacing="0" border="0" background="/sitedesign/pld/images/pix-menu.png"><tr><td><table cellpadding="3" cellspacing="0" border="0" width=170>';
	for (t=2; t<=menu[what].length-1; t=t+2) {
		if ((t+1)/2 == localPage && what == menuPage) {
				HTML += '<tr><td><img src="' + imageDir + 'dot_trans.gif" width="1" height="1">' +  menu[what][t] + '</a></td></tr>';
		} else {
			if (nn4)
				HTML += '<tr><td><img src="' + imageDir + 'dot_trans.gif" width="7" height="1"><a href="' + menu[what][t+1] + '" >' +  menu[what][t] + '</a></td></tr>';
			else{
				HTML += '<tr><td height="19" class="menuSub'+ what +'" style="color:#999999; cursor:'+ cursor + '" id="sub' + t + '" name="sub'+ t  + '" onMouseover="subOver(' + t + ');window.status=\''+ menu[what][t] +'\';MM_swapImage(\'puce'+t+'\',\'\',\'/sitedesign/pld/images/puce_dhtmlsurvol.png\',1);return true;" onMouseout="subOut(' + t + ');MM_swapImgRestore();return true;" onClick="location.href=\''+ menu[what][t+1] + '\'">&nbsp;<img id="puce'+t+'" src="/sitedesign/pld/images/espace.png" width="4" height="7">&nbsp;' + menu[what][t] + '</td></tr>';
				if (t<menu[what].length-2)
				{
				
					HTML += '<tr><td><img src="' + imageDir + 'pix-separateur.png" height="1" width="100%"></td></tr>';
				}
				}
//				HTML += '<tr><td class="menuSub" style="cursor:'
//				+ cursor + '" id="sub' + t + '" name="sub'
//				+ t + '" onMouseover="subOver(' + t + ')" onMouseout="subOut(' + t + ')" onClick="location.href=\''+ menu[what][t+1] + '\'"><img src="' + imageDir + 'dot_trans.gif" width="7" height="1">' + menu[what][t] + '&nbsp;&nbsp;</td></tr>';
		}
	}
	HTML += '</table></td></tr></table><br>';
	}
	x = xsPos(menuLRef+'m'+what+'_1') + 2;
	y = ysPos(menuLRef+'m'+what+'_1');

	if (nn4) {
		document.menucontent.document.open();
		document.menucontent.document.write(HTML);
		document.menucontent.document.close();
		x += xsPos('posGif');
		y += ysPos('posGif');
	} else 	if (ie4) {
		menucontent.innerHTML = HTML;
	} else if (dom) {
		document.getElementById("menucontent").innerHTML = HTML;
	}

	menuC.left = x+ "px";
	menuC.top = y+ "px";
	menuC.visibility = "visible";
	// mouse-over area for menus
	if (ie4) {
		scrollPos = document.body.scrollTop;
	}
	xMin = x;
	xMax = x + xsWidth('menucontent');
	yMin = y - scrollPos
	yMax = y + xsHeight('menucontent')-scrollPos;

	currentMenu = what;
}

function subOver(what) {
	if (ie4) {
		bg1 = eval('sub' + what);
	} else {
		bg1 = document.getElementById('sub' + what);
	}
	//bg1.style.backgroundColor = "#FF3399";
	bg1.style.color = "#FF3399";

}

function subOut(what) {
	if (ie4) {
		bg1 = eval('sub' + what);
	} else {
		bg1 = document.getElementById('sub' + what);
	}
	//bg1.style.backgroundColor = "#FF3399";
	bg1.style.color = "#999999";

}













function over(what) {
	if (currentMenu > 0) {
		menuC.visibility = "hidden";
	}
	currentMenu = what;
	makeMenuContent(what);

}

function out(what) {
	menuC.visibility = "hidden";
	currentMenu = 0;
	//MM_swapImgRestore();

}

