//<!--
//Global data storage object
function GlobalMenuData()
{
	this.ActiveMenu = "";
	this.TotalMenus = 0;
	this.TotalMenuItems = 0;
	this.CountDown = 0;
	this.HideAll = false;
}

//The build menu object
//Name : The name of the menu.  This should be the same as the name of the new menu when you define it
//Container : The DIV that the menu will be displayed in
//SubMenu : If a menu item needs to show a sub menu specify the name of the container.  Should be null if not used 
//Item _x_ Text : The text for the menu item
//Item _x_ URL : The URL for the menu item
//Item _x_ SubMenu : The name of the sub menu hanging off a menu item. If not used it should be null 
function BuildMenu(Name, Container, SubMenu, Item1Text, Item1URL, Item1SubMenu, Item2Text, Item2URL, Item2SubMenu, Item3Text, Item3URL, Item3SubMenu, Item4Text, Item4URL, Item4SubMenu, Item5Text, Item5URL, Item5SubMenu, Item6Text, Item6URL, Item6SubMenu, Item7Text, Item7URL, Item7SubMenu, Item8Text, Item8URL, Item8SubMenu, Item9Text, Item9URL, Item9SubMenu, Item10Text, Item10URL, Item10SubMenu, Item11Text, Item11URL, Item11SubMenu, Item12Text, Item12URL, Item12SubMenu, Item13Text, Item13URL, Item13SubMenu, Item14Text, Item14URL, Item14SubMenu, Item15Text, Item15URL, Item15SubMenu, Item16Text, Item16URL, Item16SubMenu, Item17Text, Item17URL, Item17SubMenu, Item18Text, Item18URL, Item18SubMenu, Item19Text, Item19URL, Item19SubMenu, Item20Text, Item20URL, Item20SubMenu)
{ 
	//Store the name of this object
	this.Name = Name;
	//The parent menu
	this.Parent = "";
	//Is the menu showing
	this.Visible = false;
	//Store the name if the div we are writing this menu into
	this.Container = Container;
	//Set up x & y coord stores
	Cell_x = 0;
	Cell_y = 0;
	
	//Specify the total number of menu items
	TotalItems = PageMenu.TotalMenuItems;
	
	//IE 5.x on a Mac detection
	if((document.all) && (navigator.appVersion.toLowerCase().indexOf("5") > -1) && (navigator.userAgent.toLowerCase().indexOf("mac") != -1))
	{
		if(navigator.appVersion.toLowerCase().indexOf("5.") > -1)
			IE5Mac = true;
		else
			IE5Mac = false;
	}
	else
		IE5Mac = false;
	
	//Start the menu structure.  If we roll over the menu it becomes the active menu
	if(!document.layers)
		this.Menu = '<table cellspacing="0" cellpadding="0" border="0" onmouseover="SetObjOver(\' ' + Name + '\');" onmouseout="SetObjOut()">';
	else
		this.Menu = '<table cellspacing="0" cellpadding="0" border="0">';
	
	//IE5 on a Mac needs all the cells finished off with a carriage return
	if(IE5Mac == true)
		this.Menu +='\n';
	
	//Loop through all menu items passed to the function 
	MenuItems = 1;
	do
	{
		
		//Make sure there is an item to add to the menu
		if(eval('Item' + MenuItems + 'Text'))
		{
			//Build up each menu cell here
			
			//Start the cell 
			this.Menu += '<tr>';
			
			//If there is a sub menu hanging off this item, specify it here
			if(eval('Item' + MenuItems + 'SubMenu') != null)
			{
				//Start by adding the opening cell and link, giving it an id 
				this.Menu += '<td id="' + Name + '_item_'  + MenuItems + '" style="padding-left: 15px; padding-top: 5px; padding-bottom: 5px; padding-right: 10px; position:relative; cursor : hand;" width="160" height="21" bgcolor="#184700" onclick="GoURL(\'' + eval("Item" + MenuItems + "URL") + '\')" onmouseover="this.bgColor = \'#396D21\';PopulateMenuLayer(\'' + SubMenu + '\',' + eval("Item" + MenuItems + "SubMenu") + ',' + Cell_x + ', ' + Cell_y + ', \'' + Name + '_item_'  + MenuItems + '\', ' + Name + ');" onmouseout="this.bgColor = \'#184700\'"><a href="' + eval('Item' + MenuItems + 'URL') + '"';
				
				this.Menu += ' onmouseover="';
				
				//In NS 4.x we need extra rollover options on the link
				if(document.layers)
					this.Menu += 'SetObjOver(\' ' + Name + '\');';
					
				Cell_x = 0;
				Cell_y = 0;
								
				this.Menu += 'ParseParents();PopulateMenuLayer(\'' + SubMenu + '\',' + eval("Item" + MenuItems + "SubMenu") + ',' + Cell_x + ', ' + Cell_y + ', \'' + Name + '_item_'  + MenuItems + '\', ' + Name + ')"';
			}
			else
			{
				//Start by adding the opening cell and link, giving it an id 
				this.Menu += '<td id="' + Name + '_item_'  + MenuItems + '" style="padding-left: 15px; padding-top: 5px; padding-bottom: 5px; padding-right: 10px; position:relative; cursor : hand;" width="160" height="21" bgcolor="#184700" onclick="GoURL(\'' + eval("Item" + MenuItems + "URL") + '\')" onmouseover="this.bgColor = \'#396D21\';';
				
				//Only Parse the top level menu's if we roll onto a different item
				if(Name.substring(5, 6) != "_")
					this.Menu += 'ParseParents()';
				
				this.Menu += '" onmouseout="this.bgColor = \'#184700\'"><a href="' + eval('Item' + MenuItems + 'URL') + '"';
				
				this.Menu += ' onmouseover="';
				
				//In NS 4.x we need extra rollover options on the link
				if(document.layers)
					this.Menu += 'SetObjOver(\' ' + Name + '\');';
					
				this.Menu += 'ParseParents();"';
			}
			
			//In NS 4.x we need extra rollover options on the link
			if(document.layers)
				this.Menu += ' onmouseout="SetObjOut();"';
			
			//Add in the menu text and closing cell 
			this.Menu += ' class="rollovermenutext">' ;
			
			if(document.layers)
				this.Menu += '<ilayer id="ns4_' + Name + '_item_'  + MenuItems + '">';
			
			//If IE4.5 on a Mac put on a font tag here
			if((document.all) && (navigator.appVersion.toLowerCase().indexOf("msie 4.") > -1) && (navigator.userAgent.toLowerCase().indexOf("mac") != -1))
				this.Menu += "<font color=white face=verdana size=2>";
			
			this.Menu += eval('Item' + MenuItems + 'Text');
			
			if(document.layers)
				this.Menu += '</ilayer>';
				
			this.Menu += '</a>';
			
			this.Menu += '</td>';
			
			//IE5 on a Mac needs all the cells finished off with a carriage return
			if(IE5Mac == true)
				this.Menu +='\n';
			
			//Add a div so we can work out sub menu positions in NS4
			//if(document.layers)
				//this.Menu += '<td valign=top><layer id="ns4_' + Name + '_item_'  + MenuItems + '" style="position:relative;">ed</layer></td>';
			
			//Finish the cell 
			this.Menu += '</tr>';
			
			//IE5 on a Mac needs all the cells finished off with a carriage return
			if(IE5Mac == true)
				this.Menu +='\n';
			
			//Increment the item count
			MenuItems++;
		}
		else
		{
			//Drop out of the loop
			MenuItems = TotalItems+1;
		}
	
	}while(MenuItems <= TotalItems)
	
	//Finish the menu structure
	this.Menu += '</table>';
	
	//IE5 on a Mac needs all the cells finished off with a carriage return
	if(IE5Mac == true)
		this.Menu +='\n';
}

//Store global menu properties
function GlobalMenuDetails()
{
	this.OpenMenus = 0;
	this.PreviousOpenMenus = 0;
}

//Hide a layer
function HideLayer(Container)
{
	if(document.all)
		eval("document.all." + Container + ".style.visibility = 'hidden'");
	else if(document.getElementById)
		document.getElementById(Container).style.visibility = "hidden";
	else
		eval("document.layers." + Container + ".visibility = 'hide'");
}

//Show a layer
function ShowLayer(Container)
{
	if(document.all)
		eval("document.all." + Container + ".style.visibility = 'visible'");
	else if(document.getElementById)
		document.getElementById(Container).style.visibility = "visible";
	else
		eval("document.layers." + Container + ".visibility = 'show'");
}

//Fill a div with a menu and position it
function PopulateMenuLayer(Container, Contents, Position_x, Position_y, DivPos, Obj)
{
	MenuPos_x = Position_x;
	MenuPos_y = Position_y;
	
	if(DivPos)
	{
		//Work out the Name of the DIV of the current menu
		ParentContainer = eval(Obj.Name + ".Container");
		
		if(document.all)
		{
			MenuPos_x = eval(DivPos + ".offsetWidth") + eval(ParentContainer + '.offsetLeft');
			//If IE on a mac work out the top value a different way
			if(navigator.userAgent.toLowerCase().indexOf("mac") != -1)
			{
				//It could be Opera on a Mac, so catch that here
				if(navigator.userAgent.toLowerCase().indexOf("opera") != -1)
					MenuPos_y = (eval(DivPos + ".offsetTop") + eval(ParentContainer + '.offsetTop'));
				//Mac IE
				else
					MenuPos_y = (eval(DivPos + ".clientTop") + eval(ParentContainer + '.clientTop'))-5;
			}
			else
				MenuPos_y = (eval(DivPos + ".offsetTop") + eval(ParentContainer + '.offsetTop'));
				
			//If IE4 on a Mac add a bit onto the menu as we use a font tag rather than the style sheet
			if((document.all) && (navigator.appVersion.toLowerCase().indexOf("msie 4.") > -1) && (navigator.userAgent.toLowerCase().indexOf("mac") != -1))
				MenuPos_y += 5;

		}
		else if(document.getElementById)
		{
			MenuPos_x = document.getElementById(DivPos).offsetWidth + document.getElementById(ParentContainer).offsetLeft;
			MenuPos_y = (document.getElementById(DivPos).offsetTop + document.getElementById(ParentContainer).offsetTop);
		}
		else
		{
			//Work out the name of the current menu item ilayer
			Current_ilayer = "ns4_" + DivPos;

			//Get and store it's number
			pos = 0;
			for(x=Current_ilayer.length-1;x>1;x--)
			{
				if(Current_ilayer.substring(x, x+1) == "_")
				{
					pos = x;
					x = 0;
				}
			}
			
			Layer_Number = Current_ilayer.substring(pos+1, pos+2);
			Layer_Start = Current_ilayer.substring(0, pos);
			Total = 0;
			
			//If the current cell is not the first in the menu, add up the heights of all previous cells in the menu, working backwards
			
			Layer_Number--;
			
			if(Layer_Number > 1)
			{
				for(x=Layer_Number;x>0;x--)
				{
					Total += eval("document.layers." + ParentContainer + ".document." + Layer_Start + "_" + Layer_Number + ".clip.height") + 2;
				}
			}
			
			//Add on the height of the parent container that is opening the new menu
			Total += eval("document.layers." + ParentContainer + ".top");
			
			//Apply the height to the sub menu's DIV
			MenuPos_y = Total;
			//Set the left position of the containing DIV
			MenuPos_x = eval("document.layers." + ParentContainer + ".clip.width") + eval("document.layers." + ParentContainer + ".left");
		}
	}
	
	//Move the menus down in IE4 on a PC as the page bumps down a bit on load
	if((document.all) && (navigator.appVersion.toLowerCase().indexOf("msie 4.") > -1) && (navigator.userAgent.toLowerCase().indexOf("mac") == -1))
		MenuPos_y += 19;
	
	//Position the menu
	if(document.all)
	{
		eval('document.all.' + Container + '.style.left = MenuPos_x');
		eval('document.all.' + Container + '.style.top = MenuPos_y');
	}
	else if(document.getElementById)
	{
		document.getElementById(Container).style.left = MenuPos_x;
		document.getElementById(Container).style.top = MenuPos_y;
	}
	else
	{
		eval("document.layers." + Container + ".left = MenuPos_x"); 
		eval("document.layers." + Container + ".top = MenuPos_y");
	}
	
	//Fill it with content
	if(document.all)
		eval(Container + '.innerHTML = Contents');
	else if(document.getElementById)
		document.getElementById(Container).innerHTML = Contents;
	else
	{
		eval("document.layers." + Container + ".document.open('text/html')");
		eval("document.layers." + Container + ".document.writeln(Contents)");
		eval("document.layers." + Container + ".document.close()");
	}
	
	//Show it
	ShowLayer(Container);
}

//Clear all the DIV's in the menu structure, keeping anything we specify to keep
function ClearAllMenus(ToKeep)
{
	//Split the string into an array
	ContainersToKeep = ToKeep.split(" : ");
	
	//Using our PageMenu object 'total menus' value, loop through the menu DIV's checking to see if the
	//name of any of the DIV's in the page match any one's passed to this function.  
	for(ContainerNumber=1;ContainerNumber<=PageMenu.TotalMenus;ContainerNumber++)
	{
		//Set the clear flag to 'true' initially
		DoClear = true;
		
		//Loop through all the elements in the ContainersToKeep array
		for(x in ContainersToKeep)
		{
			//If a match is found set the clear flag to false
			if(ContainersToKeep[x] == 'Container' + ContainerNumber)
				DoClear = false;
		}
			
		//If the clear flag reains true the current container in the loop is not used, so we can clear it	
		if(DoClear == true)
			HideLayer('Container' + ContainerNumber);
	}
}

//Countdown so the menu(s) stay on for a certain amout of time before disapearing
function Counter()
{
	if((PageMenu.HideAll == true) && (CountDown > 0))
	{
		CountDown--; 
		
		if (CountDown > 0)
		{
	 		id = window.setTimeout("Counter()",1000); 
		} 
		else
		{
				ClearAllMenus('');
		}
	}
}	

//Look at all the parents of the current active menu.  Keep them and clear out any old menu DIV's
function ParseParents()
{
	//Set the string to blank that stores all the DIV names we want to keep
	DivString = "";
	
	//Get the current container
	NewParent = eval(PageMenu.ActiveMenu + ".Parent");
	TheDiv = eval(PageMenu.ActiveMenu + ".Container");
	//Save the DIV name down to the string
	DivString = TheDiv;
		
	//If it isn't a top level container, get the next one
	if(NewParent.length > 0)
	{
		NewContainer = eval(NewParent + ".Container");
		//Save the DIV name down to the string, splitting them up with ' : ' 
		DivString += " : " + NewContainer;
	}
	
	//Loop through getting any other containers that may exist
	while(NewParent)
	{
		NewParent = eval(NewParent + ".Parent");
		
		if(NewParent.length > 0)
		{
			NewContainer = eval(NewParent + ".Container");
			//Save the DIV name down to the string, splitting them up with ' : ' 
			DivString += " : " + NewContainer;
		}
	}
	
	//Clear any unwanted menu's away
	ClearAllMenus(DivString);
}

//Useful function for getting X & Y div coords
function getAbsX(elt) 
{ 
	return parseInt(elt.x) ? elt.x : 
	getAbsPos(elt,"Left"); 
};

function getAbsY(elt) 
{ 
	return parseInt(elt.y) ? elt.y :
	getAbsPos(elt,"Top"); 
};
	
function getAbsPos(elt,which) 
{
	iPos = 0;
	while (elt != null) 
	{
		iPos += elt["offset" + which];
		elt = elt.offsetParent;
	}
		
	return iPos;
};

//Call this from a top level mouse over to initiate a menu
function TopLevelMouseOver(Container, Menu)
{
	//Work out the positions of the drop down menu's via the DIV's around each menu button
	if(Menu == "Menu1")
	{
		if(document.all)
		{
			Menu_x = getAbsX(aboutbutton);
			Menu_y = getAbsY(aboutbutton);
		}
		else if(document.getElementById)
		{
			Menu_x = document.getElementById("aboutbutton").offsetLeft;
			Menu_y = document.getElementById("aboutbutton").offsetTop;
		}
	}
	if(Menu == "Menu2")
	{
		if(document.all)
		{
			Menu_x = getAbsX(whybutton);
			Menu_y = getAbsY(whybutton);
		}
		else if(document.getElementById)
		{
			Menu_x = document.getElementById("whybutton").offsetLeft;
			Menu_y = document.getElementById("whybutton").offsetTop;
		}
	}
	if(Menu == "Menu3")
	{
		if(document.all)
		{
			Menu_x = getAbsX(coursesbutton);
			Menu_y = getAbsY(coursesbutton);
		}
		else if(document.getElementById)
		{
			Menu_x = document.getElementById("coursesbutton").offsetLeft;
			Menu_y = document.getElementById("coursesbutton").offsetTop;
		}
	}
	if(Menu == "Menu4")
	{
		if(document.all)
		{
			Menu_x = getAbsX(eventsbutton);
			Menu_y = getAbsY(eventsbutton);
		}
		else if(document.getElementById)
		{
			Menu_x = document.getElementById("eventsbutton").offsetLeft;
			Menu_y = document.getElementById("eventsbutton").offsetTop;
		}
	}
	if(Menu == "Menu5")
	{
		if(document.all)
		{
			Menu_x = getAbsX(researchbutton);
			Menu_y = getAbsY(researchbutton);
		}
		else if(document.getElementById)
		{
			Menu_x = document.getElementById("researchbutton").offsetLeft;
			Menu_y = document.getElementById("researchbutton").offsetTop;
		}
	}
	if(Menu == "Menu6")
	{
		if(document.all)
		{
			Menu_x = getAbsX(newsbutton);
			Menu_y = getAbsY(newsbutton);
		}
		else if(document.getElementById)
		{
			Menu_x = document.getElementById("newsbutton").offsetLeft;
			Menu_y = document.getElementById("newsbutton").offsetTop;
		}
	}
	if(Menu == "Menu7")
	{
		if(document.all)
		{
			Menu_x = getAbsX(alumnibutton);
			Menu_y = getAbsY(alumnibutton);
		}
		else if(document.getElementById)
		{
			Menu_x = document.getElementById("alumnibutton").offsetLeft;
			Menu_y = document.getElementById("alumnibutton").offsetTop;
		}
	}
	
	Menu_y+=21;
	
	//NS4 users can just click the button, no need for a popup menu
	if(!document.layers)
	{
		//Mac IE 4.5 users can just click the button, no need for a popup menu
		if((navigator.userAgent.toLowerCase().indexOf("mac") != -1) && (navigator.appVersion.toLowerCase().indexOf("msie 4.5") > -1))
		{}
		else
		{
			ClearAllMenus('');
			PopulateMenuLayer(Container, eval(Menu + ".Menu"), Menu_x, Menu_y);
			ShowLayer(Container);
			PageMenu.HideAll = false;
			PageMenu.ActiveMenu= Menu;	
		}
	}
}

//Call this on mouse out of a top level menu
function TopLevelMouseOut(CountDownValue)
{
	//NS4 users csn just click the button, no need for a popup menu
	if(!document.layers)
	{
		CountDown = CountDownValue;
		PageMenu.HideAll = true;
		Counter();	
	}
}

//Apply values to the global object on mouse over....
function SetObjOver(Name)
{
	PageMenu.HideAll = false;
	PageMenu.ActiveMenu=Name;
}

//...and mouse out
function SetObjOut()
{
	CountDown = PageMenu.CountDown;
	PageMenu.HideAll = true;
	Counter();
}

//If you click a menu cell go to the URL
function GoURL(TheURL)
{
	window.location.href = TheURL;
}

//Avoid JavaScript errors in IE on a Mac so you don't get the ugly JS error box
function handleError() {
	//Only return true and avoid the error on a mac in IE...
	if((document.all) && (navigator.userAgent.toLowerCase().indexOf("mac") != -1))
	{
		//...IE 4.x or 5.x
		if ((navigator.appVersion.toLowerCase().indexOf("5.") > -1) || (navigator.appVersion.toLowerCase().indexOf("4.") > -1))
		{
			//If a menu messes up refresh the page
			GoURL(window.location.href);
			return true;
		}
	}
}

//-->
