function menuObject(anchorid, pos, glidetime)
{
	this.delaybeforehide = 100;
	this.disableanchorlink=true;
	this.anchorobj=document.getElementById(anchorid)
	this.subobj=document.getElementById(this.anchorobj.getAttribute("rel"))
	this.subobjsource=this.anchorobj.getAttribute("rev")
			
	this.initialClass = this.anchorobj.className;
	
		if (this.subobjsource!=null && this.subobjsource!="")
			dropObject(this.subobjsource, this.anchorobj.getAttribute("rel"))

		this.subobj.dropposition=pos.split("-")
		this.subobj.glidetime=glidetime || 1000
		this.subobj.style.left=this.subobj.style.top=0
		
		this.curObj = this;
		
		this.anchorobj.objBinder = this;
		this.subobj.objBinder = this;
		
		this.anchorobj.onmouseover=function(e)
		{
			this.objBinder.show(this, this.objBinder.subobj, e)
		}
		
		this.anchorobj.onmouseout=function(e)
		{
			this.objBinder.hide(this.objBinder.subobj, this.objBinder.anchorobj, this.objBinder.subobj, e)
		}
		
		this.subobj.onmouseout=function(e)
		{
			this.objBinder.hide(this, this.objBinder.anchorobj, this.objBinder.subobj, e)
		}

	  this.subobj.style.visibility="hidden";			
}


function hide( activeobj, anchorobj, subobj, e)
{
	
	if (!isExisted(activeobj, e) && !isExisted(anchorobj, e))
	{
		window["hidetimer_"+subobj.id]=setTimeout
		(
			function()
			{
				subobj.style.visibility="hidden";
				subobj.style.left=subobj.style.top=0;
				anchorobj.className=this.initialClass;	
				clearTimeout(window["glidetimer_"+subobj.id]);
			}, this.delaybeforehide
		)
	}
}

function effectObject(obj, direction)
{
	var elapsed=new Date().getTime()-obj.startTime
	if (elapsed<obj.glidetime){
		var distancepercent=(direction=="down")? this.curveincrement(elapsed/obj.glidetime) : 1-this.curveincrement(elapsed/obj.glidetime)
		var currentclip=(distancepercent*obj.contentheight)+"px"
		obj.style.clip=(direction=="down")? "rect(0 auto "+currentclip+" 0)" : "rect("+currentclip+" auto auto 0)"
		window["glidetimer_"+obj.id]=setTimeout(function(){effectObject(obj, direction)}, 10)
	}
	else
	{
		obj.style.clip="rect(0 auto auto 0)"
	}
}

function curveincrement(percent)
{
	return 0.1; 
}

function show(anchorobj, subobj, e)
{
	if (!this.isExisted(anchorobj, e) && subobj.style.visibility!="visible")
	{
		var horizontaloffset=(subobj.dropposition[0]=="left")? -(subobj.offsetWidth-anchorobj.offsetWidth) : -this.crashBalance(subobj,anchorobj)
		var verticaloffset=(subobj.dropposition[1]=="top")? -subobj.offsetHeight : anchorobj.offsetHeight
		subobj.style.left=this.getPosition(anchorobj, "offsetLeft") + horizontaloffset + "px"
		subobj.style.top=this.getPosition(anchorobj, "offsetTop")+verticaloffset+"px"
		subobj.style.clip=(subobj.dropposition[1]=="top")? "rect(auto auto auto 0)" : "rect(0 auto 0 0)"
		subobj.style.visibility="visible"
		subobj.startTime=new Date().getTime()
		subobj.contentheight=parseInt(subobj.offsetHeight)
		var layer=document.getElementById(this.subobj.id + "Layer");
		
		if(layer!=null)
		{
			layer.style.height = parseInt(this.subobj.offsetHeight) + "px";
			layer.style.width = parseInt(this.subobj.offsetWidth) + "px";
		}
				
		if (typeof window["hidetimer_"+subobj.id]!="undefined")
			clearTimeout(window["hidetimer_"+subobj.id])
		this.effectObject(subobj, (subobj.dropposition[1]=="top")? "up" : "down")
		anchorobj.className="on"
	}
}

function crashBalance(subobj,anchorobj)
{
	var parent = anchorobj.parentNode.parentNode;
	var subobjWidth = subobj.offsetWidth;
		
	if (parent != null && (this.getPosition(anchorobj, "offsetLeft") + subobjWidth) > (this.getPosition(parent, "offsetLeft")+parent.offsetWidth))
	{
		return (this.getPosition(anchorobj, "offsetLeft") + subobjWidth) - (this.getPosition(parent, "offsetLeft")+parent.offsetWidth);
	}
	else
	{
		return 0;
	}
}

function isExisted(m, e)
{
	var e=window.event || e
	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
	if (c==m)
		return true
	else
		return false
}

function getPosition(what, offsettype)
{
	return (what.offsetParent)? what[offsettype]+this.getPosition(what.offsetParent, offsettype) : what[offsettype]
}

menuObject.prototype.hide=hide;
menuObject.prototype.effectObject=effectObject;
menuObject.prototype.curveincrement=curveincrement;
menuObject.prototype.show=show;
menuObject.prototype.isExisted=isExisted;
menuObject.prototype.crashBalance=crashBalance;
menuObject.prototype.getPosition=getPosition;