
/*
 * Setup the menu
 */

var indexPageName = "index";

function SetupMenu()
{
	var imgArray = new Array();
	var menuOption = new Array();
	var currentPage = FindCurrentPage();
	imgArray = document.getElementsByTagName("img");
	
	for(var i=0; i < imgArray.length; i++)
	{
		var idString = imgArray[i].id
		idString = idString.toLowerCase();
		if(idString.match("option") != null)
		{
			menuOption.push(idString);
			var idString = idString.replace("option_", "");
			if(idString != currentPage)
			{
				imgArray[i].onmouseover = MenuOptionRollOver; // assign the mouseover action
				imgArray[i].onmouseout = MenuOptionRollOut; // assign the mouseover action
			}
			else
				AssignCurrentPageMenuOption(imgArray[i]);
		}
	}
}

function AssignCurrentPageMenuOption(obj)
{
	var oldSrc = obj.src;
	var newSrc = oldSrc.replace(/_off/, "_on");
	obj.src = newSrc;
}

/*
 * Returns the current page name from the user's current location.
 */
function FindCurrentPage()
{
	var urlString = window.location.toString(); // get the url
	var urlArray = new Array();
	urlArray = urlString.split("/"); // split the url
	var currentPage = urlArray[(urlArray.length-1)]; // get the entire page name + extension
	var extension = currentPage.substr(currentPage.length-4); // get the extension of the page.
	var currentPageName = currentPage.replace(extension, ""); // remove the extension
	
	currentPageName = currentPageName.replace(/_cs/, ""); // replace the case study extension.
	
	if(currentPageName == indexPageName || currentPageName == "")
		currentPageName = "home";

	return currentPageName.toLowerCase(); // return the page name
}

function MenuOptionRollOver()
{
	var oldSrc = this.src;
	var newSrc = oldSrc.replace(/_off/, "_on");
	this.src = newSrc;
}

function MenuOptionRollOut()
{
	var oldSrc = this.src;
	var newSrc = oldSrc.replace(/_on/, "_off");
	this.src = newSrc;
}


