var inmenu=false;
var btype="";
var bLeftOffset=0;
var bTopOffset=0;
var bWidthAdj=0;
var tmp=0;
var mPosX=0;
var mPosY=0;
var oldmenu='';
var lastmenu='';
var tglFlag=0;
var x=0,y=0;
var isIE = false;
	if(navigator.appName.indexOf("Netscape")>-1)
	{
		btype="Netscape";
		bLeftOffset=-1;
		bTopOffset=21;
		bWidthAdj=-7;
	} else if((navigator.appName.indexOf("Microsoft")>-1) || (navigator.appName.indexOf("MSIE")>-1)) {
		isIE = true;
		btype="Microsoft Internet Explorer";
		bLeftOffset=-1;
		bTopOffset=21;
		bWidthAdj=-10;
	} else if(navigator.appName.indexOf("Opera")>-1) {
		btype="Opera";
		bLeftOffset=-1;
		bTopOffset=21;
		bWidthAdj=-10;
	} else {
		make="unknown";
	}

function Menu(current) {
    if (!document.getElementById) return;
	if (current == '') return;	
	if (inmenu) return;
	var spcoffset=0; x=0;y=0;
	var basecurrent=current;
    getAnchorPosition(basecurrent + 'loc');
    oldmenu=lastmenu;
    lastmenu=current;
    if (oldmenu) {
		inmenu=false;
		Erase(oldmenu);
	}

	var cellleft = document.getElementById(current + 'loc');
	var posset = document.getElementById('menu-' + current);
	var curWidth = posset.offsetWidth;
	var navcell = document.getElementById('navcell');
	var navtable = document.getElementById('navtable');
	var ctrline = Math.round(navcell.offsetWidth / 2);
	var tagstart = document.getElementById(current + 'tags');
	var tagend = document.getElementById(current + 'tage');
	
    box=document.getElementById('menu-' + basecurrent);
	var algn = cellleft.align;
	algn = algn.toUpperCase();
	
	var tblleft = navtable.offsetLeft;
	
	//Where "would" the box be put on the screen? Is it to the left or right of center
	var tpos = cellleft.offsetLeft + cellleft.offsetWidth;
	if (tpos < ctrline || tpos == ctrline) { //Menu position will be to left of center
		spcoffset = tagstart.offsetLeft;
	} else { //Menu position will be to right of center
		if (isIE) {
			spcoffset = cellleft.offsetWidth - posset.offsetWidth;
		} else {
			spcoffset = tagend.offsetLeft - posset.offsetWidth; //OK
		}
	}
	//Override if the left of the table is to the right of the centerline
	if (tblleft > ctrline) {
		if (isIE) {
			spcoffset = cellleft.offsetWidth - posset.offsetWidth;
		} else {
			spcoffset = tagend.offsetLeft - posset.offsetWidth; //OK
		}
	}
	//Setup and display the box.
	box.style.left = x + bLeftOffset + spcoffset;
	box.style.top = y + bTopOffset;
	
	
	
	if (mnuStyle == "SIDE") {
		var b1 = box.style.left;
		b1 = b1.replace(/px/, "");
		b1 = b1 /1;
		var b2 = box.style.top;
		b2 = b2.replace(/px/, "");
		b2 = b2 / 1;
		b1+=mnuSideOffsetLeft;
		b1+="px";
		b2-=mnuSideOffsetTop;
		b2+="px";
		box.style.left = b1;
		box.style.top = b2;
	}
	Highlight(current);
    box.style.visibility="visible";
//    box.style.backgroundColor=mnuBgColorHighlight;
    inmenu=true;
}
function Erase(current) {
   if (!document.getElementById) return;
   if (inmenu) return;
   if (current == '') return;
   m=document.getElementById('menu-' + current);
   box=document.getElementById('menu-' + current);
   box.style.visibility="hidden";
   UnHighlight(current);
}
function Timeout(current) {
   inmenu=false;
   window.setTimeout("Erase('" + current + "');",150);
}
function Highlight(item) {
   if (!document.getElementById) return;
	var x = document.getElementById(item + 'loc');
	//x.style.backgroundColor=mnuBgColorHighlight;
}
function UnHighlight(item) {
   if (!document.getElementById) return;
	var x = document.getElementById(item + 'loc');
	//x.style.backgroundColor='#FFFFCC'; //mnuBgColorHighlightOff;

}

function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	mPosX=x;
	mPosY=y;

	}
// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
