/**************************************************************************
 *                                                                        *
 *  JAVASCRIPT MENU HIGHLIGHTER v.1.5 (080929)                            *
 * --------------------------------------------                           *
 * ©2005 Media Division (www.MediaDivision.com)                           *
 *                                                                        *
 * Written by Marius Smarandoiu & Armand Niculescu                        *
 *                                                                        *
 * You are free to use, modify and distribute this file, but please keep  *
 * this header and credits                                                *
 *                                                                        *
 * Usage:                                                                 *
 * - the script will apply the .current class to the <a> and its parent   *
 *   <li> that is contained in the element with id="primarynav" and points*
 *   to the current URL                                                   *
 * - works in IE6, Firefox and Opera                                      *
 **************************************************************************
 * Code modified on 2011-Jan-09 by Dwayne Collins						  *
 * This code was modified to work with the multi-level menus specoific to *
 * this site. It is currently set to work with menus up to three levels   *
 * and could be modified for further sub-menus by increasing the          *
 * .parentNode IF and className statements according to the pattern.      *
 * The original code for this was found at:								  *
 * http://www.richnetapps.com/automatically_highlight_current_page_in/	  *
 **************************************************************************/
function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();               
}

function setActiveMenu(arr, crtPage)
{
	for (var i=0; i<arr.length; i++)
	{
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "DIV")
			{
				arr[i].className = "current_page_item";
				arr[i].parentNode.className = "current_page_item";
				if (arr[i].parentNode.parentNode.parentNode.tagName == "LI")
				{
					arr[i].parentNode.parentNode.parentNode.className = "current_page_parent";
				}
				if (arr[i].parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "LI")
				{
					arr[i].parentNode.parentNode.parentNode.parentNode.parentNode.className = "current_page_ancestor";
				}
			}
		}
	}
}

function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;

	if (document.getElementById("nav")!=null)
		setActiveMenu(document.getElementById("nav").getElementsByTagName("a"), extractPageName(hrefString));
}
