/*
# $Id$
*/

/*
# @function void highlightNavigation()
#
# Highlights the menus that correspond to the current page
*/
function highlightNavigation() {

	// Vars
	var menuContainers = document.getElementById('page-nav').getElementsByTagName('ul');

	// Determine which menu matches the current URL
	var pathname = self.location.pathname;
	var host = self.location.host;
	var hostRegEx = new RegExp("http[s]*\:\/\/"+host+"");
	for(var i=0; i<menuContainers.length; i++) {
		var menus = menuContainers[i].getElementsByTagName('li');
		for(var j=0; j<menus.length; j++) {
			var href = menus[j].getElementsByTagName('a')[0].href.toString().replace(hostRegEx, '');
			if(href==pathname) {

				// Add 'active' class to the <li> node
				menus[j].className += ' active';

				// Add 'active' class to all parent <li> nodes
				var pNode = menus[j].parentNode.parentNode;
				while(pNode.nodeName.toString().toLowerCase()=='li') {
					pNode.className += ' active';
					pNode.getElementsByTagName('ul')[0].style.display = 'block';
					pNode = pNode.parentNode.parentNode;
				}

				// Expand sub-menu, if one exists
				var submenus = menus[j].getElementsByTagName('ul');
				if(submenus.length>0) {
					submenus[0].style.display = 'block';
				}
			}
		}
	} 
}