addEventSimple(window,'load',setCurrentNavItem);


/**
 * addEventSimple
 * 
 * @param {object} obj - the object the event is added to
 * @param {string} event - the event name (without 'on') 
 * @param {string} fn - the function to be executed
 *
 * Adds an Event Handler to a function
 *
 * more info: http://developer.mozilla.org/en/docs/DOM:element.addEventListener - under "Internet Explorer"
 *    
 */
function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}



/**
 * setCurrentNavItem
 *
 * Check for W3C DOM and add 'class="on"' to the current nav item
 *
 */
function setCurrentNavItem() {
	var W3CDOM = document.getElementsByTagName && document.createElement;
	if(!W3CDOM) return; //checks if the W3C DOM is supported

	var topNavHrefs = document.getElementById('topnav').getElementsByTagName('a');
	var curPathPos = getCurPathPos(topNavHrefs); //the current position of link that will be highlighted
	if (curPathPos != null) {
		(null) ? '' : topNavHrefs[curPathPos].parentNode.className = 'on';
	}
}



/**
 * getCurPathPos
 *
 * @param {array} topNavHrefs - list of all the anchor (<a>) elements in 'topnav'
 * @return - the current position number in the array
 * 
 * Get the current position of the link in 'topnav' that will be highlighted and return that number
 *
 */
function getCurPathPos(topNavHrefs) {
	var pathList = new Array();

	//create a list of URLs and pull out the directory name
	for(var i=0; i<topNavHrefs.length; i++) {
		pathList[i] = topNavHrefs[i].href.split('/')[3].toLowerCase();
	}

	var curPath = getCurPath();
	var curPathPos = null;

	for(var a=0; a<pathList.length; a++) {
		if(pathList[a] == curPath) {
			curPathPos = a;
			break;
		}
	}

	return curPathPos;
}



/**
 * getCurPath
 *
 * @return - the current locaction of the browser
 *
 * Get the URL of the page and return the first directory
 *
 */
function getCurPath() {
	return location.pathname.split('/')[1].toLowerCase();
}
