/*
Amanda Allen, 4th Jump
*/
var MenuHover = {
	init: function() {
		var gnm = document.getElementById('greennav_menu');
		// center the whole green nav and set the class for the last item
		var last = gnm.lastChild;
		if (last.nodeName!='LI')
		{
			last = last.previousSibling;
		}
		var pad = Math.round((gnm.offsetWidth - (last.offsetLeft+last.offsetWidth)) /2);
		gnm.style.paddingLeft =pad+'px';
		last.className +=' last';

		// add the hover class to LIs when you mouse over them
		var ULs = document.getElementsByTagName("ul");
		for (var i=0;i <ULs.length ;i++ ) {
			if (ULs[i].className.indexOf('menu_top')>=0) {
				for (var j=0; j < ULs[i].childNodes.length; j++) {
					var node = ULs[i].childNodes[j];
					if (node.nodeName == "LI") {
						// the 'prev' class gets rid of the divider line in the LI to the left of the highlighted one
						if (node.className.indexOf('active') >=0 ) {
							if (node.previousSibling) {
								if (node.previousSibling.nodeName=='LI') node.previousSibling.className +=' prev';
								else if (node.previousSibling.previousSibling && node.previousSibling.previousSibling.nodeName=='LI') 
									node.previousSibling.previousSibling.className +=' prev'; 
							}
						} 
						//mouseover
						node.onmouseover= function() { 
							this.className += ' hover';
							if (this.previousSibling) {
								if (this.previousSibling.nodeName=='LI') this.previousSibling.className +=' prev';
								else if (this.previousSibling.previousSibling && this.previousSibling.previousSibling.nodeName=='LI') 
									this.previousSibling.previousSibling.className +=' prev'; 
							}
						}
						//mouseout
						node.onmouseout= function ()  { 
							this.className = '';
							//this.className = this.className.replace(' hover',''); 
							if (this.previousSibling) {
								if (this.previousSibling.nodeName=='LI') this.previousSibling.className =this.previousSibling.className.replace(' prev','');
								else if (this.previousSibling.previousSibling && this.previousSibling.previousSibling.nodeName=='LI')
									this.previousSibling.previousSibling.className = this.previousSibling.previousSibling.className.replace(' prev',''); 
							}
							
							/* 1/7/11 Fix of the alignment of the last drop down, makes sure the last li has the 'last' class -Adrian */
							var last = this.parentNode.lastChild;
							while(last.nodeType != 1)
							{
								last = last.previousSibling;
							}
							last.className = "last";	
							//**********************************************
						}
						//onclick *********************************Fix drop down not resetting*****************************
						node.onclick= function ()  { 
							this.className = this.className.replace(' hover',''); 
							if (this.previousSibling) {
								if (this.previousSibling.nodeName=='LI') this.previousSibling.className =this.previousSibling.className.replace(' prev','');
								else if (this.previousSibling.previousSibling && this.previousSibling.previousSibling.nodeName=='LI')
									this.previousSibling.previousSibling.className = this.previousSibling.previousSibling.className.replace(' prev',''); 
							}
						}
						//*************************************************************************************************/
					}
				}
			}			
		}
		var divs = document.getElementsByTagName("div");
		for (i=0; i < divs.length; i++) {
			if (divs[i].className.indexOf('dynhover')>=0) {
				divs[i].onmouseover= function() { 
					this.className += ' hover';
				}
				//mouseout
				divs[i].onmouseout= function ()  { 
					this.className = this.className.replace(' hover',''); 
				}
			}
		}
	}
}

window.onload = MenuHover.init;
