var strClassName = "highlighted";
var blnFound = false;
var strCurrentURL = "";
var strCurrentFile = "";
var strClosestURL = "";

function highlightItem(strElement) {

	blnFound = false;
	strCurrentURL = document.location.pathname.toLowerCase();
	strCurrentFile = "";
	strClosestURL = "";

	var objElement = document.getElementById(strElement);

	var blnExists = false;
	
	if (objElement.innerHTML.toLowerCase().indexOf(strCurrentURL) > -1) blnExists = true;

	if (blnExists == false) {

		var strFile = strCurrentURL;

		while (strFile.indexOf("/") > -1) {
			strFile = Right(strFile, strFile.length - strFile.indexOf("/") - 1);
		}
		strCurrentFile = strFile;
		strCurrentURL = strCurrentURL.replace(strFile, "");
	}

	if (objElement.childNodes != null) {
		findElement(objElement, blnExists);
	}
	
	if (blnFound == false) {
		strCurrentURL = strClosestURL;
		findElement(objElement, blnExists);
	}
}

function findElement(objParent, blnExists) {

	if (objParent.tagName == "A") {

		if (objParent.href != "") {

			var strLink = "/" + objParent.pathname.toLowerCase();

			if (strLink != "/") {

				if (blnExists == false) {

					var strFile = strLink;
					while (strFile.indexOf("/") > -1) {
						strFile = Right(strFile, strFile.length - strFile.indexOf("/") - 1);
					}
					strLink = strLink.replace(strFile, "");
				}

				if (strCurrentURL == "") {
					strCurrentURL = document.location.pathname.toLowerCase();
				}

				if (strLink.indexOf(strCurrentURL) != -1 && blnFound == false) {

					objParent.className = strClassName;

					backTrack(objParent.parentNode);

					blnFound = true;

				} else if (blnExists == false && blnFound == false) {

					if (document.location.pathname.toLowerCase().indexOf(strLink) > -1) {
						strClosestURL = strLink;
					}
					if (document.location.pathname.toLowerCase().indexOf(strLink + strCurrentFile) > -1) {
						strClosestURL = strLink;
					}
				}
			}
		}
	} else {

		var objChildren = objParent.childNodes;

		for (var i = 0; i < objChildren.length; i++) {
		
			if (objChildren[i].childNodes != null) {
				findElement(objChildren[i], blnExists);
			}
		}
	}
}

function backTrack(objParent) {
	
	while (objParent.parentNode != null) {

		if (objParent.tagName == "LI") {

			var objLink = objParent.getElementsByTagName("A");
			
			if (objLink != null) {
				if (strCurrentURL.indexOf(objLink[0].href.toLowerCase())) {
					objParent.className = strClassName;
				}
			}
		}
		objParent = objParent.parentNode;
	}
}

function Right(str, n) {

	if (n <= 0)

		return "";

	else if (n > String(str).length) return str;

	else {

		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);

	}
}