// JavaScript Document
function AddEventListener(element, eventType, handler, capture) {
	if (element.addEventListener)
		element.addEventListener(eventType, handler, capture);
	else if (element.attachEvent)
		element.attachEvent("on" + eventType, handler);
}
// multiple onloads
//use addLoadEvent(function name);
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function linkCurrentPage() { 
	
	if (!document.getElementsByTagName) return;  
		 topNavDiv=document.getElementById('nav') //if I want to limit it to a specific div
		 var links = topNavDiv.getElementsByTagName("a"); 
		 var thispage = location.href; 
		 var thispage=thispage.substring(thispage.lastIndexOf("\/")+1, thispage.length); 
		 
		 for (var i=0; i<links.length; i++) {  
		 	var link = links[i]; 
		 	thisHREF = link.getAttribute("href");
			thisHREF=thisHREF.substring(thisHREF.lastIndexOf("\/")+1, thisHREF.length); 
		 	if (thisHREF == thispage) { 
			 	//link.style.color='#f2be4a';
				link.style.color='#f2c5a2';
				//returns the parent of the link
				return link.parentNode; 
		 	}
	 	}
} 
function addLogoDivRO() {
	//checks the current page, finds the link with the same href, colors it, returns it's containing LI
	var currentPage=linkCurrentPage();
	//loop that checks the number of UL's above the current link
	var numOfUL=0;
	var parentLink=currentPage;
	var currentSubNav;
	if (currentPage.childNodes.length>1) {
			currentPage.childNodes[2].style.display="block";
			currentSubNav=currentPage.childNodes[2];
		}
	if (currentPage.parentNode.nodeName != 'DIV') {
		do {
			//cycles through parent nodes
			parentLink=parentLink.parentNode;
			//only affects UL nodes
			if (parentLink.nodeName=='UL') {
				numOfUL++;
				//opens the sub navigation menus
				parentLink.style.display="block";
				//colors the links if the parent isn't the div that contains the nav
				if (parentLink.parentNode.nodeName!='DIV') {
					//parentLink.parentNode.firstChild.style.color='#f2be4a';
					parentLink.parentNode.firstChild.style.color='#f2c5a2';
				}
			}
			if (parentLink.parentNode.parentNode.parentNode.nodeName=='DIV') {
				currentSubNav=parentLink;
			}
		} while (parentLink.nodeName!='DIV');
	} else {
		
	}
	
	//searches the nav menu for UL's
	var navMenu=document.getElementById('nav');
	for (i=0; i<navMenu.childNodes.length; i++) {
		//looks for UL"s in the navigation DIV
		currNode=navMenu.childNodes[i];
		if (currNode.nodeName=="UL") {
			//mouseout Events
			/*
			currNode.onmouseout = function(){
				if (this.childNodes.length>1) {
					if (this.childNodes[2].id==currentSubNav.id) {
						this.firstChild.style.color='#f2be4a';
					}
					currentSubNav.style.display="block";
				}
				//if no subMenu and currentMenu return to orange on rollout
				if (this==currentPage) {
					this.firstChild.style.color='#f2be4a';
				}
			};
			*/
			currNode.onmouseover = function(){
				this.firstChild.style.color='#FFFFFF';
				/*if (this.childNodes[2].id!=currentSubNav.id) {
					currentSubNav.style.display="none";
				}*/
			};
			
			
		}
	}
};
addLoadEvent(addLogoDivRO);
