function ancestor(element, ancestorTagName, ancestorIndex) {
	ancestorIndex = ancestorIndex || 0;
	var domElement = element; 
	var indexCounter = 0; 
	while (domElement.tagName.toLowerCase() !== "body") { 
		if (domElement.tagName.toLowerCase() === ancestorTagName) { 
			if (indexCounter === ancestorIndex) { 
				return domElement; 
			}
		}
		domElement = domElement.parentNode;
	}
	return null;
}

function cancelBubble(e) {
	e = e || event;
	e.cancelBubble = true;
	if (e.stopPropagation) {
		e.stopPropagation();
	}
}

function openMenu() {
	var rightMenu = document.getElementById("rightMenu");
	var olColl = rightMenu.getElementsByTagName("ol");
	var ilColl = rightMenu.getElementsByTagName("li");
	var aColl = rightMenu.getElementsByTagName("a");
	var i, l;
	for (i = 1, l = olColl.length; i < l; i += 1) {
		olColl[i].style.display = "none";
	}
	
	for (i = 0, l = ilColl.length; i < l; i += 1) {
		if (ilColl[i].getElementsByTagName("ol").length ||
			ilColl[i].getElementsByTagName("ul").length) {
			ilColl[i].onclick = openMenu.showHide;
			ilColl[i].style.background = "url('images/Arrow_left.gif') no-repeat 30px 10px";
		}
	}
	
	for (i = 0, l = aColl.length; i < l; i += 1) {
		if (aColl[i].href === window.location.href) {
			aColl[i].style.color = "red";
			try {
				ancestor(ancestor(aColl[i], "li", 0).parentNode, "li", 0).style.borderWidth = "0px";
				ancestor(ancestor(aColl[i], "li", 0).parentNode, "li", 0).style.background = "url('images/Arrow_down.gif') no-repeat 32px 10px";
				ancestor(aColl[i], "ol", 0).style.display = "";
			} catch (err) {}
		}
	}
}

openMenu.showHide = function (e) {
	e = e || event;
	cancelBubble(e);
	var sElm = ancestor(e.target || e.srcElement, "li", 0);
	var listElement = sElm.getElementsByTagName("ol")[0];
	if (! listElement) {
		listElement = sElm.getElementsByTagName("ul")[0];
	}
	if (listElement) {
		if (listElement.style.display === "") {
			listElement.style.display = "none";
			sElm.style.borderWidth = "";
			sElm.style.background = "url('images/Arrow_left.gif') no-repeat 30px 10px";
		} else {
			listElement.style.display = "";
			sElm.style.borderWidth = "0px";
			sElm.style.background = "url('images/Arrow_down.gif') no-repeat 32px 10px";
		}
	}
};

function winLoad() {
	//openMenu();
}

window.onload = winLoad;
