//browser detect
var isNS = (navigator.appName == "Netscape");
var isMacIE = ( (navigator.userAgent.indexOf("IE 4")  > -1) && (navigator.userAgent.indexOf("Mac")  > -1) );
var layerRef = (isNS) ? "document" : "document.all";
var styleRef = (isNS) ? "" : ".style";
var isDynamic = ( (document.layers || document.all) && !isMacIE );
//var isDynamic = ( (document.layers || document.all));

var activeMenu = 0;
var finalClip;
var yyPos=0;
var xxPos=0;

function aMenu(menuLayerRef, offset) {	
	scrBars = 20;	
	if (isDynamic && activeMenu != menuLayerRef) {

		if (activeMenu) hideMenu("menu" + activeMenu);
			
		menuID = "menu" + menuLayerRef;
		activeMenu = menuLayerRef;
	
		if (isNS) {		
			document[menuID].top = yyPos-20+offset*16;
			document[menuID].left = xxPos+166;		
		} else {
    
			dif=0;	
			mtop=yyPos+175+offset*2-dif
			if (document.all[menuID].offsetHeight+mtop>(document.body.scrollTop + document.body.clientHeight - scrBars)) 
			{corr=document.body.scrollTop + document.body.clientHeight - (document.all[menuID].offsetHeight+mtop)- 2}
			else
			{corr=0}
			document.all[menuID].style.pixelTop = mtop+corr;
			document.all[menuID].style.pixelLeft = xxPos+130;
		}

		if (!isNS) {showMenu(menuID)}
		
	}
	if (isDynamic && !isNS) window.event.cancelBubble = true;
}

function keepInWindow() {
	scrBars = 20;

	if (NS4) {
		winRight = (window.pageXOffset + window.innerWidth) - scrBars;
		rightPos = this.left + menuWidth;
   
		if (rightPos > winRight) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.left;
				newLeft = ((parentLeft-menuWidth) + childOverlap);
				this.left = newLeft;
			}
			else {
				dif = rightPos - winRight;
				this.left -= dif;
			}
		}

		winBot = (window.pageYOffset + window.innerHeight) - scrBars;
		botPos = this.top + this.fullHeight;

		if (botPos > winBot) {
			dif = botPos - winBot;
			this.top -= dif;
		}
	}
	else {
    	winRight = (document.body.scrollLeft + document.body.clientWidth) - scrBars;
		rightPos = this.style.pixelLeft + menuWidth;
	
		if (rightPos > winRight) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.style.pixelLeft;
				newLeft = ((parentLeft - menuWidth) + childOverlap);
				this.style.pixelLeft = newLeft;
			}
			else {
				dif = rightPos - winRight;
				this.style.pixelLeft -= dif;
			}
		}

		winBot = (document.body.scrollTop + document.body.clientHeight) - scrBars;
		botPos = this.style.pixelTop + this.fullHeight;

		if (botPos > winBot) {
			dif = botPos - winBot;
			this.style.pixelTop -= dif;
		}
	}
}


function showMenu(layerID) {
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.visibility = "visible"');
}

function hideMenu(layerID) {
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.visibility = "hidden"');
}

function killMenu(e) {
	//check if there is a menu active
	if (activeMenu) {
		menuID = "menu" + activeMenu;
		if (isNS) {
			menuX1 = document[menuID].left;
			menuX2 = menuX1 + document[menuID].clip.right;
			menuY1 = document[menuID].top;
			menuY2 = menuY1 + document[menuID].clip.bottom;
			if (e.pageX > menuX2 || e.pageY > menuY2 || e.pageY < menuY1) {		
			//alert(e.pageY + " -  " + menuY1);
				hideMenu(menuID);
				activeMenu = 0;
			}
		} else {
				hideMenu(menuID);
				activeMenu = 0;

		}
	}  

}

function init() {
	if (isDynamic) {
		if (isNS) { 
			//yyPos=document["map"].pageY;		
			//xxPos=document["map"].pageX;		
			//document.captureEvents(Event.MOUSEMOVE); 
			//document.onmousemove = killMenu;
			setTimeout("window.onresize=reDo",500);
		} else {
			yyPos = document.all["map"].offsetTop;
			xxPos = document.all["map"].offsetLeft;		
			document.onmouseover = killMenu;
		}
		
	}
}

function reDo(){window.location.reload()}