// remove link to current page in nav
// (c) 2006 eightize
// add call to this script at the end of the page
//   after all elements containing the menus
// last modified: feb 23 2006	 by: mb
//

// the id's of the elements containing the menu
var mainDiv = new Array("nav");

// the class to apply in place of current page link
var thisPg = "currpg";

// default page url if root of site is called.
//  script will also check for this link on page.
//  leave blank to ignore
// i.e. index.html
var defaultUrl = "index.html";

// the url of the current page
var RE = /^(.+)\?.*$/;
var currPg = (location.href).replace( RE , '$1');
// :KLUDGE: safari does not encode uri properly in location.href
//  only testing for spaces. Should add other characters that mac allows.
if (currPg.match(/[ ]/)) currPg = encodeURI(currPg);
// try to deal with safari file name problem for local files
currPg = currPg.replace(/file:\/([^\/])/,"file:///$1");

// go through document tree and find element with mainDiv id
for (var i=0; i<mainDiv.length; i++) {
	if (document.getElementById) var thisDiv = document.getElementById(mainDiv[i]);
    else if (document.all) var thisDiv = document.all[mainDiv[i]];
    // fail silently
    if (thisDiv)  {
		// go through this element
		setPage(thisDiv, currPg);
	}
}

// go through tree of elParnt looking for an element with 
//	href == aURL
function setPage(elParnt, aURL) {
	var nTree = elParnt.getElementsByTagName('a');
	for (var j=0; j<nTree.length; j++) {
		if (aURL == nTree[j].href || (aURL.match(/\/$/) && ((aURL+defaultUrl) == nTree[j].href))) {
			// this page is referenced, so change it
			clearLink(nTree[j]);
		}
	}
}

// change the current page reference
function clearLink(pNode) {
	// copy all child nodes of pNode before pNode
	var ocNod = pNode.parentNode;
	var tempNod = document.createElement('SPAN');
	// apply thisPg class to it
	tempNod.className = thisPg;
	// replace the url and its contents
	ocNod.replaceChild(tempNod,pNode);
	tempNod.innerHTML=pNode.innerHTML;
}

// add encodeURI to old javascript implementations *KLUDGE*
if (typeof(encodeURI)=='undefined') {
	function encodeURI(tx) {
		return escape(tx);
	}
}

