// Bold menu items that match the URL

"use strict";

// open anonymous function
(function()
{

	// get location without hash portion, compute once
	var window_location_nohash = window.location.protocol + '//' +
				     window.location.hostname +
				     window.location.pathname;
	
	
	// onclick activation
	function disable_current_menu()
	{
		/*
		 * This is tricky because we want the item to be clickable
		 * only if it will take us to a new href, and we can't test
		 * this on page load because it can have a hash that was added
		 * 'in-page' after load by clicking on a hash link.
		 */
		if (this.href == window.location.href)
		{
			this.blur();
			return false;
		}
		else
			return true;
	}
	
	function mark_active(parentObj)
	{
		if (!parentObj)
			return;
	
		var aList = parentObj.getElementsByTagName('a');
	
		for (var a_num = 0; a_num < aList.length; a_num++)
		{
			var aObj = aList[a_num];
	
			// 'li' first child is 'a', is 'inactive', and matches window URL
			// do most restrictive check first
			if (aObj.href == window_location_nohash &&
			    aObj.className == 'inactive')
			{
				aObj.className = 'active';
	
				// Call function this way so 'this' is passed properly.
				// Closure allows the function to exist after we exit
				aObj.onclick = disable_current_menu;
				// no more matches in this 'ul'
				break;
			}
		}
	}
	
	// handle sidebar, which is a div
	var sidebarObj = document.getElementById('sidebar-menu');
	if (sidebarObj)
		mark_active(sidebarObj);
	
	// find all 'years' menus
	// There are fewer 'ul's than 'div's, so we put classes on those
	var ulList = document.getElementsByTagName('ul');
	for (var ul_num = 0; ul_num < ulList.length; ul_num++)
		if (ulList[ul_num].className == 'years-menu')
			mark_active(ulList[ul_num]);

// close anonymous function
})();

