/**************************************************************************
 *                                                                        *
 *  JAVASCRIPT MENU HIGHLIGHTER v.1.5 (080929)                            *
 * --------------------------------------------                           *
 * ©2005 Media Division (www.MediaDivision.com)                           *
 *                                                                        *
 * Written by Marius Smarandoiu & Armand Niculescu   					  *
 * Modified by Olga Turkevich											  *
 *                                                                        *
 * 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                                      *
 **************************************************************************/
/*
ORIGINAL FUNCTION
function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();               
}
*/
/*
TO HANDLE ANCHORS
function extractPageName(hrefString)
{
	var hrefString = hrefString.split('#');
	var hrefString = hrefString[0].split('?');	
	var arr = hrefString.split('/');
	return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}
*/

/* to handle query result pages with ? after the url */
function extractPageName(hrefString){
	var arr = hrefString.split('.');	
	var hasquestion=hrefString.indexOf('?'); // Check to see if the url has a query string by searching for the question mark
	if (hasquestion == '-1')
	{
		arr = arr[arr.length-2].split('/');
		//return arr[arr.length-1].toLowerCase();	//returns the actual page name minus extension
		//alert(arr);
		//return arr[arr.length-2].toLowerCase();		//returns the folder name the actual page lives in
		//return arr[2].toLowerCase();					//returns the file folder in the position of 3
		if (arr[1] != null){
			return arr[1].toLowerCase();					//returns the file folder in the position of 2
		}
		else{
			return "default";
		}	
	}
	else{
		//alert("here1");
		//return arr[arr.length-1].toLowerCase();
		var hrefString = arr[arr.length-2].split('?');	
		arr = arr[arr.length-2].split('/');
		//return arr[2].toLowerCase();					//returns the file folder in the position of 3	
		return arr[1].toLowerCase();					//returns the file folder in the position of 2
	}
}

function setActiveMenu(arr, crtPage)
{
	for (var i=0; i<arr.length; i++)
	{
		//alert("arr: " + arr[i].href);
		//alert("crtPage: " + crtPage);
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "DIV")
			{
				arr[i].className = "current";
				
				/*findImgPath*/
				var bgImg = document.getElementById(arr[i].id).getElementsByTagName('img')[0].src;
				
				var a = bgImg.split("/");
				var a_length = a.length-1;
				aa = a[a_length];
			
				var b = aa.split(".");
				var b_length = b.length;
				bb = b[0];
			
				//alert(bgImg); //full bgImg string
				//alert(a); //elements in array of bgImg string
				//alert(aa); //full image name
				//alert(bb); //image name without filetype
				bbb= ("/library/images/nav/") + bb + ("_On.gif");
				document.getElementById(arr[i].id).getElementsByTagName('img')[0].src = bbb;
				//arr[i].parentNode.className = "current";
				//arr[i].parentNode.parentNode.parentNode.className = 'current';
				
				return;	// We changed the nav graphic. Need to make sure it doesn't go into subitems in the menu.
			}
		}
	}
}

function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;
	//alert("hrefString: " + hrefString);	//get current URL

	if (document.getElementById("nav")!=null){
		setActiveMenu(document.getElementById("nav").getElementsByTagName("a"), extractPageName(hrefString));
	}
}