var currentElement = false;		// contains the object the mouse is over
var timer;						// must be declared. holds timer obj		
var timecount = 500;			// how long sub menus should stay up

function startList() 
{
	// start at root
	navRoot = document.getElementById("nava");

	//get the li tags from root
	lis = navRoot.childNodes;

	// loop thru li tags
	for (i=0; i< lis.length; i++) 
	{
		if (lis[i].nodeName=="LI")
		{
			// get li
			li = lis[i];

			// is there a sub-munu in this li?
			if(li.getElementsByTagName("UL").length > 0)
			{
				li.onmouseover=function() 
				{
					
					//we no longer want to wait...we'll do it manually below
					clearTimeout(timer);

					//if another list is open, close it with no delay
					if(currentElement)
					{
						openList = currentElement.getElementsByTagName("UL")[0];
						openList.style.display = "none";
					}

					//get new sub-menu
					subMenu = this.getElementsByTagName("UL")[0];
					//show new sub-menu
					subMenu.style.display = "block";	
					//store li the mouse that holds sub-menu
					currentElement = this;
				}

				//close sub-menu with a delay
				li.onmouseout=function() 
				{
					//must store in a var cuz setTimeOut ruins the li's scope (this)
					subMenu = this.getElementsByTagName("UL")[0];
					//hide the UL after timecount (time) has passed
					timer = setTimeout('subMenu.style.display = "none"', timecount);
				}
			}
		}
	}
}

window.onload = startList;