/*******************************************
 A few global variables & objects
*******************************************/

//flag to tell menu JS not to hide window - because we're over a menu item
var KeepMenuUp = false;

// "Constants"
var MENU_DELAY_MS = 100;
var MENU_HEIGHT_PER_ITEM = 21.5;
var MENU_Y_OFFSET = 5;

//global menus container
var Menus = new Object();


/*******************************************
 TC 26/3/05
 new menu system - allows variable menu items and multiple menus
 both menus are drawn dynamically in renderMenu, based on MainMenu and ContactMenu arrays
 these are MD arrays, of text/href pairs
*******************************************/
Menus['ProjectsMenu'] = new Array();

Menus['ProjectsMenu'].push(Array("Masterplanning","wembleymasterplan.htm"));
Menus['ProjectsMenu'].push(Array("Mixed Use","wembley.htm"));
Menus['ProjectsMenu'].push(Array("Retail","martlets.htm"));
Menus['ProjectsMenu'].push(Array("Commercial","riverplate.htm"));
Menus['ProjectsMenu'].push(Array("Residential","queenswharf.htm"));
Menus['ProjectsMenu'].push(Array("Hotel &amp; Leisure","bathspa.htm"));
Menus['ProjectsMenu'].push(Array("Community","aylesbury.htm"));
Menus['ProjectsMenu'].push(Array("Industrial","cherwell40.htm"));




/*******************************************
 Functions to draw/show/hide menus follow
*******************************************/

function renderMenus(bFromProjects)
{
	if(bFromProjects == true)
	{
		//write paths relative to projects subfolder
		drawMenu(Menus['ProjectsMenu'],'ProjectsMenu','');
		
		
		renderPageLayout(); //don't wait for project images to finish loading
	}
	else
	{
		//write paths relative to root folder
		drawMenu(Menus['ProjectsMenu'],'ProjectsMenu','projects/');
		
	}
}

function drawMenu(MenuArray,MenuName,ExtraPath)
{
	var HREF = 1;
	var TEXT = 0;
	
	document.write('<DIV id=' + MenuName + ' style="position:absolute;top=0;left=0;z-order:100;visibility:hidden;"'
		+ ' onmouseover="KeepMenuUp=true;" onmouseout="hideMenu(\'' + MenuName + '\');"'
		+ '>')
		
	for(var i = 0;i < MenuArray.length; i++)
	{
		if(i+1 == MenuArray.length)
		{
			document.write('<div class="LastPopupMenuItem">');
		}
		else
		{
			document.write('<div class="PopupMenuItem">');
		}
		document.write('<a href="'+ ExtraPath + MenuArray[i][HREF] + '" class=smallLink>' + MenuArray[i][TEXT] +'</a></div>');
	}
	document.write('</div>');
}

function showMenu(MenuID)
{
	var MENU_X_OFFSET = 0 - (Menus[MenuID].length * MENU_HEIGHT_PER_ITEM)
	if(IsIE() == true)
	{
		//correcting for useless IE CSS handling
		MENU_X_OFFSET += 10;
	}
	
	KeepMenuUp=true;
	
	var MenuRoot = document.getElementById(MenuID + '_Root');
	var Menu = document.getElementById(MenuID);
		
	if(Menu.style.visibility == 'hidden')
	{	
		Menu.style.top = getAbsTop(MenuRoot)+MENU_X_OFFSET;
		Menu.style.left = getAbsLeft(MenuRoot)+MENU_Y_OFFSET;
		Menu.style.visibility = 'visible';	
	}
}


function hideMenu(MenuID)
{
	// called when mouse leaves an element that created or supports menu
	// actually leaves MENU_DELAY_MS before closing in case mouse enters 
	// another element that actually keeps the menu alive, and resets KeepMenuUp 
	// which is checked again in reallyHideMenu
	
	KeepMenuUp=false;
	setTimeout('reallyHideMenu("' + MenuID + '")',MENU_DELAY_MS);
}

function reallyHideMenu(MenuID)
{
	//actually hide the menu, if KeepMenuUp flag hasn't been reset
	
	if(!KeepMenuUp)
	{
		document.getElementById(MenuID).style.visibility = 'hidden';	
	}
}