/*
////////////////////////////////////////////////
//  HCoB Javascript Menu Configuration File  //
//////////////////////////////////////////////

////  Properties
arrMenuMain:Array																		Holds the references to main menu links
arrMenuSub:Array																		Holds the references to the sub menu sections
links:Array																					Holds all of the anchor elements of the menu
strLocation:String																	The current location from the webroot


////  Methods
MenuConfigure:Void																	()
MenuSetup:Void																			()


////  Description
The script needs to run once the document has loaded, upon which the configure function needs to execute. The page needs to have a container with the id "Menucontainer", in which anchor tags are placed. Any sub menu links need to appear below the main menu item with the class name "sub". The configuration function then loops through the anchor tags contained in Menucontainer and checks the href against the current location. If the location matches, the sub menu links of that menu (or siblings of that sub menu item) are shown by changing the class name of the main element to "active".

*/

var arrMenuMain = new Array();
var arrMenuSub = new Array();
var links = new Array();

if (navigator.userAgent.indexOf("MSIE") != -1)
{
	var strLocation = new String(location.protocol+"//"+location.host+location.pathname+location.search);
} else
{
	var strLocation = new String(location.pathname+location.search);
};











////  Function to run when the menu is set up and needs to be configed
function MenuConfigure (parentid)  //  Void
{
	//  Append the main to the class name of he main menu
	var mainmenu = arrMenuMain[parentid];
	
	
	//  Check if the parent id exists in the subs array
	if (mainmenu == undefined)
	{
		///  There is no offset at that address
		//  Return from the function
		return;
		
	};
	
	
	//  Set the class name of the main menu
	mainmenu.className = "main";
	
	
	//  Put the sub menu into the local variable
	var submenuarray = arrMenuSub[parentid];
	
	
	//  Loop through the menu items
	for (var inc = 0; inc < submenuarray.length; inc++)
	{
		//  Append the classname "active" to the object's current class name
		var submenu = submenuarray[inc];
				submenu.className += " active";
		
	};

};











////  Function to set up the menu
////  To run only once upon page load
function MenuSetup ()  //  Void
{
	//  Get the main menu div tag
	var themenu = document.getElementById("Menucontainer");
	
	
	//  Get all of the links in this container
	links = themenu.getElementsByTagName("a");
	
	
	//  Set a default id to pass tot eh configuration function
	var theid = -1;
	
	
	//  Loop through the links array
	for (var inc = 0; inc < links.length; inc++)
	{
		//  Put the link into a local var
		var link = links[inc];
		
		
		//  Save the information on the current entry
		var linkClass = link.className;
		var linkLocale = link.getAttribute("href");
		
		
		//  Switch the clas name
		switch (linkClass)
		{
		
		
			case "sub":
			//  Set a sub menu container var locally
			var submenu = arrMenuSub[arrMenuSub.length - 1];
			
			//  Check if there is an array to push to
			if (submenu == undefined || submenu.length == undefined)
			{
				//  Do nothing
				
			} else
			{
				//  Add the element to the last available submenu array
				submenu.push(link);
			
			};
			break;
			
			
			
			
			default:
			//  Set the current id for use in the config function
			var currentid = arrMenuMain.length;
			
			
			//  Include the link in the main menu array
			arrMenuMain.push(link);
			
			
			//  Create an array for the sub menus
			var subs = new Array();
			arrMenuSub.push(subs);
			break;
		
		
		};
		
		
		//  Cheeck if the location of the link matches the current location
		if (strLocation == linkLocale)
		{
			//  Save the current id as THE id
			theid = currentid;
			
		};
		
	};
	
	
	//  Call the configuration function
	MenuConfigure(theid);
	
};