// base folder path
var strImagesPath = "/"

//Primary menus and links
/*var menusL0 = new Array("Item1_1","Item1_2","Item1_3");
var menusLinks0 = new Array("Item1_1.asp","","");
var menusL1 = new Array("Item2_1","Item2_2","Item2_3");
var menusLinks1 = new Array("Item2_1.asp","Item2_2.asp","Item2_3");
*/
//secondary menus
/*var oSecMenus = new Object();
oSecMenus.menusL0_1 = new Array("SubItem1_1","SubItem1_2","SubItem1_3");
menusLinks0_1 = new Array("SubItem1_1.asp","SubItem1_2.asp","SubItem1_3.asp");
oSecMenus.menusL0_2 = new Array("Aerospace/Aviation","Agribusiness","Energy","IT/E-Commerce","Legal","WTO");
menusLinks0_2 = new Array("index.asp?fuseaction=ComAerospace","index.asp?fuseaction=ComAgribusiness","index.asp?fuseaction=ComEnergy","index.asp?fuseaction=ComIT","index.asp?fuseaction=ComLegal","index.asp?fuseaction=ComWTO");
oSecMenus.menusL0_5 = new Array("Employment","DC office");
menusLinks0_5 = new Array("Employment.asp","DC.asp");
oSecMenus.menusL1_10 = new Array("Currency Control","Leasing","Insurance","Pension Reform","Securities Reform");
menusLinks1_10 = new Array("index.asp?fuseaction=F_Currency","index.asp?fuseaction=F_Leasing","index.asp?fuseaction=F_Insurance","index.asp?fuseaction=F_Pension","index.asp?fuseaction=F_Securities");
oSecMenus.menusL1_20 = new Array("Consulting","Executive Search","PR","Real Estate","Strategic Communications","Travel/Tourism");
menusLinks1_20 = new Array("index.asp?fuseaction=S_Consulting","index.asp?fuseaction=S_Executive","index.asp?fuseaction=S_PR","index.asp?fuseaction=S_Real","index.asp?fuseaction=S_Strategic","index.asp?fuseaction=S_Travel");
*/
var IsMenuSetUp = false;
function MDown(elemName)
{	
	switch(elemName)
	{
		case 'level1_1' :
					top.location.href = strImagesPath + "m_whoweare.asp";	
					break;
		case 'level1_2' :
					top.location.href = strImagesPath + "m_industrysectors.asp";	
					break;				
	}	
}

var menusL2AllowSplit = true;
var menusL3AllowSplit = true;

var menuWidth = 120;
var submenuWidth = 120;

var bIsNN = navigator.userAgent.indexOf('Netscape')>-1;
var bIsOpera = navigator.userAgent.indexOf('Opera')>-1;
var bIsMac = navigator.userAgent.indexOf('Mac')>-1;
var bIsIE = (document.all)?!bIsOpera:false;

var	OperaBefore6
if (bIsOpera)
	OperaBefore6=parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("Opera")+6,navigator.userAgent.indexOf("Opera")+7))<6;
else
	OperaBefore6=false;

var	OperaBefore7
if (bIsOpera)
	OperaBefore7=parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("Opera")+6,navigator.userAgent.indexOf("Opera")+7))<7;
else
	OperaBefore7=false;


var	MacBefore5
if (bIsMac)
	MacBefore5 = parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5,navigator.userAgent.indexOf("MSIE")+6))<5;
else
	MacBefore5 = false

	
var menuShift=bIsNN?1:bIsOpera?6:1;

var lastDisplayed = ""
var lastDisplayed2 = ""
var lastDisplayedX = 0
var lastDisplayedY = 0
var lastSplit = false
function Show(elemName)
{
	if (!IsMenuSetUp)
		return
	// hide previous menus and their submenus
	if (lastDisplayed!=elemName)
	{
		if (lastDisplayed)
			FHide(lastDisplayed);
		lastDisplayed = ""
		if (lastDisplayed2)
		{
			FHide(lastDisplayed2)
			lastDisplayed2 = ""
		}
	}
	else
		if (TimerID!=0)
		{
			lastHide = ""
			clearTimeout(TimerID)
			TimerID = 0
		}


	// display menu "top" bar
	MM_showHideLayers('B'+elemName,'show',0,0,false);
	if (MM_findObj(elemName)!=null)
	{
		var ElemID = GetMenuID(elemName)
		var primMenus = eval("menusL" + ElemID);
		var numItems = primMenus.length
		var MenuHeight = (bIsOpera?LeftBarsPos[ElemID].primHeight+numItems+1:LeftBarsPos[ElemID].primHeight)+2
		var bSplit = false
	
		// // Calculate optimal position of menu on the screen
		// get current screen parameters
		var s=GetClientRect()
	
		// attempt to place element normally in full size
		var x = LeftBarsPos[ElemID].primLeft + LeftBarsPos[ElemID].left - ((!window.IsSecondary) && ElemID<7?menuShift:0);
		var y = LeftBarsPos[ElemID].primTop + LeftBarsPos[ElemID].top;
		
		// check if menu is scrolled out
		if (x+menuWidth+menuShift-1>s.x+s.w) x = s.x+s.w-menuWidth-menuShift+1
		if (y+MenuHeight>s.y+s.h) y = s.y+s.h-MenuHeight
		if (x<s.x) x=s.x
		if (y<s.y)
		{
			y=s.y
			
			// by previous actions, if menu does not fit on screen vertically, we fall into this code
			// if menu does not fits, split it, if possible
			if (menuWidth*2<s.w && eval("window.menusL" + ElemID + "AllowSplit?true:false"))
			{
				bSplit = true

				// attempt to place element normally in full size
				var x = LeftBarsPos[ElemID].primLeft + LeftBarsPos[ElemID].left - ((!window.IsSecondary) && ElemID<7?menuShift:0)
				var y = LeftBarsPos[ElemID].primTop + LeftBarsPos[ElemID].top

				// check if menu is scrolled out
				MenuHeight = (bIsOpera?LeftBarsPos[ElemID].primHeightS+numItems/2+1:LeftBarsPos[ElemID].primHeightS)+2

				if (x+menuWidth+menuWidth+(menuShift-1)*2-1>s.x+s.w) x = s.x+s.w-menuWidth-menuWidth-(menuShift-1)*2+1
				if (y+MenuHeight>s.y+s.h) y = s.y+s.h-MenuHeight
				if (x<s.x) x=s.x
				if (y<s.y) y=s.y
			}
		}
		
		if (bSplit)
		{
			MM_showHideLayers(elemName+'S1','show',x,y,true);
			MM_showHideLayers(elemName+'S2','show',x+menuWidth+menuShift-2,y,true);
		}
		else
			MM_showHideLayers(elemName,'show',x,y,true);
	
		lastDisplayedX = x
		lastDisplayedY = y
		lastSplit = bSplit
	}
	
	lastDisplayed = elemName
}

function Show2(elemName)
{
	if (!IsMenuSetUp)
		return
	// hide previous menus and their submenus
	if (lastDisplayed2!=elemName)
	{
		if (lastDisplayed2)
			FHide(lastDisplayed2);
		lastDisplayed2 = ""
	}
	else
		if (TimerID2!=0)
		{
			lastHide2 = ""
			clearTimeout(TimerID2)
			TimerID2 = 0
		}

	if (MM_findObj(elemName)!=null)
	{
		var aSubId = elemName.split("_")
		var ElemID = parseInt(aSubId[0].substr(6))
		var subElemID = parseInt(aSubId[1])
		var subElemPos = parseInt(aSubId[2])
		
		var primMenus = eval("menusL" + ElemID);
		var strSubId = new String("menusL" + ElemID + "_" + subElemID); // sub menu id
		var secMenus = eval( "(oSecMenus." + strSubId +")?oSecMenus." + strSubId + ":null");
		var numItems = secMenus.length
		var MenuHeight = (bIsOpera?LeftBarsPos[ElemID].secHeight[subElemPos]+numItems+1:LeftBarsPos[ElemID].secHeight[subElemPos])+2
	
		// // Calculate optimal position of menu on the screen
		// get current screen parameters
		var s=GetClientRect()

		// attempt to place element normally (relatively to main sub menu)
		var x, y
		if (!lastSplit || subElemID<primMenus.length/2)
			x = lastDisplayedX + menuWidth - 2 + (ElemID<7?menuShift:0)
		else
			x = lastDisplayedX + menuWidth + menuWidth - 2 + (ElemID<7?menuShift-1:0)*2

		if (lastSplit)
			y = LeftBarsPos[ElemID].secTopS[subElemPos] + lastDisplayedY + (bIsOpera?subElemID-(subElemID>=parseInt(primMenus.length/2)?parseInt(primMenus.length/2)+1:0):0)
		else
			y = LeftBarsPos[ElemID].secTop[subElemPos] + lastDisplayedY + (bIsOpera?subElemID:0)

		// check if menu is scrolled out, attempt to plase up or left
		if (x+submenuWidth>s.x+s.w)
		{
			if (!lastSplit || subElemID<primMenus.length/2)
				x = lastDisplayedX - submenuWidth + 1 - (ElemID<7?menuShift-1:0)
			else
				x = lastDisplayedX + menuWidth - submenuWidth
		}
		if (y+MenuHeight>s.y+s.h)
		{
			if (lastSplit)
				y = LeftBarsPos[ElemID].secTopS[subElemPos] + lastDisplayedY + (bIsOpera?subElemID-(subElemID>=parseInt(primMenus.length/2)?parseInt(primMenus.length/2)+1:0):0) - MenuHeight + (bIsOpera?19:18)
			else
				y = LeftBarsPos[ElemID].secTop[subElemPos] + lastDisplayedY + (bIsOpera?subElemID:0) - MenuHeight + (bIsOpera?19:18)
		}
		
		if (x<s.x) {x=s.x;}
		
		if (y<s.y) {y=s.y;}
		
		MM_showHideLayers(elemName,'show',x+1,y,true);
	}

	lastDisplayed2 = elemName
}


var TimerID = 0;
var lastHide = "";
var TimerID2 = 0;
var lastHide2 = "";
function Hide(elemName)
{
	if (!IsMenuSetUp)
		return
	if (TimerID!=0)
	{
		if (lastHide)
			FHide(lastHide)
		lastHide = ""
		clearTimeout(TimerID)
		TimerID = 0
	}
		
	lastHide = elemName
	TimerID = setTimeout("FHide('" + elemName + "')", 300)
}

function Hide2(elemName)
{
	if (!IsMenuSetUp)
		return
	if (TimerID2!=0)
	{
		if (lastHide2)
			FHide(lastHide2);
		lastHide2 = ""
		clearTimeout(TimerID2)
		TimerID2 = 0
	}
		
	lastHide2 = elemName
	TimerID2 = setTimeout("FHide('" + elemName + "')", 300)
	if (lastHide)
		TimerID = setTimeout("FHide('" + lastHide + "')", 300)
}

function FHide(elemName)
{
	MM_showHideLayers(elemName,'hide',-1000,-1000,true);
	MM_showHideLayers('B' + elemName,'hide',0,0,false);
	MM_showHideLayers(elemName+'S1','hide',-1000,-1000,true);
	MM_showHideLayers(elemName+'S2','hide',-1000,-1000,true);
}



function getAbsoluteLeft(oNode){
	//debugger; 
  var oCurrentNode=MM_findObj(oNode);
   var iLeft=0;
   while(oCurrentNode!=null)
   {
      iLeft+=oCurrentNode.offsetLeft;
      oCurrentNode=oCurrentNode.offsetParent;
   }   
   return(iLeft);
}

// distance from top border of browser window including all HTML elements in which map is nested
function getAbsoluteTop(oNode){
   var oCurrentNode=MM_findObj(oNode);
   var iTop=0;
   while(oCurrentNode!=null)
   {
      iTop+=oCurrentNode.offsetTop;
      oCurrentNode=oCurrentNode.offsetParent;
   }   
   return(iTop);
}

	function setupMenuLocations()
	{
		for (var i=0; i<window.LeftIDs.length; i ++)
		{
			var strId = window.LeftIDs[i];
			var oPos = new Object();
			oPos.left = 180 + getAbsoluteLeft("topmenu") + (bIsOpera?5:0);
			oPos.top = 83 + (bIsOpera?8:0);
			oPos.width = 427;
			oPos.height = 15;
			
			oPos.primLeft = i * 70 - 5;
			oPos.primTop = 3;
			oPos.primHeight = 0;
			oPos.primHeightS = 0;
			
			oPos.secTop = new Array();
			var k = 0;
			for (var j = 0; j < 20; j++)
			//try
			//{
			if ( eval("(window.menusLinks" + i + "_" + j + "?true:false)"))
			{
			oPos.secTop[k] = oPos.primTop - 3 + j * 18;
			if (bIsOpera)oPos.secTop[k] = oPos.primTop - 3 + j * 17;
			k++;
			}
			//catch(e){}
			oPos.secTopS = new Array(170,119);
			oPos.secHeight = new Array(5*17,6*17+8);
			LeftBarsPos[i] = oPos;
		}
	}


function SetupMenus()
{
	if (IsMenuSetUp)
		return

	var numSecMenus = 0; // number of secondary menus in primary menu
	var strMenus = new String();
			
	for (var i=0; i<LeftIDs.length; i++)
	{
		//Setting buttons on home page		
		strMenus += "<div name='B" + 
			LeftIDs[i] + "' id='B" + 
			LeftIDs[i] + "' style='position:absolute;left:" + 
			LeftBarsPos[i].left + ";top:" + 
			LeftBarsPos[i].top + ";visibility:hidden;z-index:10' onMouseOver=\"Show('"+ 
			LeftIDs[i] + "')\" onMouseOut=\"Hide('"+ 
			LeftIDs[i] + "')\"></div>";
		
		var primMenus = eval("menusL" + i); // primary menus linked to this button
		
		var bSplit = eval("window.menusL" + i + "AllowSplit?true:false")
		var strSplit1 = new String()
		var strSplit2 = new String()
		
		if (primMenus.length != 0)
		{
			// setting primary menus
			strMenus += "<div name='" + 
				LeftIDs[i] + "' id='" + 
				LeftIDs[i] + "' style='border:1px solid gray;background-color:#b2b2b2;position:absolute;visibility:hidden;z-index:1000;left:-1000;top:-1000;width:" + menuWidth + ";" + 
					(MacBefore5?"BORDER-RIGHT: black 1px solid;BORDER-LEFT: black 1px solid;":"") + 
					"' onMouseOver=\"Show('"+ 
				LeftIDs[i] + "')\" onMouseOut=\"Hide('"+ 
				LeftIDs[i] + "')\"><table border='0' cellspacing='0' cellpadding='0' width='" + menuWidth + "'>"
				
			if (bSplit)
			{
				strSplit1 += "<div name='" + 
					LeftIDs[i] + "S1' id='" + 
					LeftIDs[i] + "S1' style='position:absolute;visibility:hidden;z-index:1000;left:-1000;top:-1000;width:" + menuWidth + ";"
					+ (MacBefore5?"BORDER-RIGHT: black 1px solid;BORDER-LEFT: black 1px solid;":"") + 
					"' onMouseOver=\"Show('"+ 
					LeftIDs[i] + "')\" onMouseOut=\"Hide('"+ 
					LeftIDs[i] + "')\"><table border='0' cellspacing='0' cellpadding='0' width='" + menuWidth + "'>"
				strSplit2 += "<div name='" + 
					LeftIDs[i] + "S2' id='" + 
					LeftIDs[i] + "S2' style='position:absolute;visibility:hidden;z-index:1000;left:-1000;top:-1000;width:" + menuWidth + ";"
					+ (MacBefore5?"BORDER-RIGHT: black 1px solid;BORDER-LEFT: black 1px solid;":"") + 
					"' onMouseOver=\"Show('"+ 
					LeftIDs[i] + "')\" onMouseOut=\"Hide('"+ 
					LeftIDs[i] + "')\"><table border='0' cellspacing='0' cellpadding='0' width='" + menuWidth + "'>"
			}
				
			var oLinks = eval("menusLinks" + i);
			var oTexts = eval("menusL" + i);
			var strSecMenus = new String();
			var numSecMenus = 0;
		
			for (var j=0; j<primMenus.length; j++)
			{
				
				var strMenusI = new String();
				var strMenusI2 = new String();
				var strMenusIrest = new String();
				
				// checking secondary menus linked to primary menu
				var strSubId = new String("menusL" + i + "_" + j); // sub menu id
				var strLink = new String(oLinks[j]); // menu link
				var aSecMenus = eval( "(oSecMenus." + strSubId +")?oSecMenus." + strSubId + ":null");
				strSubId += "_" + numSecMenus
					
				// start menu item
				if (MacBefore5)
					strMenusI += "<tr><td class='PrimMenuCellMacIE4'";
				else
					strMenusI += "<tr><td class='PrimMenuCell'"
				
				strMenusI2 = strMenusI
				

				// last cell needs to have the bottom border
				/*if (j==primMenus.length-1)
				{
					strMenusI += " style='border-bottom:solid black 1px;height:19'";
					strMenusI2 = strMenusI
				}
				if ( (bSplit && j==parseInt(primMenus.length/2)) )
					strMenusI2 += " style='border-bottom:solid black 1px;height:19'";
				*/
				// link: for secondary menu, we display menu, otherwise - add link
				if (aSecMenus)
					//strMenusIrest += " onmouseover=\"Show2('" + strSubId + "')\" onmouseout=\"Hide2('" + strSubId + "')\"><table border='0' cellspacing='0' cellpadding='0' width='100%'><tr><td class='" + (MacBefore5?"PrimMenuImageCellMacIE4":"PrimMenuImageCell") + "' width=165>"
					strMenusIrest += " onmouseover=\"Show2('" + strSubId + "')\" onmouseout=\"Hide2('" + strSubId + "')\"" + " onclick='window.location.href=\"" + strImagesPath + strLink + "\"'>"+
								 "<a class=\"menuLink\" href='" + strLink + 
								 "'><table cellpadding='0' cellspacing='0' border='0' onmouseover=\"this.style.color = 'white'\" onmouseout=\"this.style.color = ''\" class='arrow' width='95%'><tr><td align='left' style=\"FONT-SIZE: 10px;\">" + 
								 oTexts[j] + "</td><td></td><td align='right'>&#187;</td></tr></table></a>";
				else
				{
					if (strLink.substr(0,7)=="http://") // link opened in new window
						strMenusIrest += " onclick='window.open(\"" + strLink + "\", \"_blank\")'>"
					else
						//strMenusIrest += " onclick='window.location.href=\"" + strImagesPath + strLink + "\"'>";
						strMenusIrest += " ><a class=\"menuLink\" href='" + strLink + "'>" + oTexts[j] + "</a>";
				}

				// menu item text
				/*if (MacBefore5)
					strMenusIrest += "&nbsp;" + oTexts[j]
				else
					strMenusIrest += oTexts[j];
				*/
				// finish menu item
				// for secondary menu, display submenu icon
				
				if (aSecMenus)
					strMenusIrest += "</td></tr>"
				else
					strMenusIrest += "</td></tr>";
					

				// add item to menu and splitted menu as well
				strMenus += strMenusI + strMenusIrest
				if (bSplit)
				{
					if (j>primMenus.length/2)
						strSplit2 += strMenusI2 + strMenusIrest
					else
						strSplit1 += strMenusI2 + strMenusIrest
				}
				
				// prepare submenus
				if (aSecMenus)
				{
					strSecMenus += "<div name='" + 
						strSubId + "' id='" + 
						strSubId + "' onmouseover=\"Show2('" + 
						strSubId + "');Show('" + 
						LeftIDs[i] + "');\" onmouseout=\"Hide2('" + 
						strSubId + "');Hide('" + 
						LeftIDs[i] + "');\" style='border:1px solid gray;background-color:#b2b2b2;position:absolute;left:-1000;top:-1000;width:" + submenuWidth + ";visibility:hidden;z-index:10000;" + 
						(MacBefore5?"BORDER-RIGHT: black 1px solid;BORDER-LEFT: black 1px solid;":"") + 
						"'><table border='0' cellspacing='0' cellpadding='0' width='" + submenuWidth + "'>";
					var aSecLinks = eval("menusLinks" + i + "_" + j);
					for (var k=0; k<aSecMenus.length; k++)
					{
						// start menu item
						if (MacBefore5)
							strSecMenus += "<tr><td class='SecMenuCellMacIE4'"
						else
							strSecMenus += "<tr><td class='SecMenuCell'";

						// last cell needs to have the bottom border
						//if (k==aSecMenus.length-1)
						//strSecMenus += " style='border-bottom:solid black 1px;height:19'";
						
						// add link
						var strLink = new String(aSecLinks[k]);
						if (strLink.substr(0,7)=="http://") // link opened in new window
							strSecMenus += " onclick='window.open(\"" + strLink + "\", \"_blank\")'>"
						else
							//strSecMenus += " onclick='window.location.href=\"" + strImagesPath + strLink + "\"'>";
							strSecMenus += " ><a class=\"menuLink\" href='" + strLink + "'>" + aSecMenus[k] + "</a>";
						
						// finish submenu item
						//strSecMenus += (MacBefore5?"&nbsp;":"") + aSecMenus[k] + "</td></tr>";
						strSecMenus += (MacBefore5?"&nbsp;":"") + "</td></tr>";
					}
					strSecMenus += "</table></div>";
					numSecMenus++;
				}
			}

			// finish menu block and add submenus
			strMenus += "</table></div>" + strSecMenus;
			
			// add splitted menus, if any
			if (bSplit)
				strMenus += strSplit1 + "</table></div>" + strSplit2 + "</table></div>";
		}
	}

	// applying menus to document
	document.write(strMenus)
	//alert(strMenus);	
	// prompt("",strMenus);

	IsMenuSetUp = true;
}

function MM_showHideLayers(LayerName,show,x,y,Place)
{
	var obj, v
	obj=MM_findObj(LayerName);
	if (obj)
	{ 
		v=show;
    if (obj.style)
		{
			obj=obj.style;
			v=(v=='show')?'visible':(v='hide')?'hidden':v;
		}
		if (Place)
		{
		//todo
		//try
		//{
			obj.left=x
			obj.top=y
			//}
			//catch(e)
			//{}
		}
		obj.visibility=v;
  }
}
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 GetClientRect()
{
	var x,y,w,h
	if (bIsIE)
	{
		x = document.body.scrollLeft
		y = document.body.scrollTop
		w = document.body.clientWidth - (bIsMac?20:0)
		h = document.body.clientHeight - (bIsMac?20:0)
	}
	else
	if (bIsNN)
	{
		x = window.pageXOffset
		y = window.pageYOffset
		w = window.innerWidth - 15
		h = window.innerHeight - 27
	}
	else
	if (bIsOpera)
	{
		x = window.pageXOffset
		y = window.pageYOffset
		w = window.innerWidth
		h = window.innerHeight - 15
	}
	else
	{
		x = window.scrollX
		y = window.scrollY
		w = window.innerWidth
		h = window.innerHeight
	}
	return {x:x,y:y,w:w,h:h}
}

function GetMenuID(elemName)
{
	for (var i=0; i<LeftIDs.length; i++)
	if (LeftIDs[i]==elemName)
		return i
	return 0
}

