	
	x_ie = document.all;
	x_firefox = document.getElementById&&!document.all;
	
var preventReopen = 1;

function MenuX (selfName)
{
	this.menuObject = null;
	this.selfName = selfName;

	this.open = function (menu, object, event, menuId)
	{
		if (preventReopen != 0)
		{
			preventReopen = 2;
			return;
		}
	
		if (this.menuObject != null) this.menuObject.style.visibility = "hidden";
		
		this.resetDelayedHide();
		
		object.onmouseout = function()
		{
			menu.delayedHide();
		}
		
		this.menuObject = document.getElementById(menuId);
		
		this.menuObject.onmouseover = function ()
		{
			menu.resetDelayedHide();
		}
		this.menuObject.onmouseout = function ()
		{
			menu.hide(event);
		}
		
		this.menuObject.onclick = function ()
		{
			menu.delayedHide();
		}
		
		this.showhide(this.menuObject.style, event, "visible", "hidden")
		this.menuObject.x=this.getposOffset(object, "left")
		this.menuObject.y=this.getposOffset(object, "top")
		this.menuObject.style.left=this.menuObject.x-this.clearbrowseredge(object, "rightedge")+"px"
		this.menuObject.style.top=this.menuObject.y-this.clearbrowseredge(object, "bottomedge")+object.offsetHeight+1+"px"
	}

	this.delayedHide = function ()
	{
		this.delayhide = setTimeout(this.selfName + ".menuObject.style.visibility='hidden';", 250);
	}

	this.resetDelayedHide = function ()
	{
		if (this.delayhide != "undefined") clearTimeout(this.delayhide)
	}

	this.hide = function (event)
	{
		var evtobj=window.event? window.event : event;
		if (x_ie&&!this.menuObject.contains(evtobj.toElement))
			menu.delayedHide()
		else
		if (x_firefox&&event.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
			menu.delayedHide()
	}
	
	this.getposOffset = function(what, offsettype)
	{
		var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
		var parentEl=what.offsetParent;
		while (parentEl!=null)
		{
			totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
			parentEl=parentEl.offsetParent;
		}
		return totaloffset;
	}

	this.showhide = function(obj, e, visible, hidden)
	{
		if (this.ie || this.firefox)
			this.menuObject.style.left=this.menuObject.style.top="-500px"
		if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
			obj.visibility=visible
		else if (e.type=="click")
			obj.visibility=hidden
	}

	this.iecompattest = function()
	{
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}

	this.clearbrowseredge = function(obj, whichedge)
	{
		var edgeoffset=0
		if (whichedge=="rightedge")
		{
			var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
			this.menuObject.contentmeasure=this.menuObject.offsetWidth
			if (windowedge-this.menuObject.x < this.menuObject.contentmeasure)  //move menu to the left?
				edgeoffset=this.menuObject.contentmeasure-obj.offsetWidth
		}
		else
		{
			var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
			var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
			this.menuObject.contentmeasure=this.menuObject.offsetHeight
			if (windowedge-this.menuObject.y < this.menuObject.contentmeasure)
			{ //move up?
				edgeoffset=this.menuObject.contentmeasure+obj.offsetHeight
				if ((this.menuObject.y-topedge)<this.menuObject.contentmeasure) //up no good either?
					edgeoffset=this.menuObject.y+obj.offsetHeight-topedge
			}
		}
		return edgeoffset
	}

	this.contains_firefox = function(a, b)
	{
		while (b.parentNode)
			if ((b = b.parentNode) == a)
				return true;
		return false;
	}
}

