// =hide .hide

// Show a particular .hide element
function showHideClass(index) {
	var icon = document.getElementById("showIcon"+index);
	if (icon) {
		(icon.innerHTML == "+") ? icon.innerHTML = "-" : icon.innerHTML = "+";
		toggle(getElementsByClass("hide",document,'*')[index]);	
	}
}
// Recursively search previousSiblings until you get something that's an Element node.
function getPreviousElement(el) {
	if (el.nodeType !== 1) {
		el = el.previousSibling;
		getPreviousElement(el);
	}

	return el;
}
// Gets all .hide UL and hides them.
// Then it makes the preceeding element into a link that allows them to click to view more.
function hideHideClass() {
	var hiders = getElementsByClass("hide",document,'*');
	if (hiders.length) {
		for (i=0; i<hiders.length; i++){
			toggleDisplay(hiders[i], false);
			var hiderPS = getPreviousElement(hiders[i].previousSibling);
			var inHiderPS = hiderPS.innerHTML;
			hiderPS.innerHTML = '<span id="showIcon'+i+'">+</span> <a href="#show'+inHiderPS.replace(/ /g,"")+'" onClick="showHideClass('+i+');return true;">'+inHiderPS+'</a>';
			hiderPS.style.display = "block";
		}
	}
}
addLoadEvent(hideHideClass);

// =sidebar functions

// Add the "over" class to an object
function addSidebarHover(object) {
	object.onmouseover = function(){
		object.className = "over";
	}
	object.onmouseout = function(){
		object.className = "";
	}
}
// Hides all the UL under #sidebar.
// Then calls addSidebarHover on any LI that don't have current class.
// Then it shows those who ARE current.
function showCurrentSidebar() {
if (document.getElementById("sidebar")){
	var sidebarList = document.getElementById("sidebar").getElementsByTagName("ul");
	for (i = 1; i < sidebarList.length; i++) {
		sidebarList[i].style.display = "none";
	}
	
	var sidebarListItem = document.getElementById("sidebar").getElementsByTagName("li");
	for (i = 0; i < sidebarListItem.length; i++) {
		if (!(sidebarListItem[i].className === "current"))
			addSidebarHover(sidebarListItem[i]);
		if ( (sidebarListItem[i].className === "current") && (sidebarListItem[i].getElementsByTagName("ul")[0]) ) {
			sidebarListItem[i].getElementsByTagName("ul")[0].style.display = "block";
		}
	}
	for (i = 0; i < sidebarList.length; i++) {
		for (j = 0; j < sidebarList[i].getElementsByTagName("li").length; j++) {
			if (sidebarList[i].getElementsByTagName("li")[j].className === "current") {
				sidebarList[i].style.display = "block";
			}
		}
	}
}
}

// Add the onLoad events to the body, unobtrusively.
addLoadEvent(showCurrentSidebar);