var tmr;

window.onload = function() {
	modifyNewWindowLinks();

	var nav = document.getElementById('nav');
	
	var aTags = nav.getElementsByTagName('a');
	var liTags = nav.getElementsByTagName('li');
	
	for (var x = 0; x < aTags.length; x++) {
		aTags[x].onmouseover = showSubNav;
		aTags[x].onmouseout = hideSubNav;
		aTags[x].onfocus = showSubNav;
		aTags[x].onblur = hideSubNav;
	}
}

function showSubNav() {
	//get the parent element of the anchor with focus (or hover)	
	var pNode = this.parentNode;
	
	//Variable flag to determine whether or not the li element is in the top level of navigation.	
	var isTopLevel = true;
	
	//Check the parent element of the pNode. If the parent element's ID is 'nav' then the LI is in the top level of the navigation.
	if (pNode.parentNode.id != 'nav') {
		isTopLevel = false;
	}
	else {
		isTopLevel = true;
	}
	
	if (isTopLevel) {
		hideMenus(); //Hide other menus that might be visible
		clearTimeout(tmr); //Clear any timers that might be active
		if (String(pNode.className).indexOf('selected') > -1) {
			pNode.className = 'over selected';
		}
		else {
			pNode.className = 'over';
		}
	}
	else {
		clearTimeout(tmr); //Clear any timers that might be active
		pNode.className = 'over';
	}
}

function hideSubNav() {
	tmr = setTimeout("hideMenus()", 100);
}

function hideMenus() {
	//This function will hide any submenus that are currently visible.
	var nav = document.getElementById('nav');
	
	var liTags = nav.getElementsByTagName('li');
	
	for (var x = 0; x < liTags.length; x++) {
		if (String(liTags[x].className).indexOf('over') > -1) {
			if (String(liTags[x].className).indexOf('selected') > -1) {
				liTags[x].className = 'selected';
			}
			else {
				liTags[x].className = '';
			}
		}
	}
}


function modifyNewWindowLinks() {
	//This function looks for all the links with a class of "NewWindow"
	//and will cause them to open in a new window.

	var aTags = document.getElementsByTagName("a");
	for (var x = 0; x < aTags.length; x++) {
		var currTag = aTags[x];
		if (String(currTag.className).indexOf('NewWindow') > -1) {
			currTag.onclick = function(){ window.open(this.href); return false;}
		}
	}
}

function changeEventDate(date) {
	var month = date.substring(0,2);
	var year = date.substring(2,6);
	
	window.location = "events.php?m="+month+"&y="+year;
	return false;
}

function changeNewsDate(date) {
	var month = date.substring(0,2);
	var year = date.substring(2,6);
	
	window.location = "news.php?m="+month+"&y="+year;
	return false;
}