// Navigation JavaScript
// BY: Cameron McGregor
// CREATED: ???
// LAST UPDATE: MAR-13-2008
// ABSTRACT: Contains javascript functions used to highlight navigation items

function findNav(strURL,nLevel)
{
	var ilNav = document.getElementById(strURL);

	//No object call function with next URL, prevent infinite recursion
	if ((!ilNav) && (nLevel < 100) && (strURL != ""))
	{
		
		//Search for last /slash
		var nSlashPos = strURL.lastIndexOf(".");
		if (nSlashPos != -1)
		{
			//Search for second last slash to move up one level
			nSlashPos = strURL.lastIndexOf(".", nSlashPos - 1);	
			
			//debugScript(strURL);
			
			if ((nSlashPos != -1) && (strURL != ".index_html"))
				ilNav = findNav(strURL.substring(0, nSlashPos + 1) + "index_html", nLevel + 1);
			else
				strURL = "";
		}
	}
	
	return ilNav;
}

function doNavContext()
{
	//Make sure the path ends with "index.html"
	var pathName = location.pathname;
	
	var nSlashPos = pathName.lastIndexOf("/");
	
	if (nSlashPos != -1)
		pathName = pathName.substring(0, nSlashPos + 1) + "index_html"

	pathName = pathName.replace(/\\/g, ".").replace(/\//g, ".");
	
	//Find the node we will take our class from
	var theNav = document.getElementById("pnav");
	if (theNav)
	{
	
		//Check for a top nav node
		var foundNav = findNav("lawofficer" + pathName, 0);
		if (foundNav)
			cssjs('add', foundNav, theNav.className);
	
		//Check for a secondary nav node
		foundNav = findNav("lawofficersnav" + pathName, 0);
		if (foundNav)
			cssjs('add', foundNav, theNav.className);
	}
}

function debugScript(outln)
{
	alert(outln);
	/*
	var out = document.getElementById("page");
	if (out)
		out.innerHTML = out.innerHTML + outln + "<br />";
	*/
}

var sfHover = function() {
	var sfEls01;
	
	if (document.getElementById("pnav")) {
		sfEls01=document.getElementById("pnav").getElementsByTagName("LI");
	}
	
	if (sfEls01) {
		for (var i=0; i<sfEls01.length; i++) {
			sfEls01[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls01[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
		}
	}

}

if (window.attachEvent) window.attachEvent("onload", sfHover);