/*=====================================================
			Written by: Ben Daley 21/06/2007
			version:	1.4
=====================================================*/


// Adds '.over' class to all li elements within the nav.
// Use the over class in place of :hover
function ieNavHooks()
{
	var navigation = document.getElementById("nav");
	
	// Loop through the menu
	for (var i=0; i<navigation.childNodes.length; i++)
	{
		// do the first level menu
		var node1 = navigation.childNodes[i];
		
		if (node1.nodeName=="LI")
		{
			// get nested UL's
			node1.childUL = node1.getElementsByTagName("UL");
			// if there are nested UL's
			if(node1.childUL.length > 0)
			{
				// get list items
				node1.items = node1.childUL[0].getElementsByTagName("LI");
				
				//alert(node1 + " has " + node1.items.length + "child list elements")
				
				for(var j=0; j<node1.items.length; j++)
				{
					var li = node1.items[j];
					
					li.onmouseover = function()
					{
						this.className += " over";
					}
					li.onmouseout = function()
					{
						this.className = this.className.replace(" over", "");
					}
				}
			}
			// Apply handlers
			node1.onmouseover=mouseOver;
			node1.onfocus=mouseOver;
			node1.onmouseout=mouseOut;
			node1.onblur=mouseOut;
		}
	}
	
	// Write tab index to navigation items
	var links = navigation.getElementsByTagName('A');
	for(var i=0; i<links.length; i++)
	{
		links[i].tabIndex = i+1;
	}
}


function mouseOver()
{
	this.className+=" rootover";
	if(this.childUL.length > 0)
	{
		this.childUL[0].style.display = "block";
		
		measureLinks(this.childUL[0]);
	}
}

function mouseOut()
{
	this.className=this.className.replace(" rootover", "");
	if(this.childUL.length > 0)
	{
		this.childUL[0].style.display = "none";
		this.childUL[0].style.width = 'auto';
	}
}


/*	
	This sets the width of the 2nd lvl UL 
	to the width of the widest nested link.
	Required for Mozilla to use no-wrap & dynamic width
*/
function measureLinks(e)
{
	var items = e.getElementsByTagName("LI");
	var n;
	var a;
	var w = 0;
	
	for(var i =0; i<items.length; i++)
	{
		n = items[i];
		a = n.getElementsByTagName('A')[0];
		if(a.offsetWidth > w)
		{
			w = a.offsetWidth;
		}
	}
	e.style.width = w + 'px';
}



