var currentPage;
var dropTimer = '';

function findMe(target, cat){
	setupDropDown();
	currentPage = target;
	foundPage = document.getElementById(target);
	foundPage.className = 'active';
	if (hasSub(foundPage.parentNode)) {
		expandNode(foundPage.parentNode);
	}
	if (cat){
		document.getElementById(cat).className = 'active';
	}
}

function hasSub(target) {
	targetChilds = target.childNodes;
	for (i=0;i<targetChilds.length;i++) {
		if (targetChilds[i].nodeType == 1 && targetChilds[i].tagName == 'UL') {
			return true;
			break;
		}
	}
	return false;
}

function setupDropDown() {
	navNodes = document.getElementById('dropdown').childNodes;
	for (i=0;i<navNodes.length;i++) {
		if (navNodes[i].nodeType == 1) {
			navNodes[i].onmouseover = function() {
				expandNode(this);
			}
			navNodes[i].onmouseout = function() {
				collapseNode(this);
			}
		}
	}
}

function expandNode(target) {
	window.clearTimeout(dropTimer);
	if (hasSub(target)) {
		subnav = target.getElementsByTagName('ul')[0];
		subnav.setAttribute('id', 'currentSub');
		subnav.style.display = 'inline';
	}
}

function collapseNode(target) {
	if (!hasSub(document.getElementById(currentPage).parentNode) && document.getElementById('currentSub')) {
		dropTimer = window.setTimeout('document.getElementById("currentSub").style.display="none";document.getElementById("currentSub").removeAttribute("id");', 400);
	}
}