// JavaScript Document

//Add and Call Multiple Functions on Window Load
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
	window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//Adds or Appends a Class to Element via the DOM
function addClass(element,value) {
	if (!element.className) {
		element.className = value;
	} else {
		newClassName = element.className;
		newClassName += " ";
		newClassName += value;
		element.className = newClassName;
	}
}

function highlightLocation() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	var navigation = document.getElementById("divMasthead");
	var links = navigation.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		var linktext = links[i].lastChild.nodeValue;
		var currentPageBodyId = document.body.getAttribute("id");
		if (linktext == currentPageBodyId) {
			addClass(links[i],"here");
			//Old way overwrites existing class value
			//links[i].className = "here";
		} 
	}
}
addLoadEvent(highlightLocation);
