var isvisible;
var topMar = 4;
var leftMar = -2;
var space = 1;
var MENU_SHADOW_COLOR='#EFEFEF';
var global = window.document;
global.fo_currentMenu = null;
global.fo_shadows = new Array;

function HideMenu(){
	var mX,mY,vDiv,mDiv;
	if (isvisible == true){
		vDiv = document.all("menuDiv");
		if(!vDiv){alert('no')}
		mX = window.event.clientX + document.body.scrollLeft;
		mY = window.event.clientY + document.body.scrollTop;
		if ((mX < parseInt(vDiv.style.left)) ||
		 (mX > parseInt(vDiv.style.left)+vDiv.offsetWidth) ||
		 (mY < parseInt(vDiv.style.top)-h) ||
		 (mY > parseInt(vDiv.style.top)+vDiv.offsetHeight))	{
			vDiv.style.visibility = "hidden";
			isvisible = false;
		}
	}
}
function HideMenu1(){
	var mX,mY,vDiv,mDiv;
	if (isvisible == true){
		vDiv = document.all("menuDiv");
		if(!vDiv){alert('no')}
		mX = window.event.clientX + document.body.scrollLeft;
		mY = window.event.clientY + document.body.scrollTop-10;
		if ((mX < parseInt(vDiv.style.left)) ||
		 (mX > parseInt(vDiv.style.left)+vDiv.offsetWidth)||
		 (mY < parseInt(vDiv.style.top))||
		 (mY > parseInt(vDiv.style.top)+vDiv.offsetHeight))	
		{
			vDiv.style.visibility = "hidden";
			isvisible = false;
		}
	}
}
function ShowMenu(s,w,hs) {
	vSrc = window.event.srcElement;
	//s = "<table id='submenu' cellspacing=1 cellpadding=3 style='width:"+w+
	//"px;' bgcolor=#9cc5f8 onmouseout='HideMenu()'><tr height=23><td nowrap align=left bgcolor=#fffff9>" +
	//s + "</td></tr></table>";
	s = "<div id='_MenuPanel' style='padding:0px;background-color:#FEFEFE;width:" + w +
	"px;' onmouseout='HideMenu()' onselectstart='return false;'>" + s + "</div>";

	h = vSrc.offsetHeight;
	w = vSrc.offsetWidth;
	l = vSrc.offsetLeft + leftMar + hs;
	t = vSrc.offsetTop + topMar + h + space-2;
	vParent = vSrc.offsetParent;
	while (vParent.tagName.toUpperCase() != "BODY"){
		l += vParent.offsetLeft;
		t += vParent.offsetTop;
		vParent = vParent.offsetParent;
	}
	if(typeof(menuDiv)=='undefined'){CreateBaseDiv();}
	menuDiv.innerHTML = s;
	menuDiv.style.top = t;
	menuDiv.style.left = l;
	menuDiv.style.visibility = "visible";
	isvisible = true;
    makeRectangularDropShadow(_MenuPanel, MENU_SHADOW_COLOR, 4);
}
function ShowMenu1(s,w,hs,ht) {
	vSrc = window.event.srcElement;
	//s = "<table id='submenu' cellspacing=1 cellpadding=3 style='width:"+w+	"px;' bgcolor=#9cc5f8 onmouseout='HideMenu()'><tr height=23><td nowrap align=left bgcolor=#fffff9>" +	s + "</td></tr></table>";
	s = "<div id='_MenuPanel' style='padding:0px;background-color:#FEFEFE;width:" + w +
	"px;' onmouseout='HideMenu1()' onselectstart='return false;'>" + s + "</div>";
	
	h = vSrc.offsetHeight-ht;
	w = vSrc.offsetWidth;
	l = vSrc.offsetLeft + leftMar + hs;
	t = vSrc.offsetTop + topMar + h + space-2;
	vParent = vSrc.offsetParent;
	while (vParent.tagName.toUpperCase() != "BODY"){
		l += vParent.offsetLeft;
		t += vParent.offsetTop;
		vParent = vParent.offsetParent;
	}
	if(typeof(menuDiv)=='undefined'){CreateBaseDiv();}
	menuDiv.innerHTML = s;
	menuDiv.style.top = t;
	menuDiv.style.left = l;
	menuDiv.style.visibility = "visible";
	isvisible = true;
    makeRectangularDropShadow(_MenuPanel, MENU_SHADOW_COLOR, 4);
}

function makeRectangularDropShadow(el, color, size){
	for(var i=size; i>0; i--){
		var rect = document.createElement('div');
		var rs = rect.style;
		rs.position = 'absolute';
		rs.left = (el.style.posLeft + i) + 'px';
		rs.top = (el.style.posTop + i) + 'px';
		rs.width = el.offsetWidth + 'px';
		rs.height = el.offsetHeight + 'px';
		rs.zIndex = el.style.zIndex - i;
		//rs.backgroundColor = color;
		var opacity = 1 - i / (i + 1);
		rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
		el.insertAdjacentElement('afterEnd', rect);
		global.fo_shadows[global.fo_shadows.length] = rect;
	}
}
function CreateBaseDiv(){
	var o = document.createElement('<div id="menuDiv" name="menuDiv" style="position:absolute; z-index:100;"></div>');
	document.body.insertAdjacentElement('afterBegin', o);
}
