﻿var navShown=false;
var navFade=null;
var NNN=(document.layers)?true:false;
var NIE=(document.all)?true:false;
var nameShown = "";
var MENU_BORDER = 2;
	
function hideNav() {
	if (navFade) {
		clearTimeout(navFade);
		navFade=null;
	}
	if(navShown) {
		if (NNN){
			document.layers[nameShown].visibility="hide";
		}
		else if (NIE){
			document.all[nameShown].style.visibility="hidden";
		}
	}
	navShown=false;
	nameShown="";
	return true;
}

function GetTopAbsolutePosition(oElement) {
	var lTop=0;
	var oStyle=document.all(oElement).style;
	if (oStyle.position=="absolute") {
		lTop=oStyle.pixelTop;
	}	
	else {
		var oCurrent=document.all(oElement);
		var oBody=window.document.body;
		do {
			lTop+=oCurrent.offsetTop;
			oCurrent=oCurrent.offsetParent;
		}
		while (oCurrent!=oBody);
	}
	return lTop;
}

function GetLeftAbsolutePosition(oElement) {
	var lLeft=0;
	var oStyle=document.all(oElement).style;
	if (oStyle.position=="absolute") {
		lLeft=oStyle.pixelLeft;
	}	
	else {
		var oCurrent=document.all(oElement);
		var oBody=window.document.body;
		do {
			lLeft+=oCurrent.offsetLeft;
			oCurrent=oCurrent.offsetParent;
		}
		while (oCurrent!=oBody);
	}
	return lLeft;
}

function EvaluateButtonAndMenuState(imgButName,divMenuName,imgUpName,imgDnName) {
		var imgButton=document.all(imgButName);
		var imgUp=document.all(imgUpName);
		var imgDn=document.all(imgDnName);
		var divMenu=document.all(divMenuName);
		if (imgButton!=null && imgUp!=null && imgDn!=null) { 
			var oEvent=window.event;
			var oOver=oEvent.toElement;
			var oPush = oEvent.srcElement;
			if (((oOver==imgButton)||(oOver==divMenu))||((oPush==imgButton)&&(divMenu.style.visibility!="visible"))||divMenu.contains(oOver)) {
				if (imgButton.src!=imgUp.src) {
					imgButton.src=imgUp.src;
					var lIdealLeft=GetLeftAbsolutePosition(imgButName);
					var lIdealTop=GetTopAbsolutePosition(imgButName);
					var stlMenu=divMenu.style;
					stlMenu.pixelLeft=lIdealLeft;
					var oBody=document.body;
					var oTable=divMenu.all.tags("TABLE").item(0);
					var lScrollTop=oBody.scrollTop;
					var lClientHeight=oBody.clientHeight; 
					lIdealTop+=imgButton.offsetHeight;
					var lAvailableHeight=lClientHeight; 
					var lMenuHeight=oTable.offsetHeight+MENU_BORDER+2;
					var lMenuWidth=oTable.offsetWidth;
					if (lMenuHeight>lAvailableHeight) {
						lMenuHeight=lAvailableHeight;
						oTable.style.pixelTop=0;
						oTable.style.clip="rect(0, auto, "+lMenuHeight-MENU_BORDER+", auto)";
					}
					else {
						oTable.style.clip="rect(auto)";
						oTable.style.pixelTop=0;
					}
					stlMenu.pixelHeight=lMenuHeight;
					if ((lIdealTop+lMenuHeight-lScrollTop)>lAvailableHeight)  lIdealTop=lAvailableHeight-lMenuHeight+lScrollTop;
					stlMenu.pixelTop=lIdealTop;
					stlMenu.pixelWidth=lMenuWidth+MENU_BORDER+2;
					stlMenu.visibility="visible";
				}
			}
			else {
				if (imgButton.src!=imgDn.src) {
					imgButton.src=imgDn.src;
					divMenu.style.visibility="hidden";
				}
			}
			CancelEvent();
		}
	nameShown = divMenuName;
	if(NNN) navFade=setTimeout("hideNav();",10000);
	navShown=true;
}

function CancelEvent() {
	var oEvent = window.event;
	oEvent.returnValue=false;
	oEvent.cancelBubble=true;
}
	
function closeNav() {
	navFade=setTimeout("hideNav();",100);
	//hideNav();
	return true;
}

function mouse_up(e) {
	closeNav();
	return true;
}

if (NNN) {
	window.onmouseup=mouse_up;
	window.captureEvents(Event.MOUSEUP);
}

function ApplyClass(sClass) {
	window.event.srcElement.className = sClass;
}
