function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function menuDropDowns() {
	if (!document.getElementById) return false;
	if (!document.getElementById("menu")) return false;
	if (document.all) {
		navRoot = document.getElementById("menu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				if ((node.className != "footprint-data") && (node.className != "reap-software")) {
					node.onmouseover=function() {
						this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}
}

addLoadEvent(menuDropDowns);

function homeNews() {
	if (!document.getElementById) return false;
	if (!document.getElementById("homenews")) return false;
	var newsList = document.getElementById("homenews");
	var newsTabs = newsList.getElementsByTagName("LI");
	for (i=0;i<newsTabs.length;i++) {
		newsTabs[i].onclick = function() {
			this.style.position = "static";
			var tabClass = this.className;
			var displayMe = document.getElementById(tabClass);
			if (tabClass == "archivedNews") {
				getPreviousElement(displayMe).style.display = "none";
				getPreviousElement(this).style.position = "relative";
			} else if (tabClass == "latestNews") {
				getNextElement(displayMe).style.display = "none";
				getNextElement(this).style.position = "relative";
			}
			displayMe.style.display = "block";
			return false;
		}
	}
}

addLoadEvent (homeNews);

function getFirstElement(node) {
	if (node.firstChild.nodeType == 1) {
		return node.firstChild;
	}
	if (node.firstChild.nextSibling) {
		return getNextElement(node.firstChild);
	}
	return null;
}

function getNextElement (node) {
	if (node.nextSibling.nodeType == 1) {
		return node.nextSibling;
	}
	if (node.nextSibling.nextSibling) {
		return getNextElement (node.nextSibling);
	}
	return null;
}

function getPreviousElement (node) {
	if (node.previousSibling.nodeType == 1) {
		return node.previousSibling;
	}
	if (node.previousSibling.previousSibling) {
		return getPreviousElement (node.previousSibling);
	}
	return null;
}

function insertAfter (newElement,targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}