//<![CDATA[

// Function to add a get elements by class command to the DOM
var menuids=["menuHz"]


function buildsubmenus_horizontal(){
for (var i=0; i < menuids.length; i++){
  // Get all nav menu list tags
  
  if (document.getElementById("index"))
  	var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
  
  // Check for subnav and call function if it exists
  if(document.getElementById("rightwing") != null){
	var subNavTags = document.getElementById("rightwing").getElementsByTagName("td");
  	subNavHeader(subNavTags);
  }
  // Loop thru the list and dynamically generate styles for the elements 
  if (document.getElementById("menuCont") ){
	  for (var t=0; t < ultags.length; t++){
			// Top level menu styles
			if (ultags[t].parentNode.parentNode.id==menuids[i]){
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px";
			ultags[t].parentNode.getElementsByTagName("a")[0].className="first";
			ultags[t].parentNode.getElementsByTagName("a")[0].style.color="white";
			ultags[t].firstChild.getElementsByTagName("a")[0].style.border="none";
			//ultags[t].parentNode.getElementsByTagName("a")[0].style.textDecoration="none";
			/* Move first menu item 1 pixel to the right to counter mac firefox bug if (Mac.test(os) && !Safari.test(browser))
				{
			ultags[t].firstChild.style.left="-1px";
				}*/
			//ultags[t].lastChild.getElementsByTagName("a")[0].style.paddingBottom="10px";
			if (t+1 == ultags.length){
				//if (Safari.test(browser) )
					//{
					storetags = ultags[t].getElementsByTagName("a");
					for (var s=0; s < storetags.length; s++) {
						storetags[s].style.width="120px";
						}
					}
				//}
			// Add the left border for all but the first top level nav items  
			}
			else{
				
				// Move the child nodes to the left by the width of their parent to avoid overlapping 
				ultags[t].style.left=ultags[t].parentNode.getElementsByTagName("a")[0].offsetWidth+"px";
				//Set left alignment of second level items to exact column width of first level items
				//to compensate for the lack of support for offsetWidth property in older versions of Safari
				//(Firefox's web developer extension was used to get width)
				/*if(Safari.test(browser) ){
					ultags[t].style.left="174px"
				}*/
				//ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px"
				ultags[t].parentNode.getElementsByTagName("a")[0].className="second";
			}
			
			// Set background styles for the top level menu items when their submenus are hovered over
			// It's set here since the corresponding CSS doesn't work on IE
			ultags[t].onmouseover=function(){
				this.parentNode.getElementsByTagName("a")[0].style.background="#212121";
				//this.parentNode.getElementsByTagName("a")[0].style.borderLeft="0.1px solid #666";
				//this.parentNode.getElementsByTagName("a")[0].style.borderRight="0.1px solid #666";
			}
			
			ultags[t].onmouseout=function(){
				this.parentNode.getElementsByTagName("a")[0].style.background="none";
				//this.parentNode.getElementsByTagName("a")[0].style.border="none";
			}
			
			// Dynamically show and hide the submenus 
			ultags[t].parentNode.onmouseover=function(){
			//this.className = "selectItem";
			this.getElementsByTagName("ul")[0].style.visibility="visible";
			}
			ultags[t].parentNode.onmouseout=function(){
			//this.className = "noselectItem";	
			this.getElementsByTagName("ul")[0].style.visibility="hidden";
			}
		}
  	}
  }
  // Add hover style properties for the top level menu items when they are hovered over 
  var litags=document.getElementsByTagName("li");
  
  if (document.getElementById("menuCont")){
  	var atags=document.getElementById("menuCont").getElementsByTagName("a");
    
	  for (var j=0; j < atags.length; j++) {
			var top = 1;
			var bt = 1; 	  
			var firstItem = atags[j].parentNode.parentNode.firstChild;
			var lastItem = atags[j].parentNode.parentNode.lastChild;
			
			// Add top and bottom images dynamically to cap second level menu items only 
			/*if (atags[j].parentNode == firstItem && atags[j].parentNode.parentNode.parentNode.parentNode.parentNode.nodeName != "LI" && top == 1) 
				{
				var listheader = document.createElement("li");
				listheader.style.backgroundImage= "url(images/menunav_top.jpg)";
				listheader.style.height= "5px";
	
				//Zero out all elements that inadvertently expand width or height of the list element in IE
				listheader.style.fontSize= "0px";
				listheader.style.lineHeight= "0px";
				listheader.style.padding= "0px";
				listheader.style.margin= "0px";
				listheader.style.width= "100%";
				if(atags[j].className != "first")
					{
					atags[j].parentNode.parentNode.insertBefore(listheader, firstItem);
					top=0;
					}
				}
				
	*/
			if (atags[j].parentNode == lastItem && atags[j].parentNode.parentNode.parentNode.parentNode.parentNode.nodeName != "LI" && bt == 0)
				{
				var	listfooter = document.createElement("li");
				listfooter.style.backgroundImage= "url(images/item.jpg)";
				listfooter.style.height= "0px";
				listfooter.style.lineHeight= "0px";
				listfooter.style.fontSize= "0px";
				listfooter.style.padding= "0px";
				listfooter.style.width= "100%";
				if(atags[j].className != "first")
					{
					atags[j].parentNode.parentNode.appendChild(listfooter);
					bt=0;
					}
				}
				
	/*	// Change line height for menu items that wrap
		if (atags[j].firstChild.nodeValue.length > 31)
		
			{
			//alert(atags[j].firstChild.nodeValue)
			atags[j].style.lineHeight= 1;
			atags[j].style.paddingTop= 5;
			atags[j].style.paddingBottom= 5;
			}
	*/		
		if (atags[j].className.match("first")) {
			/*if (Safari.test(browser) ){
				atags[j].style.fontSize = "9px";
				atags[j].style.fontWeight = "normal";
			}*/
			
			atags[j].onmouseover=function(){
				mouseAction(this,"","#212121");
				//this.style.background="#3f4447";
				//this.parentNode.getElementsByTagName("a")[0].style.borderLeft="0.1px solid #666";
				//this.parentNode.getElementsByTagName("a")[0].style.borderRight="0.1px solid #666";
				}
			atags[j].onmouseout=function(){
				this.style.background="none";
				this.style.border="none";
				}
			}
		// Add styles for second level menus to retain when their children are hovered over
		if (atags[j].className.match("second")) {
			atags[j].style.backgroundImage="url(" + img.src + ")";
			// Adjust bottom margin of second level menu headers for only IE
			if (window.ActiveXObject)
				{atags[j].style.marginBottom="-10px";}
			//atags[j].style.backgroundPosition="179px 0px";
			
			atags[j].nextSibling.onmouseover=function(){
				mouseAction(this.previousSibling,"none");
				}
			atags[j].nextSibling.onmouseout=function(){
				mouseAction(this.previousSibling,img.src);
				}
			atags[j].onmouseover=function(){
				mouseAction(this,"none");
				}
			atags[j].onmouseout=function(){
				mouseAction(this,img.src);	
				}
			}
			
		// Check the parent elements of the 'a' tags that don't have a class association, and if it is five levels deep inside a list element
		// it must be a third level subnav menu item.  For those tags, use a color instead of an image as the background
		if (atags[j].className == "") {
			if(atags[j].parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI"){
					//atags[j].parentNode.parentNode.firstChild.getElementsByTagName("a")[0].style.paddingTop="10px";
					//atags[j].parentNode.parentNode.lastChild.getElementsByTagName("a")[0].style.paddingBottom="10px";
					atags[j].onmouseover=function(){
						mouseAction(this,"","#17181C");
						}
					}
			if(atags[j].parentNode.parentNode.parentNode.parentNode.id == "menuHz"){
				atags[j].style.backgroundImage="url(" + img.src + ")";
				//atags[j].style.backgroundPosition="179px 0px";
				
				atags[j].onmouseover=function(){
					mouseAction(this,"none");
					}
				atags[j].onmouseout=function(){
					mouseAction(this,img.src);
					}
				}
		}		
	  }
  
  	//alert(!window.opera);
	//alert(!Safari.test(browser));
	// Resize the nav for IE and Firefox only
  	resizeNav();
  }
}

function mouseAction(thisObj,image,color) {
	if (color) thisObj.style.backgroundColor=color;
	if (image == "none") {
		thisObj.style.backgroundImage = "none";
	}
	else if (image != "") {
		thisObj.style.backgroundImage="url(" + image + ")";
	}
}

 function subNavHeader(subNavTags){
	for (var i = 0; i < subNavTags.length; i++) {
		if (subNavTags[i].className.match("subnav") ) {
			subNavTags[i].getElementsByTagName("a")[0].className = "subnav subnav_top";
			break;
		}
	}
}	


function resizeNav() {
	var menu = document.getElementById('menuCont');
	var aTags = menu.getElementsByTagName("a");
	var totalWidth = 0;
	var margin = 0;
	var i = 0;
	for (i = 0; i < aTags.length; i++) {
		if (aTags[i].className == "first") {
			totalWidth = totalWidth + aTags[i].parentNode.offsetWidth;
		}
	}
	menu.style.width = totalWidth;
	
	if(!window.opera && !Safari.test(browser) ){
		margin = Math.floor((491 - totalWidth)/2);
		menu.style.marginLeft = 25;
		menu.style.marginRight= 25;
	}
	
	menu.style.visibility = "visible";
}

if (window.addEventListener ){
window.addEventListener("load", buildsubmenus_horizontal, false);
}

else if (window.attachEvent ){
window.attachEvent("onload", buildsubmenus_horizontal);
}
/*function change(imageName){
	if(document.images){ document["thumb"].src = eval(imageName + ".src"); }
	}
function changeBack(){
	if(document.images){ document["thumb"].src = main.src; }
	}
*/
//]]>