
/**************************************************************************
 *                                                                        *
 *  JAVASCRIPT MENU HIGHLIGHTER v.1.0 (051123)                            *
 * --------------------------------------------                           *
 * ©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                                      *
 **************************************************************************/
function extractPageName(hrefString)
{
	var name;
	var arr = hrefString.split('.');
	arr = arr[arr.length-2].split('/');
	name = arr[arr.length-1].toLowerCase();	
//alert(name);
	return name;		
}

function setActiveMenu(arr, crtPage)
{
	for(var i=0; i < arr.length; i++)
		if(extractPageName(arr[i].href) == crtPage)
		{
			arr[i].className = "current";
			arr[i].parentNode.className = "current";
		}
}


function inString(findMe, searchMe)
{
//alert(findMe);
//alert(searchMe);
		var searchMeLength = searchMe.length;
		var findMeLength = findMe.length;
		var foundIt = false;
		for (var i = 0; i <=(searchMeLength - findMeLength); i++) 
		{
			foundIt = false;
			for(var a =0;a<findMeLength;a++)
			{
//alert(findMe.charAt(a));
//alert(searchMe.charAt(i+a));
				if (searchMe.charAt(i+a) == findMe.charAt(a))
					foundIt = true;
				else
				{
					foundIt = false;
					break;
				}
			}
			if(foundIt == true)
			{
				return foundIt;
			}
		}
//alert(foundIt);
		return foundIt;
}

function mysetActiveMenu(arr, title)
{
	for(var i=0; i < arr.length; i++)
	{
		if(inString(title.toLowerCase(),arr[i].href.toLowerCase()))
		{
			arr[i].className = "current";
			arr[i].parentNode.className = "current";
		}
	}
}
function mysetActiveMenuGallery(arr, crtPage)
{
		for(var i=0; i < arr.length; i++)
		if(inString(arr[i].childNodes[0].nodeValue.toLowerCase(),crtPage.toLowerCase()))
		{
			arr[i].className = "current";
			arr[i].parentNode.className = "current";
		}
}
//set menu active if the page title is part of the page name
function setNav()
{
	var title;
	title = document.title;
//alert(title);
	if(document.location.href) 
		hrefString = document.location.href;
	else
		hrefString = document.location;
//alert(document.getElementById("main_nav"));

	if (document.getElementById("main_nav")!=null){
		mysetActiveMenu(document.getElementById("main_nav").getElementsByTagName("a"), document.title);
	}
	if (document.getElementById("small_nav")!=null){
		mysetActiveMenu(document.getElementById("small_nav").getElementsByTagName("a"), document.title);
	}
	if (document.getElementById("gallery_nav")!=null){
				mysetActiveMenuGallery(document.getElementById("gallery_nav").getElementsByTagName("a"), extractPageName(hrefString));
	}
	if (document.getElementById("Journals_nav")!=null){
				mysetActiveMenuGallery(document.getElementById("Journals_nav").getElementsByTagName("a"), extractPageName(hrefString));
	}
} 
