function collapseall() { // Function hides all items in menu
	
	var navRoot = document.getElementById("navlist");
	var liTags = navRoot.getElementsByTagName("li");
	
	// Search through all li tags in menu and match tags where className contains "active"
	// then replace the word "active" with ""
	for (var i = 0; i < liTags.length; i++) {
		if (liTags[i].className.indexOf("active") != -1) {
			liTags[i].className = liTags[i].className.replace("active","");
		}
	}
	
}

window.onload = function startList() { // Function runs on page load and sets event handlers for menu
	
	if (!document.getElementById("navlist")) {
		return;
	}
	var navRoot = document.getElementById("navlist");
	var spanTags = navRoot.getElementsByTagName("span");
	var currentPage = false;
	
	for (var i = 0; i < spanTags.length; i++) { 
		
		// Search for current page in menu and display it
		var liTags = spanTags[i].parentNode.getElementsByTagName("li");
		for (var j = 0; j < liTags.length; j++) {
			if (liTags[j].className.indexOf("active") != -1) {
				currentPage = true;
				break;
			} else {
				currentPage = false;
			}
		}
		if (currentPage == true) {
			spanTags[i].parentNode.className += " active";
		}
		
		// Set event handler for menu items
		spanTags[i].onmouseup = function() {
			collapseall();
			if (this.parentNode.className.indexOf("active") == -1) {
				this.parentNode.className+=" active";
			}
		}
		
	}
	
}