function firstLoad() {
	menuList = document.getElementById("menu");
	subMenus = menuList.getElementsByTagName("ul");
	for(m=0;m<subMenus.length;m++) {
		subMenuLink = subMenus[m].parentNode.getElementsByTagName("a")[0];
		subMenuLink.originalClass = subMenuLink.className;
		// only hide the sub menu if the submenu's link is not contained in the current document.location
		if(document.location.toString().indexOf(subMenuLink.href) == -1) {
			hideSubMenu(subMenus[m], subMenuLink);
		} else {
			showSubMenu(subMenus[m], subMenuLink);
		}
		subMenuLink.onclick = function() {
			currSubMenu = this.parentNode.getElementsByTagName("ul")[0];
			if(currSubMenu.expanded == true) {
				// hide this submenu
				hideSubMenu(currSubMenu, this);
				// reposition the footer
				repositionFooter();
			} else {
				// hide all submenus
				hideAllSubMenus();
				// then show this one
				showSubMenu(currSubMenu, this);
				// reposition the footer
				repositionFooter();
			}
			return false;
		}		
	}
	repositionFooter();
}

function hideAllSubMenus() {
	subMenus = menuList.getElementsByTagName("ul");
	for(m=0;m<subMenus.length;m++) {
		subMenuLink = subMenus[m].parentNode.getElementsByTagName("a")[0];
		hideSubMenu(subMenus[m], subMenuLink);
	}
}

function hideSubMenu(subMenu, subMenuLink) {
	// set the display of the current submenu to none
	subMenu.style.display = "none";
	subMenu.style.left = "-999em";
	subMenu.style.position = "absolute";
	// set the expanded of the submenu to false
	subMenu.expanded = false;
	// show the up expand icon 
	subMenuLink.className = subMenuLink.originalClass + " menuhidden";
}

function showSubMenu(subMenu, subMenuLink) {
	// set the display of the current submenu to shown
	subMenu.style.display = "block";
	subMenu.style.left = "auto";
	subMenu.style.position = "static";
	// set the expanded of the submenu to true
	subMenu.expanded = true;
	// show the contract icon
	subMenuLink.className = subMenuLink.originalClass + " menushown";
}

function repositionFooter() {
	if(document.getElementById) {
		footer = document.getElementById("navigationbottom");
		leftmenu = document.getElementById('menu');
	} else if (document.all) {
		footer = document.all["navigationbottom"];
		leftmenu = document.all["menu"];
	}
	if(document.layers||(document.getElementById&&!document.all)){
		browserHeight = window.innerHeight;
	} else if (document.all) {
		browserHeight = document.body.clientHeight;
	}
	footerHeight = footer.offsetHeight;
	footerYPosition = footer.offsetTop;
	menuHeight = leftmenu.offsetHeight;
	menuYPosition = leftmenu.offsetTop;
	newPosition = browserHeight-footerHeight-20;
	if(footerYPosition && browserHeight && footerHeight && menuHeight && menuYPosition) {
		if(footerYPosition<browserHeight && newPosition>(menuYPosition+menuHeight)) {
			footer.style.position = 'absolute';
			footer.style.top = newPosition+'px';
		} else {
			footer.style.position = 'static';
		}
	}
}

// run functions on load
if (document.all&&window.attachEvent) {
	// IE-Win 
	window.attachEvent("onload", firstLoad);
	window.attachEvent("onresize", repositionFooter);
} else if (window.addEventListener) {
	// Others
	window.addEventListener("load", firstLoad, false);
	window.addEventListener("resize", repositionFooter, false);
}