/*
	objTopNavigation
*/
var objTopNavigation = new MainNavigation();

// add handler to onload event
window.onload = objTopNavigation.InitTopNav;

function MainNavigation(){

	var thisObject = this;
	
	this.InitTopNav = function(){
		if(!document.getElementById) return;
		
		// Fix nav top drop downs
		var root = document.getElementById("mainNavigation");
		if(root)
		{ 
			// In each drop down, make each a element equally wide
			thisObject.SetSubNavWidths(root, 78, null)
			
			// Because IE lacks support for the hover pseudo element we simulate it with javascript
			if(document.all)
			{
				for (var i=0; i<root.childNodes.length; i++) 
				{
					var node = root.childNodes[i];
				}
				
				var lists = root.childNodes;
				for (var j = 0; j < lists.length; j++)
				{
					var listItems = lists[j].childNodes;
					for (var k = 0; k < listItems.length; k++)
					{
						var item = listItems[k];
						if (item.nodeName=="LI") 
					    {
						    objGlobal.IEAttachMouseEvents(item, "ie-hover", null, item.className, null, true);
					    }
					}
				}	
					
			}
		}
	}

	this.SetSubNavWidths = function(root, minWidth, maxWidth) {

		// get collection of subnav div containers
		var subListColl = root.getElementsByTagName("div");
		
		// operate on all subnavs found
		for(var i=0; i<subListColl.length; i++)
		{
			// get collection of a elements
			var aColl = subListColl[i].getElementsByTagName("a");
			
			// get the width of the widest a element
			var newWidth = 0;
			for(var j=0; j<aColl.length; j++)
			{
				newWidth = Math.max(aColl[j].offsetWidth, newWidth);
			}
			if(minWidth)
				newWidth = Math.max(newWidth, minWidth);
			if(maxWidth)
				newWidth = Math.min(newWidth, maxWidth);
			
			// set width on all a elements to the widest retrieved
			for(var j=0; j<aColl.length; j++)
			{
				var aEl = aColl[j];	
				
				// hard-coded value, cannot retrieve computed style values in safari
				var hPad = 10;
		
				// set hPad to 0 for IE versions using Microsoft's faulty box model
				if(objGlobal.Agent.indexOf("windows") != -1 && objGlobal.Agent.indexOf("msie") != -1 && objGlobal.Agent.indexOf("opera") == -1)
				{
					var hPad = parseInt(aEl.currentStyle.paddingLeft)+ parseInt(aEl.currentStyle.paddingRight);
					// Using IE's non-standard box model
					if(!document.compatMode || document.compatMode == "BackCompat")
					{
						hPad = 0;
					}
				}
				aEl.style.width = (newWidth - hPad) + "px";
			}
		}
	}
}

