var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

loaded = false;
menuVLoaded = false;
	
// mouse coordinates
xMin_V = 0;
xMax_V = 0;
yMin_V = 0;
yMax_V = 0;

scrollPosV = 0; // IE: handling scrollbar
currentMenuV = 0; // selected menu
menuVLRef = ""; // NN4: refer to image i layer

// Fix NS4 resize bug
function reDo() {
	if (innerWidth != origWidthV || innerHeight != origHeightV) {
		location.reload();
	}
}
if (nn4) {
	var origWidthV = innerWidth;
	var origHeightV = innerHeight;
	onResize = reDo;
}

// init layer-objects
function initV() {
	if (nn4) {
		menuVL = document.menubarV;
		menuCV = document.menucontentV;
		menuVLRef = "menubarV.document.";
		document.captureEvents(Event.MOUSEMOVE)
	} else	if (ie4) {
		menuVL = document.all.menubarV.style;
		menuCV = document.all.menucontentV.style;
		cursorV = "hand";
	} else if (dom) {
		menuVL = document.getElementById("menubarV").style;
		menuCV = document.getElementById("menucontentV").style;
		cursorV = "pointer";
	}
}

function initMenuV(dest,chemin) {
	hauteur = 20;
	largeur = 768;
	HTML_V = '<table height="'+ hauteur + '" width="'+ hauteur +'" cellpadding="0" cellspacing="0" border="0"><tr>';

	for (t=0; t<menuV.length; t++) {
		if (t == 0)
			HTML_V += '<td align="left"><a href="#" class="TopmenuDHTML" onMouseover="MM_swapImage(\'mairie\',\'\',\''+chemin+'images/bout1.gif\',1);over(' + t + ');window.status=\''+ menuV[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();" ><img name="mairie" src="'+chemin+'images/bout1.gif" id="m_V' + t + '_1" name="m_V' + t + '_1" border="0"></a></td>';
		else if (t == 1)
			HTML_V += '<td align="left"><a href="#" class="TopmenuDHTML" onMouseover="MM_swapImage(\'decouvrir\',\'\',\''+chemin+'images/bout2.gif\',1);over(' + t + ');window.status=\''+ menuV[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();" ><img name="decouvrir" src="'+chemin+'images/bout2.gif" id="m_V' + t + '_1" name="m_V' + t + '_1" border="0"></a></td>';
		else if (t == 2)
			HTML_V += '<td align="left"><a href="#" class="TopmenuDHTML" onMouseover="MM_swapImage(\'vivre\',\'\',\''+chemin+'images/bout3.gif\',1);over(' + t + ');window.status=\''+ menuV[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();" ><img name="vivre" src="'+chemin+'images/bout3.gif" id="m_V' + t + '_1" name="m_V' + t + '_1" border="0"></a></td>';
		else if (t == 3)
			HTML_V += '<td align="left"><a href="#" class="TopmenuDHTML" onMouseover="MM_swapImage(\'travailler\',\'\',\''+chemin+'images/bout4.gif\',1);over(' + t + ');window.status=\''+ menuV[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();" ><img name="travailler" src="'+chemin+'images/bout4.gif" id="m_V' + t + '_1" name="m_V' + t + '_1" border="0"></a></td>';
		else if (t == 4)
			HTML_V += '<td align="left"><a href="#" class="TopmenuDHTML" onMouseover="MM_swapImage(\'vieassos\',\'\',\''+chemin+'images/bout5.gif\',1);over(' + t + ');window.status=\''+ menuV[t][0] + '\';return true;" onMouseOut="MM_swapImgRestore();" ><img name="vieassos" src="'+chemin+'images/bout5.gif" id="m_V' + t + '_1" name="m_V' + t + '_1" border="0"></a></td>';

	}
	if (nn4) {
		document.menubarV.document.open();
		document.menubarV.document.write(HTML_V);
		document.menubarV.document.close();
	} else	if (ie4) {
		menubarV.innerHTML = HTML_V;
	} else if (dom) {
		document.getElementById("menubarV").innerHTML = HTML_V;
	}
	menuVL.top = ysPosV('posGifV') - 9;
	menuVL.left = xsPosV('posGifV') + 15;
	menuVL.visibility = "visible";
	menuVLoaded = true;
}

function ysPosV(what){
	if(ie4)
		return yIEV(eval('document.'+what));
	else if(nn4)
		return eval('document.'+what+'.y_V');
	else if(dom)
		return yIEV(document.getElementById(what));
}

function xsPosV(what){
	if(ie4)
		return xIEV(eval('document.'+what));
	else if(nn4)
		return eval('document.'+what+'.x_V');
	else if(dom)
		return xIEV(document.getElementById(what));
}

function yIEV(what){
	if(what.offsetParent)
		return parseInt(what.offsetTop + yIEV(what.offsetParent));
	else
		return parseInt(what.offsetTop);
}


function xIEV(what){
	if(what.offsetParent)
		return parseInt(what.offsetLeft + xIEV(what.offsetParent));
	else
		return parseInt(what.offsetLeft);
}

function xsHeightV(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 xsWidthV(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_V = 0;
mouse_X_V = 0;

// capture mouvement de la souris
function move(e) {
	if(ie4){
		mouse_Y_V = event.clientY;
		mouse_X_V = event.clientX;
	}
	else if(nn4 || dom){
		mouse_Y_V = e.pageY;
		mouse_X_V = e.pageX;
	}	

	if((mouse_X_V < xMin_V || mouse_X_V > xMax_V + 150|| mouse_Y_V < yMin_V || mouse_Y_V > yMax_V) && currentMenuV >=0 && menuVLoaded) {
		menuTimer = setTimeout('hideMenuV()',500);
	} else {
		clearTimeout(menuTimer);
	}
}

document.onmousemove = move;

function hideMenuV() {
	if ((mouse_X_V < xMin_V || mouse_X_V > xMax_V + 150  || mouse_Y_V < yMin_V || mouse_Y_V > yMax_V) && currentMenuV >=0 && menuVLoaded) {
		menuCV.visibility = "hidden";
		currentMenuV = 0;
	}
}

if (ie4 || dom) {
	window.onresize = posMenuNav;
}

function posMenuNav() {
	menuVL.left = xsPosV('posGifV');
}

function makemenuVcontent(what) {
	HTML_V = '';
	// FOND DE MENU
	if (menuV[what][2])
	{
	HTML_V += '<table cellpadding="1" cellspacing="0" border="0" bgcolor="#13AD60"><tr><td><table cellpadding="3" cellspacing="0" bgcolor="#009966">';
	for (t=2; t<=menuV[what].length-1; t=t+2) {
		if ((t+1)/2 == localPage && what == menuPageV) {
				HTML_V += '<tr><td class="menuSub"><img src="/sitedesign/standard/images/dot_trans.gif" width="7" height="1">' +  menuV[what][t] + '&nbsp;&nbsp;';
		} else {
			if (nn4)
				HTML_V += '<tr><td><img src="/sitedesign/standard/images/dot_trans.gif" width="7" height="1"><a href="' + menuV[what][t+1] + '" class="menuSub">' +  menuV[what][t] + '&nbsp;&nbsp;</a>';
			else
				HTML_V += '<tr><td class="menuSub" style="cursor:' + cursorV + '" id="sub_V' + t + '" name="sub_V' + t + '" onMouseover="subOver(' + t + ');window.status=\''+ menuV[what][t] +'\';return true;" onMouseout="subOut(' + t + ')" onClick="location.href=\''+ menuV[what][t+1] + '\';"><img src="/sitedesign/standard/images/dot_trans.gif" width="7" height="1">' + menuV[what][t] + '&nbsp;&nbsp;</td></tr>';
		}
	}
	HTML_V += '</table></td></tr></table><br>';
	}
	x_V = xsPosV(menuVLRef+'m_V'+what+'_1');
	y_V = ysPosV(menuVLRef+'m_V'+what+'_1');
//	alert("x_V =" + x_V);
//	alert("y_V =" + y_V);
	
	if (nn4) {
		document.menucontentV.document.open();
		document.menucontentV.document.write(HTML_V);
		document.menucontentV.document.close();
		x_V += xsPosV('posGifV');
		y_V += ysPosV('posGifV');
	} else 	if (ie4) {
		menucontentV.innerHTML = HTML_V;
	} else if (dom) {
		document.getElementById("menucontentV").innerHTML = HTML_V;
	}

	menuCV.left = x_V;
	menuCV.top = y_V + 20;
	menuCV.visibility = "visible";
	
//	render(menuCV.left);
//	render(menuCV.top);
	// mouse-over area for menus
	if (ie4 || dom) {
		scrollPosV = document.body.scrollTop;
	}
	xMin_V = x_V;
	xMax_V = x_V + xsWidthV('menucontentV');
	yMin_V = y_V - scrollPosV;
	yMax_V = y_V + xsHeightV('menucontentV')-scrollPosV;
	
	currentMenuV = what;
}

function makemenuVcontent2(what) {
//	width = xsPosV(menuVLRef+'m_V'+what+'_2') - xsPosV(menuVLRef+'m_V'+what+'_1')-11;

	HTML_V = '';
	// FOND DE MENU
	if (menuV[what][2])
	{
	HTML_V += '<br><table cellpadding="1" cellspacing="1" border="0" bgcolor="#0066CC"><tr><td bgcolor="#FFFFFF"><table cellpadding="3" cellspacing="0" border="0">';
	for (t=2; t<=menuV[what].length-1; t=t+2) {
		if ((t+1)/2 == localPage && what == menuPageV) {
				HTML_V += '<tr><td class="menuSub2"><img src="/sitedesign/standard/images/dot_trans.gif" width="5" height="1"><font color="#3399FF">' +  menuV[what][t] + '</font>&nbsp;&nbsp;</a>';
		} else {
			if (nn4)
				HTML_V += '<tr><td><img src="/sitedesign/standard/images/dot_trans.gif" width="7" height="1"><a href="' + menuV[what][t+1] + '" class="menuSub2">' +  menuV[what][t] + '&nbsp;&nbsp;</a>';
			else
				HTML_V += '<tr><td class="menuSub2" style="cursor:' + cursorV + '" id="sub_V' + t + '" name="sub_V' + t + '" onMouseover="subOver2(' + t + ');window.status=\''+ menuV[what][t] +'\';return true;" onMouseout="subOut2(' + t + ')" onClick="location.href=\''+ menuV[what][t+1] + '\'"><img src="/sitedesign/standard/images/dot_trans.gif" width="7" height="1">' + menuV[what][t] + '&nbsp;&nbsp;</td></tr>';
		}
	}
	HTML_V += '</table></td></tr></table><br>';
	}
	x_V = xsPosV(menuVLRef+'m_V'+what+'_1');
	y_V = ysPosV(menuVLRef+'m_V'+what+'_1');

	if (nn4) {
		document.menucontentV.document.open();
		document.menucontentV.document.write(HTML_V);
		document.menucontentV.document.close();
		x_V += xsPosV('posGifV');
		y_V += ysPosV('posGifV');
	} else 	if (ie4) {
		menucontentV.innerHTML = HTML_V;
	} else if (dom) {
		document.getElementById("menucontentV").innerHTML = HTML_V;
	}

	menuCV.left = 0;
	menuCV.top = y_V - 14;
	menuCV.visibility = "visible";
	// mouse-over area for menus
	if (ie4) {
		scrollPosV = document.body.scrollTop;
	}
	xMin_V = x_V;
	xMax_V = x_V + xsWidthV('menucontentV');
	yMin_V = y_V - scrollPosV;
	yMax_V = y_V + xsHeightV('menucontentV')-scrollPosV;
	
	currentMenuV = what;
}
	

function subOver(what) {
	if (ie4) {
		bg1V = eval('sub_V' + what);
	} else {
		bg1V = document.getElementById('sub_V' + what);	
	}
	bg1V.style.backgroundColor = "#16DD79";
	bg1V.style.color = "#FFFFFF";
	bg1V.style.fontWeight = "normal";
}

function subOver2(what) {
	if (ie4) {
		bg1V = eval('sub_V' + what);
	} else {
		bg1V = document.getElementById('sub_V' + what);	
	}
	bg1V.style.backgroundColor = "#16DD79";
	bg1V.style.color = "#FFFFFF";
	bg1V.style.fontWeight = "normal";
}

function subOut(what) {
	if (ie4) {
		bg1V = eval('sub_V' + what);
	} else {
		bg1V = document.getElementById('sub_V' + what);	
	}
	bg1V.style.backgroundColor = "#13AD60";
	bg1V.style.color = "#FFFFFF";
	bg1V.style.fontWeight = "normal";
}

function subOut2(what) {
	if (ie4) {
		bg1V = eval('sub_V' + what);
	} else {
		bg1V = document.getElementById('sub_V' + what);	
	}
	bg1V.style.backgroundColor = "#13AD60";
	bg1V.style.color = "#FFFFFF";
	bg1V.style.fontWeight = "normal";
}

function over(what) {
	if (currentMenuV > 0) {
		menuCV.visibility = "hidden";
	}
	currentMenuV = what;
	makemenuVcontent(what);
}

function over2(what) {
	if (currentMenuV > 0) {
		menuCV.visibility = "hidden";
	}
	currentMenuV = what;
	makemenuVcontent2(what);
}

function out(what) {
	menuCV.visibility = "hidden";
	currentMenuV = 0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}