/*
	
 	- getElementsByClassName by http://snipplr.com/users/tylerhall/
*/
var t = '';
function getElementsByClassName(classname, node)  {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className))a.push(els[i]);
	return a;
}
// Set up our object array
var myDropLink = document.getElementById("menu").getElementsByTagName("A");
var myMenuLink = getElementsByClassName("drop"); // for the links with dropdowns
var myNoDrop = getElementsByClassName("nodrop"); // for the links with dropdowns

var myDropDownUL = getElementsByClassName("dropdown"); // the actual dropdown menus - we have this so we can turn them all off quickly



// Set up the event handlers to show all menus
for(var i=0; i<myDropLink.length; i++){
	addEvent(myDropLink[i], 'mouseover', showMenu, i);
}


// Bind the event listener with ID
function addEvent(obj, evType, fn, i){ 
	if (window.addEventListener){ 
		obj.onmouseover = function(){
									showMenu(obj, i)
									obj.style.backgroundColor = '#013f6c';
								};
		obj.onmouseout = function(){
									setTime()
									obj.style.backgroundColor = '#004273';
						};
		return true; 
	} else { 
		var r = obj.attachEvent("onmouseover",function(){
															showMenu(obj, i)
															obj.style.backgroundColor = '#013f6c';
														});
		var r = obj.attachEvent("onmouseout",function(){
															setTime()
															obj.style.backgroundColor = '#004273';
														});
		return r;
	} 
}
function hideMenu(){
	clearTimeout(t);

	for(var i=0; i<myMenuLink.length; i++){
		myMenuLink[i].style.background = '';
		myMenuLink[i].style.borderBottom = '1px #fff solid';
	}
	for(var i=0; i<myDropDownUL.length;i++){
		myDropDownUL[i].style.display = "none";
	}
}
var currentMenu;
var parentMenu;
function showMenu(obj,i){
	for(var i=0; i<myNoDrop.length; i++){
		myNoDrop[i].style.background = '#0061aa';
		
	}
	document.getElementById('navon').style.background = '#004273';


	clearTimeout(t);	
	
	parentMenu = obj.parentNode.parentNode.id;
	if(parentMenu !== currentMenu){
		hideMenu();
		if(obj.parentNode){
			if(obj.parentNode.parentNode){
				obj.parentNode.parentNode.style.display = "block";
				if(obj.parentNode.parentNode.previousSibling){
					if(obj.parentNode.parentNode.previousSibling.previousSibling){
						obj.parentNode.parentNode.previousSibling.previousSibling.style.backgroundColor = '#004273';
						obj.parentNode.parentNode.previousSibling.previousSibling.style.borderBottom = '1px #002c4c solid';
					}
				}
			}
		}
	}
	
	if(obj.nextSibling){
		if(obj.nextSibling.nextSibling){
			currentMenu = obj.nextSibling.nextSibling.id;
			obj.nextSibling.nextSibling.style.left = 0;
			obj.nextSibling.nextSibling.style.display = "block";
			obj.style.backgroundColor = '#004273';
			obj.style.borderBottom = '1px #002c4c solid';
		}
	}
}
function setTime(){
	t = setTimeout('hideMenu()',2000);
}

// end