// JavaScript Document

//<![CDATA[

// Function to add a get elements by class command to the DOM
var menuids=["navbar"]

function buildsubmenus_horizontal(){
for (var i=0; i < menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
	
  // Loop thru the list and dynamically generate styles for the elements 
  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].parentNode.getElementsByTagName("a")[0].style.textDecoration="none";
		//ultags[t].firstChild.getElementsByTagName("a")[0].style.paddingTop="10px";
		/* 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="135px";
					}
	 			}
			//}
		// 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="#6D53EA";
			//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";
   	 	}
    }
  }
  
/*THIS IS THE AREA WE NEED TO CONCENTRATE ON!!!!!!!!!!*/
  
  // Add hover style properties for the top level menu items when they are hovered over 
  var litags=document.getElementsByTagName("li");
/*  var ultags=document.getElementsByTagName("ul");*/
  var atags=document.getElementsByTagName("a");
  
  for (var j=0; j < atags.length; j++) {
/*	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,"","#6D53EA");
			//this.style.background="#6D53EA";
			//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";
			}
		}	
		
		
/*END OF AREA*/		
		
	// 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 + ")";
		//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 == "navbar"){
			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);
				}
			}
	}		
  }
 	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 resizeNav() {
	var aTags = document.getElementById('navbar_contain').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;
		}
	}
	document.getElementById('navbar_contain').style.width = totalWidth;
	if (navigator.userAgent.toLowerCase().indexOf("safari") == "-1") {
		margin = Math.floor((658 - totalWidth)/2);
		document.getElementById('navbar_contain').style.marginLeft = margin;
		document.getElementById('navbar_contain').style.marginRight= margin;
	}
	document.getElementById('navbar_contain').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; }
	}
*/
//]]>