function MenuItem(LinkNode, SubmenuNode, Parent)
{
	this.anchor = LinkNode;
	this.subMenu = SubmenuNode;
	this.parent = Parent;
	this.children = new Array();
	this.addChild = function(oChild)
	{
		if(oChild != this){ this.children.push(oChild); }
	}
	this.collapse = function()
		{
			for(var i=0; i<this.children.length; i++)
			{
				this.children[i].collapse();
			}
			if(this.subMenu == null){ return false; }
			this.subMenu.style.display = "none";
			this.collapsed = true;
			return true;
		}
	this.expand = function()
		{
			if(this.subMenu == null){ return false; }
			this.subMenu.style.display = "block";
			this.collapsed = false;
			return true;
		}
	this.collapsed = false;
	if(this.anchor && this.subMenu)
	{
		this.anchor.menuItem = this;
		/*
		this.anchor.onclick = function()
			{
				var oMenuItem = this.menuItem;
				if(oMenuItem.collapsed)
				{
					oMenuItem.expand();
				}
				else
				{
					oMenuItem.collapse();
				}
				return false;
			}
		*/
	}
	this.selectItem = function()
		{
			if(this.anchor){ this.anchor.className = "selectedNav"; }
		}
	this.autoExpand = function()
	{
		if(this.anchor && this.parent)
		{
			/*
			if(self.location.href.toLowerCase() == this.anchor.href.toLowerCase())
			*/
			var sFolder = self.location.pathname.split("/")[1].toLowerCase();
			if(sFolder == this.anchor.pathname.toLowerCase().substring(0, sFolder.length))
			{
				this.parent.expand();
				this.selectItem();
				this.parent.selectItem();
			}
		}
		for(var i=0; i<this.children.length; i++)
		{
			this.children[i].autoExpand();
		}
	}
}
function createMenu(oMenuNode, oParent)
{
	// Go through child nodes and get all <li>s
	if((!oMenuNode) || (!oMenuNode.childNodes)){ return false; }
	for(var i=0; i<oMenuNode.childNodes.length; i++)
	{
		var oListItem = oMenuNode.childNodes[i];
		if(oListItem.nodeName && oListItem.nodeName.toLowerCase && (oListItem.nodeName.toLowerCase() == "li"))
		{
			// Okay, this is a menu item.
			// Go through its children and see if we can find an <a> (the main link) and an <ul> (submenu)
			var oLink = null;
			var oSubmenu = null;
			for(var e=0; e<oListItem.childNodes.length; e++)
			{
				var oMenuSection = oListItem.childNodes[e];
				switch(true)
				{
					case (oMenuSection.nodeName && oMenuSection.nodeName.toLowerCase && (oMenuSection.nodeName.toLowerCase() == "a")):
						oLink = oMenuSection;
						break;
					case (oMenuSection.nodeName && oMenuSection.nodeName.toLowerCase && (oMenuSection.nodeName.toLowerCase() == "ul")):
						oSubmenu = oMenuSection;
						break;
					default:
						// Nothing
						break;
				}
			}
			// Create a new menu item
			var oNewMenuItem = new MenuItem(oLink, oSubmenu, oParent);
			// If we have a parent, assign it this child
			if(oParent != null){ oParent.addChild(oNewMenuItem); }
			// Can we recurse?
			if((oLink != null) && (oSubmenu != null)){ createMenu(oSubmenu, oNewMenuItem); }
		}
	}
}
function createNavigation(oParent)
{
	// Sanity testing
	if(!document.getElementById){ return false; }
	if(!document.createElement){  return false; }
	// Get main navigation <div>
	var oNav = document.getElementById("nav");
	if(!oNav){ return false; }
	// Iterate through children and find <div>s with classes of navSection
	for(var i=0; i<oNav.childNodes.length; i++)
	{
		var oNavElement = oNav.childNodes[i];
		if(oNavElement.nodeName && oNavElement.nodeName.toLowerCase && (oNavElement.nodeName.toLowerCase() == "div") && oNavElement.className && oNavElement.className.toLowerCase && (oNavElement.className.toLowerCase() == "navsection"))
		{
			// This is a navigation section, find the UL inside it and pass it to createMenu().
			for(var e=0; e<oNavElement.childNodes.length; e++)
			{
				var oMenu = oNavElement.childNodes[e];
				if(oMenu.nodeName && oMenu.nodeName.toLowerCase && (oMenu.nodeName.toLowerCase() == "ul"))
				{
					// Create a menu object and put it in the array
					createMenu(oMenu, oParent);
				}
			}
		}
	}
	// Return that it worked
	return true;
}
function replaceDefaults()
{
	if(!document.getElementsByTagName){ return false; }
	var aInputs = document.getElementsByTagName("INPUT");
	for(var i=0; i<aInputs.length; i++)
	{
		if((aInputs[i].className == "emailTxt") || (aInputs[i].className == "passwordTxt") || (aInputs[i].className == "search"))
		{
			aInputs[i].initialSelected = true;
			aInputs[i].onfocus = function()
				{
					if(!this.initialSelected){ return false; }
					this.initialSelected = false;
					this.value = "";
				}
		}
	}
}
var oBaseMenu = new MenuItem(null, null, null);
createNavigation(oBaseMenu);
oBaseMenu.collapse();
oBaseMenu.autoExpand();
replaceDefaults();
