// ===================================================================================
// ===================================================================================
// Module CBM : script de barres de menus
// -----------------------------------------------------------------------------------
// Features :
// - cross-browser support
// - unlimited levels
// - full personalisable style
// - multiple occurence on single page
// - horizontal or vertical appearance
// - XHTML compliant
// - Microsoft filters support (IE only)
// -----------------------------------------------------------------------------------
// Création	: 30/12/2006 - SEB
// M. à j.	: XX/XX/XXXX - XXX - ...
//
// ===================================================================================
// ===================================================================================

tabChildren = new Array();
idMenu = -1;
curFather = null;
curRoot = null;
actRoot = null;
hMenu = null;
mIE = false;

function getId(vId)
{
	return(document.getElementById(vId));
}

function creMenu(vTabMenu, posX, posY)
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		mIE = true;
		if (IEFilter != "") IEFilter += "; ";
	}
	else IEFilter = "";
	idMenu++;
	tabChildren[idMenu] = new Array();
	vIdItem = -1;
	var pX = posX;
	var pY = posY;
	var vHMargin = MENU_TEMPLATE[0][2] + MENU_TEMPLATE[0][4] + MENU_TEMPLATE[0][6] + MENU_TEMPLATE[0][8];
	for(var i=0; i < vTabMenu.length; i++)
	{
		if ( (mType == 0) && (i != 0) )
		{
			pX+= vTabMenu[i-1][2];
			pX+=MENU_TEMPLATE[0][12];
		}
		if ( (mType == 1) && (i != 0) )
		{
			pY+= MENU_TEMPLATE[0][0];
			pY+=MENU_TEMPLATE[0][12];
		}
		creItem(vTabMenu[i], true, pX, pY, null, 0, false, false);
	}
}

function creItem(vItem, vRoot, posX, posY, vFather, vDepth, vFirst, vLast)
{
	vIdItem++;
	var curId = vIdItem;
	var vHTML = '';
	vaction = "";
	if (typeof(vItem[1]) == 'string') vaction = vItem[1];
	var vHMargin = MENU_TEMPLATE[vDepth][2] + MENU_TEMPLATE[vDepth][4] + MENU_TEMPLATE[vDepth][6] + MENU_TEMPLATE[vDepth][8];
	var vVMargin = MENU_TEMPLATE[vDepth][1] + MENU_TEMPLATE[vDepth][3] + MENU_TEMPLATE[vDepth][5] + MENU_TEMPLATE[vDepth][7];
	if (vDepth!=0) tabChildren[idMenu][vIdItem] = vFather;
	if (vDepth==0)
	{
		vHTML += '<div style="z-index: ' + eval(defZIndex+vDepth) + '; position: absolute; top: ' + posY + 'px; left: ' + posX + 'px; width: ' + eval(vItem[2]) + 'px; height: ' + eval(MENU_TEMPLATE[0][0]) + 'px; ">';
		if (mIFrames) vHTML += '<iframe scrolling="no" frameborder="0" src="javascript: false;" style="width: ' + eval(vItem[2]) + 'px; height: ' + eval(MENU_TEMPLATE[0][0]) + 'px; position: absolute; top: 0px; left: 0px;"><\/iframe>';
		if (mDeploy == 0) vHTML += '<div class="rootmenu" id="r' + idMenu  + vIdItem + '" onmouseover="this.className = \'rootmenuover\'; menuMouseOverRoot(' + vIdItem + ', ' + idMenu + ');" onmouseout="menuMouseOut(' + idMenu + ');" onclick="this.className = \'rootmenuactive\'; menuMouseOver(' + vIdItem + ', ' + idMenu + ', true);' + vaction+'" style="z-index: ' + eval(defZIndex+vDepth) + '; padding: ' + MENU_TEMPLATE[0][1] + 'px ' + MENU_TEMPLATE[0][2] + 'px ' + MENU_TEMPLATE[0][3] + 'px ' + MENU_TEMPLATE[0][4] + 'px; border-width: ' + MENU_TEMPLATE[0][5] + 'px ' + MENU_TEMPLATE[0][6] + 'px ' + MENU_TEMPLATE[0][7] + 'px ' + MENU_TEMPLATE[0][8] + 'px; width: ' + eval(vItem[2]-vHMargin) + 'px; height: ' + eval(MENU_TEMPLATE[0][0]-vVMargin) + 'px; cursor: pointer; position: absolute;">' + vItem[0];
		else  vHTML += '<div class="rootmenu" id="r' + idMenu  + vIdItem + '" onmouseover="menuMouseOverRoot(' + vIdItem + ', ' + idMenu + '); this.className = \'rootmenuactive\'; menuMouseOver(' + vIdItem + ', ' + idMenu + ', true);" onclick="' + vaction + '" onmouseout="menuMouseOut(' + idMenu + ');" style="z-index: ' + eval(defZIndex+vDepth) + '; padding: ' + MENU_TEMPLATE[0][1] + 'px ' + MENU_TEMPLATE[0][2] + 'px ' + MENU_TEMPLATE[0][3] + 'px ' + MENU_TEMPLATE[0][4] + 'px; border-width: ' + MENU_TEMPLATE[0][5] + 'px ' + MENU_TEMPLATE[0][6] + 'px ' + MENU_TEMPLATE[0][7] + 'px ' + MENU_TEMPLATE[0][8] + 'px; width: ' + eval(vItem[2]-vHMargin) + 'px; height: ' + eval(MENU_TEMPLATE[0][0]-vVMargin) + 'px; cursor: pointer; position: absolute;">' + vItem[0];
		vHTML += '<\/div><\/div>';
		document.write(vHTML);
		curWidth = vItem[2];
		if ( (vItem[1] != null) && (typeof(vItem[1]) != 'string') )
		{
			if (vItem[1].length == 1) creItem(vItem[1][0], false, eval(posX+MENU_TEMPLATE[1][12]), eval(MENU_TEMPLATE[vDepth+1][13] + posY + MENU_TEMPLATE[0][0]), curId, vDepth+1, true, true);
			else
			{
				creItem(vItem[1][0], false, eval(posX+MENU_TEMPLATE[1][12]), eval(MENU_TEMPLATE[vDepth+1][13] + posY + MENU_TEMPLATE[0][0]), curId, vDepth+1, true, false);
				for(var i=1; i < ((vItem[1].length)-1); i++) creItem(vItem[1][i], false, eval(posX+MENU_TEMPLATE[1][12]), eval(MENU_TEMPLATE[vDepth+1][13] + posY + ((i+1)*(MENU_TEMPLATE[1][0]))), curId, vDepth+1, false, false);
				creItem(vItem[1][i], false, eval(posX+MENU_TEMPLATE[1][12]), eval(MENU_TEMPLATE[vDepth+1][13] + posY + ((i+1)*(MENU_TEMPLATE[1][0]))), curId, vDepth+1, false, true);
			}
		}
	}
	else
	{
		if (typeof(vItem[2]) != "undefined") wWidth = vItem[2];
		else wWidth = curWidth;
		bTop = MENU_TEMPLATE[vDepth][5];
		bBot = MENU_TEMPLATE[vDepth][7];
		if ( (MENU_TEMPLATE[vDepth][14]) && (!vFirst) )
		{
			vVMargin-= MENU_TEMPLATE[vDepth][5];
			var bTop = 0;
		}
		if ( (MENU_TEMPLATE[vDepth][15]) && (!vLast) )
		{
			vVMargin-= MENU_TEMPLATE[vDepth][7];
			var bBot = 0;
		}
		if ( (vItem[1] != null) && (typeof(vItem[1]) != 'string') )
		{
			vHTML += '<div id="b' + idMenu  + vIdItem + '" style="' + IEFilter + 'z-index: ' + eval(defZIndex+vDepth) + '; width: ' + wWidth + 'px; height: ' + MENU_TEMPLATE[vDepth][0] + 'px; display: none; position: absolute; top: ' + posY + 'px; left: ' + posX + 'px;">';
			if (mIFrames) vHTML += '<iframe allowtransparency="true" unselectable="on" scrolling="no" frameborder="0" src="" style="position: absolute; display: block; width: ' + wWidth + 'px; height: ' + MENU_TEMPLATE[vDepth][0] + 'px; position: absolute; top: 0px; left: 0px;"><\/iframe>';
			vHTML += '<div class="menu" id="m' + idMenu  + vIdItem + '" onmouseout="menuMouseOut(' + idMenu + ');" onmouseover="this.className = \'menuactive\'; menuMouseOver(' + vIdItem + ', ' + idMenu + ', true);" style="position: absolute; z-index: ' + eval(defZIndex+vDepth) + '; padding: ' + MENU_TEMPLATE[vDepth][1] + 'px ' + MENU_TEMPLATE[vDepth][2] + 'px ' + MENU_TEMPLATE[vDepth][3] + 'px ' + MENU_TEMPLATE[vDepth][4] + 'px; border-width: ' + bTop + 'px ' + MENU_TEMPLATE[vDepth][6] + 'px ' + bBot + 'px ' + MENU_TEMPLATE[vDepth][8] + 'px; width: ' + eval(wWidth-vHMargin) + 'px; height: ' + eval(MENU_TEMPLATE[vDepth][0]-vVMargin) + 'px; cursor: pointer;"><div style="float: left;">' + vItem[0] + '<\/div><div style="float: right;"><img style="vertical-align: middle;" src="' + menPathImg + 'submenu.gif" alt="Sous-menu" title="" /><\/div>';
			vHTML += '<\/div><\/div>';
			document.write(vHTML);
			var nposX = parseInt(getId('m' + idMenu  + vIdItem).style.width.substr(0, (getId('m' + idMenu  + vIdItem).style.width.length-2))) + vHMargin + posX + MENU_TEMPLATE[vDepth+1][12];
			if (vItem[1].length == 1) creItem(vItem[1][0], false, nposX, posY, curId, vDepth+1, true, true);
			else
			{
				creItem(vItem[1][0], false, nposX, posY + MENU_TEMPLATE[vDepth+1][13], curId, vDepth+1, true, false);
				for(var i=1; i < ((vItem[1].length)-1); i++) creItem(vItem[1][i], false, nposX, posY + (i*MENU_TEMPLATE[vDepth+1][0]) + MENU_TEMPLATE[vDepth+1][13], curId, vDepth+1, false, false);
				creItem(vItem[1][i], false, nposX, posY + (i*MENU_TEMPLATE[vDepth+1][0]) + MENU_TEMPLATE[vDepth+1][13], curId, vDepth+1, false, true);
			}
		}
		else
		{
			vHTML += '<div id="b' + idMenu  + vIdItem + '" style="' + IEFilter + 'z-index: ' + eval(defZIndex+vDepth) + '; width: ' + wWidth + 'px; height: ' + MENU_TEMPLATE[vDepth][0] + 'px; display: none; position: absolute; top: ' + posY + 'px; left: ' + posX + 'px;">';
			if (mIFrames) vHTML += '<iframe unselectable="on" scrolling="no" frameborder="0" src="" style="position: absolute; display: block; width: ' + wWidth + 'px; height: ' + MENU_TEMPLATE[vDepth][0] + 'px; position: absolute; top: 0px; left: 0px;"><\/iframe>';
			if (vItem[0] == "-") vHTML += '<div class="menu" id="m' + idMenu  + vIdItem + '" onmouseout="this.className = \'menu\'; menuMouseOut(' + idMenu + ');" onmouseover="menuMouseOver(' + vIdItem + ', ' + idMenu + ', false);" style="position: absolute; z-index: ' + eval(defZIndex+vDepth) + '; padding: ' + MENU_TEMPLATE[vDepth][1] + 'px ' + MENU_TEMPLATE[vDepth][2] + 'px ' + MENU_TEMPLATE[vDepth][3] + 'px ' + MENU_TEMPLATE[vDepth][4] + 'px; border-width: ' + bTop + 'px ' + MENU_TEMPLATE[vDepth][6] + 'px ' + bBot + 'px ' + MENU_TEMPLATE[vDepth][8] + 'px; width: ' + eval(wWidth-vHMargin) + 'px; height: ' + eval(MENU_TEMPLATE[vDepth][0]-vVMargin) + 'px;"><hr />';
			else vHTML += '<div class="menu" id="m' + idMenu  + vIdItem + '" onclick="' + vaction + '" onmouseout="this.className = \'menu\'; menuMouseOut(' + idMenu + ');" onmouseover="this.className = \'menuover\'; menuMouseOver(' + vIdItem + ', ' + idMenu + ', false);" style="position: absolute; z-index: ' + eval(defZIndex+vDepth) + '; padding: ' + MENU_TEMPLATE[vDepth][1] + 'px ' + MENU_TEMPLATE[vDepth][2] + 'px ' + MENU_TEMPLATE[vDepth][3] + 'px ' + MENU_TEMPLATE[vDepth][4] + 'px; border-width: ' + bTop + 'px ' + MENU_TEMPLATE[vDepth][6] + 'px ' + bBot + 'px ' + MENU_TEMPLATE[vDepth][8] + 'px; width: ' + eval(wWidth-vHMargin) + 'px; height: ' + eval(MENU_TEMPLATE[vDepth][0]-vVMargin) + 'px; cursor: pointer;">' + vItem[0];
			vHTML += '<\/div><\/div>';
			document.write(vHTML);
		}
	}
}

function menuMouseOver(idFather, vIdMenu, isFather)
{
	clearTimeout(hMenu);
	if (isFather)
	{
		var vFather = tabChildren[vIdMenu][idFather];
		if ( (curFather != vFather) && (curFather != idFather) )
		{
			for(var i=0; i < tabChildren[vIdMenu].length; i++)
			{
				if (tabChildren[vIdMenu][i] == curFather) getId('b'+vIdMenu+i).style.display="none";
				if ( (tabChildren[vIdMenu][i] == vFather) && (i != idFather) )
				{
					for(var j=0; j < tabChildren[vIdMenu].length; j++) {if (tabChildren[vIdMenu][j] == i) getId('b'+vIdMenu+j).style.display="none";}
					if (getId('m'+vIdMenu+i)) getId('m'+vIdMenu+i).className = "menu";
				}
			}
			if (getId('m'+vIdMenu+curFather)) getId('m'+vIdMenu+curFather).className = "menu";
		}
		curFather = idFather;
		for(var i=0; i < tabChildren[vIdMenu].length; i++)
		{
			if (tabChildren[vIdMenu][i] == idFather)
			{
				if ( (mIE) && (IEFilter != "") ) run_filter(getId('b'+vIdMenu+i));
				getId('b'+vIdMenu+i).style.display="";
			}
		}
		if (tabChildren[vIdMenu][idFather] == null)
		{
			if ( (getId('r'+vIdMenu+actRoot)) && (actRoot != idFather) && mCurrent) getId('r'+vIdMenu+actRoot).className = "rootmenu";
			actRoot = idFather;
		}
	}
	else
	{
		var vFather = tabChildren[vIdMenu][idFather];
		if (curFather != vFather)
		{
			for(var i=0; i < tabChildren[vIdMenu].length; i++) {if (tabChildren[vIdMenu][i] == curFather) getId('b'+vIdMenu+i).style.display="none";}
		}
		for(var i=0; i < tabChildren[vIdMenu].length; i++)
		{
			if ( (tabChildren[vIdMenu][i] == vFather) && (i != idFather) )
			{
				for(var j=0; j < tabChildren[vIdMenu].length; j++) {if (tabChildren[vIdMenu][j] == i) getId('b'+vIdMenu+j).style.display="none";}
				if (getId('m'+vIdMenu+i)) getId('m'+vIdMenu+i).className = "menu";
			}
		}
	}
}

function menuMouseOverRoot(idRoot, vIdMenu)
{
	clearTimeout(hMenu);
	for(var i=0; i < tabChildren[vIdMenu].length; i++)
	{
		if ( (tabChildren[vIdMenu][i] != idRoot) && (tabChildren[vIdMenu][idRoot] == null) && (getId('m'+vIdMenu+i)) ) getId('b'+vIdMenu+i).style.display="none";
	}
	if ( (getId('r'+vIdMenu+curRoot)) && (curRoot != idRoot)) getId('r'+vIdMenu+curRoot).className = "rootmenu";
	if ( (getId('r'+vIdMenu+curRoot)) && (actRoot != idRoot) && mCurrent) getId('r'+vIdMenu+curRoot).className = "rootmenu";
	if ( (curRoot == idRoot) && (idRoot == actRoot)) getId('r'+vIdMenu+curRoot).className = "rootmenuactive";
	curRoot = idRoot;
}

function menuMouseOut(vIdMenu)
{
	hMenu = setTimeout('hideMenus( ' + vIdMenu + ')', defTimeOut);
}

function hideMenus(vIdMenu)
{
	for(var i=0; i < tabChildren[vIdMenu].length; i++)
	{
		if (getId('m'+vIdMenu+i))
		{
			getId('b'+vIdMenu+i).style.display="none";
			getId('m'+vIdMenu+i).className = "menu";
		}
	}
	if (getId('r'+vIdMenu+curRoot)) getId('r'+vIdMenu+curRoot).className = "rootmenu";
	if (mCurrent && getId('r'+vIdMenu+actRoot)) getId('r'+vIdMenu+actRoot).className = "rootmenuactive";
	curRoot = null;
}

function run_filter(obj)
{
	if(obj && obj.filters[0])
	{
		obj.filters[0].apply();
		obj.visibility="visible";
		obj.filters[0].play();
	}
}