var activeMenu = null;
var timeOutFn;
var timeOut;

function showMenu(e,o){
	if (o.firstChild.style.left=="") o.firstChild.style.left=o.firstChild.offsetLeft-12+"px";

	
	var el = o.firstChild.firstChild;
	el.parentDiv = o;
	
	if (el.animating || (!isNaN(el.y) && el.y!=0)) return;
	
	if (activeMenu) hideMenu(activeMenu.e,activeMenu.o,true,true);
	activeMenu = {e:e,o:o};	
	clearTimeout(timeOut);
	
	el.parentDiv.childNodes[1].className="on";
	if (!el.offset){
		el.offset = {left:el.offsetLeft, top:el.offsetTop, width:el.offsetWidth, height:el.offsetHeight};
	}
	el.y=0;
	el.animating = true;

	el.intervalFn = function(){
		el.y+= (el.offset.height-el.y)/8+3;
		if (el.y>el.offset.height){
			clearInterval(el.interval);
			el.style.top = (el.offset.top)
			el.y = el.offset.height;
			el.animating = false;
		}
		el.style.top = (el.offset.top - el.offset.height + el.y)+"px";			
	}

	el.interval = setInterval(el.intervalFn,20);
	el.intervalFn();
	el.style.visibility="visible";
}


function hideMenu(e,o,forceClose,immediate,inf){
	var el = o.firstChild.firstChild;	
	var srcEl,relEl;
	if (!forceClose){
		srcEl = (document.all) ? e.srcElement : e.target;
		relEl = e.relatedTarget || e.toElement;	
		clearTimeout(timeOut);
		if (!inSubNav(srcEl)){
			timeOutFn = function(){
				if (activeMenu) hideMenu(activeMenu.e,activeMenu.o,true);
			}
			timeOut = setTimeout(timeOutFn,2000);
			return;
		}
	}
	if (forceClose && immediate){
	
		activeMenu = null;
		el.y=0;
		el.animating = false;
		el.parentDiv.childNodes[1].className="";
		el.style.top = (el.offset.top - el.offset.height + el.y)+"px";	
		clearInterval(el.interval);
	
	}
	if ((forceClose || (inSubNav(srcEl) && !inSubNav(relEl))) && !el.animating && el.y==el.offset.height){
		el.animating=true;
		el.intervalFn = function(){
			el.y-= (el.offset.height-el.y)/8+3;
			if (el.y<0){
				clearInterval(el.interval);
				el.y=0;
				el.animating = false;
				el.parentDiv.childNodes[1].className="";
				activeMenu = null;
			}
			el.style.top = (el.offset.top - el.offset.height + el.y)+"px";	
		}
		el.interval = setInterval(el.intervalFn,20);
	}
	function inSubNav(o){
		while (o!=document.body){
			if (o.className=="subnav" || o.className=="subnav2") return true;
			o = o.parentNode;
		}
		return false;
	}
}

function highlightMenu(id){
	var menuDiv = document.getElementById("topnavList");
	elTest(menuDiv);
	function elTest(o){
		if (!o.childNodes) return;
		for (var i=0;i<o.childNodes.length;i++){
			elTest(o.childNodes[i]);
			if (o.childNodes[i].id==id) o.childNodes[i].className="on";
		}
	}
}



// Gallery Popup
function galleryPopup(src){
	window.open("/helpers/galleryPopup.aspx?src="+escape(src),"_popup","width=660,height=410");
	return false;
}
function galleryPopup2(src){
	window.open("/helpers/galleryPopupPortrait.aspx?src="+escape(src),"_popup","width=320,height=410");
	return false;
}


function disclaimerOpen(){
	window.open("/Docs/Disclaimer.aspx","_popup","width=500,height=410");
	return false;
}
