function initNav() {
	if (document.getElementById && document.getElementsByTagName) {
		var li_array = document.getElementById("nav").getElementsByTagName("LI");
		for( var i = 0; i < li_array.length; i++ ) {
			// bind li tags and set class names
			if (li_array[i].getElementsByTagName("UL").length > 0) { // li has subnav
				var newClassName = (li_array[i].className.match("selected") ? "less" : "more"); // if li has subnav and it's not active, add the "less" class, otherwise if it has subnav add the "more" class
				li_array[i].className = (li_array[i].className ? li_array[i].className + " " + newClassName : newClassName); // if there's already a class name, append a space and then the new class name
				li_array[i].onclick = preventBubbleUp;
			}
			// bind anchors
			var theLink = li_array[i].getElementsByTagName("A")[0];
			theLink.onclick = followLinkOnly;
		}
	}
}

function doSubMenu(pEl) {
	var parent = getGroupParent(pEl, "LI");
	if (!parent) parent = document.getElementById("nav");
	var li_array = parent.getElementsByTagName("LI");
	for (var i = 0; i < li_array.length; i++) {
		if (li_array[i].className.match("less") || li_array[i] == pEl) toggleMenuClass(li_array[i]);
	}
}

// prevent onclick event from propagating to the A's parent LI
function followLinkOnly(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	//if you want to pass a reference to the element clicked use target for mozilla and srcElement for IE
	//var theEl = e.target;
	//if (e.srcElement) theEl = e.srcElement;
}

function getGroupParent(pNode,strTagName) {
	var groupParent = pNode.parentNode;
	while (groupParent.tagName != strTagName.toUpperCase() && groupParent.tagName != "BODY") {
		groupParent = groupParent.parentNode;
	}
	if (groupParent.tagName == "BODY") {
		return false;
	} else {
		return groupParent;
	}
}

// prevent onclick event from propagating to the Li's parent LI
function preventBubbleUp(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	//call doSubMenu, pass a reference the LI clicked
	var theEl = e.target;
	if (e.srcElement) theEl = e.srcElement;
	doSubMenu(theEl);
	resizeLeftCol();
}

function resizeLeftCol() {
	var mainNav = document.getElementById("nav");
	var leftCol = document.getElementById("leftColumn");
	if (mainNav.offsetHeight>=(leftCol.offsetHeight-40)) {
		document.getElementById('leftColumn').style.height = mainNav.offsetHeight + 40 + "px";
		document.getElementById('visitMassArt').style.bottom = "8px";
	}

}

function toggleMenuClass(pEl) {
	if (pEl.className.match("less")) {
		pEl.className = pEl.className.replace("less", "more");
	} else {
		pEl.className = pEl.className.replace("more", "less");
	}
}
