var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

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) {
	hauteur = 140 * (menu.length-1);
	HTML = '<table width="130" height="'+ hauteur + '" cellpadding="0" cellspacing="0" border="0">';

	for (t=0; t<menu.length-1; t++) {
//		if (t != menuPage)
// nedenstående linie er ændret
//		{
			HTML += '<tr><td valign="top" align="center"><img src="/sitedesign/broglie/images/dot_trans.gif" width="1" height="5" id="m' + t + '_1" name="m' + t + '_1"></td><td align="right"><a href="javascript:location.href=\''+ menu[t][1] + '\';" class="TopmenuDHTML" onMouseover="over(' + t + ');window.status=\''+ menu[t][0] + '\';return true;"><img src="/sitedesign/broglie/images/decouvrir.jpg" width="150" border="0"><br/><img src="/sitedesign/broglie/images/decouvrir.gif" width="150" border="0"><br/>' + menu[t][0].substring(10) + '</a></td><td><img src="/sitedesign/broglie/images/dot_trans.gif" width="1" height="5" id="m' + t + '_2" name="m' + t + '_2"></td></tr>';
//		}
//		else
//		{
//			HTML += '<tr><td><a href="javascript:location.href=\''+ menu[t][1] + '\';" class="TopmenuDHTML" onMouseover="over(' + t + ');" >' + menu[t][0] + '</a></td></tr>';
//		}	
	}
	HTML += '</table><br/><table width="130" height="141" cellpadding="0" cellspacing="0" border="0">';
	for (t=menu.length-1; t<menu.length; t++) {
//		if (t != menuPage)
//// nedenstående linie er ændret
//		{
			HTML += '<tr><td valign="top" align="center"><img src="/sitedesign/broglie/images/dot_trans.gif" width="1" height="5" id="m' + t + '_1" name="m' + t + '_1"></td><td><a href="javascript:location.href=\''+ menu[t][1] + '\';" class="Topmenu2DHTML" onMouseover="over(' + t + ');window.status=\''+ menu[t][0] +'\';return true;"><img src="/sitedesign/broglie/images/vivre.jpg" width="150" border="0"><br/><img src="/sitedesign/broglie/images/vivre.gif" border="0"><br/><img src="/sitedesign/broglie/images/dot_trans.gif" width="20" height="10" border="0">' + menu[t][0].substring(6) + '</a></td><td><img src="/sitedesign/broglie/images/dot_trans.gif" width="1" height="5" id="m' + t + '_2" name="m' + t + '_2"></td></tr>';
//		}
//		else
//		{
//			HTML += '<tr><td><a href="javascript:;" class="Topmenu2DHTML" onMouseover="over(' + t + ');">' + menu[t][0] + '</a></td></tr>';
//		}	
	}
	HTML += '</table><br><img src="/sitedesign/broglie/images/dot_trans.gif" width="1" height="1">';
	
	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')-30;
	menuL.left = xsPos('posGif');
	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;

mouse_Y = 0;
mouse_X = 0;

// capture mouvement de la souris
function move(e) {
	if(ie4){
		mouse_Y = event.clientY;
		mouse_X = event.clientX;
	}
	else if(nn4 || dom){
		mouse_Y = e.pageY;
		mouse_X = e.pageX;
	}	

	if((mouse_X < xMin || mouse_X-135 > xMax || mouse_Y < yMin || mouse_Y > yMax+100) && currentMenu >=0 && menuLoaded) {
		menuTimer = setTimeout('hideMenu()',500);
	} else {
		clearTimeout(menuTimer);
	}
}

document.onmousemove = move;

function hideMenu() {
	if ((mouse_X < xMin || mouse_X-135 > xMax || mouse_Y < yMin || mouse_Y > yMax+100) && currentMenu >=0 && menuLoaded) {
		menuC.visibility = "hidden";
		currentMenu = 0;
	}
}

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

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

function makemenucontent(what) {
//	width = xsPos(menuLRef+'m'+what+'_2') - xsPos(menuLRef+'m'+what+'_1')-11;

	HTML = '';
	// FOND DE MENU
	if (menu[what][2])
	{
	HTML += '<table cellpadding="1" cellspacing="1" border="0"><tr><td bgcolor="#3399FF"><table cellpadding="3" cellspacing="0" border="0" bgcolor="#CCE6FF">';
	for (t=2; t<=menu[what].length-1; t=t+2) {
//		if ((t+1)/2 == localPage && what == menuPage) {
//				HTML += '<tr><td class="menuSub" bgcolor="#C5CCD2"><img src="/sitedesign/broglie/images/dot_trans.gif" width="7" height="1"><font color="#B6E005">' +  menu[what][t] + '</font>&nbsp;&nbsp;</a>';
//		} else {
			if (nn4)
				HTML += '<tr><td><img src="/sitedesign/broglie/images/dot_trans.gif" width="7" height="1"><a href="' + menu[what][t+1] + '" class="menuSub">' +  menu[what][t] + '&nbsp;&nbsp;</a>';
			else
				HTML += '<tr><td class="menuSub" style="cursor:' + cursor + '" id="sub' + t + '" name="sub' + t + '" onMouseover="subOver(' + t + ');window.status=\''+ menu[what][t] +'\';return true;" onMouseout="subOut(' + t + ')" onClick="location.href=\''+ menu[what][t+1] + '\';"><img src="/sitedesign/broglie/images/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');
	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 + 120;
	menuC.top = y + 3;
	menuC.visibility = "visible";
	
	// mouse-over area for menus
	if (ie4) {
		scrollPos = document.body.scrollTop;
	}
//	alert(scrollPos);
	
	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 = "#F5FAFF";
	bg1.style.color = "#3366CC";
	bg1.style.fontWeight = "normal";
}

function subOut(what) {
	if (ie4) {
		bg1 = eval('sub' + what);
	} else {
		bg1 = document.getElementById('sub' + what);	
	}
	bg1.style.backgroundColor = "#CCE6FF";
	bg1.style.color = "#3399FF";
	bg1.style.fontWeight = "normal";
}

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

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

