// @(#) $Id: menu.js,v 1.1 2004/09/20 14:53:27 tom Exp $

//--------------------------------------------------------------------
// TopMenu

function PopUpMenu(pid,id,dir)
{
var obj,pobj,width,height,x0,y0;
	obj=document.getElementById(id);
	if(this.quickpopup)
	{
//		if(obj && obj.offsetLeft!=-2000)
		if(obj && obj.offsetTop!=-2000)
		{
			PopDownMenu(id);
			return;
		}
	}
	robj=pobj=document.getElementById(pid);
	dx=dy=0;
	while(robj.offsetParent)
	{
		if(robj.style.position=="absolute")
			break;
		dx+=robj.offsetLeft;
		dy+=robj.offsetTop;
		robj=robj.offsetParent;
	}
	if(obj && pobj)
	{
		x0=robj.offsetLeft+dx;
		y0=robj.offsetTop+dy;
		height=pobj.offsetHeight;
		width=pobj.offsetWidth

		switch(dir)
		{
			case 3: //MENU_RIGHT_DOWN:
				x=x0+width-this.xshift-1;
				y=y0+this.yshift;
				break;
			case 2: //MENU_RIGHT_UP:
				x=x0+width-this.xshift-1;
				y=y0+height-obj.offsetHeight-this.yshift+1;
				break;
			case 1: //MENU_LEFT_DOWN:
				x=x0-obj.offsetWidth+this.xshift+1;
				y=y0-this.yshift;
				break;
			case 0: //MENU_LEFT_UP:
				x=x0-obj.offsetWidth+this.xshift+1;
				y=y0+height-obj.offsetHeight-this.yshift+1;
				break;
			case 7: //MENU_BOTTOM_RIGHT:
				x=x0;
				y=y0+height;
				break;
			case 6: //MENU_BOTTOM_LEFT:
				x=x0+width-obj.offsetWidth;
				y=y0+height;
				break;
			case 5: //MENU_TOP_RIGHT:
				x=x0;
				y=y0-obj.offsetHeight;
				break;
			case 4: //MENU_TOP_LEFT:
				x=x0+width-obj.offsetWidth;
				y=y0-obj.offsetHeight;
				break;
			default:
				x=0; y=0;
				break;
		}
		this.ClosePanes(pid);
		this.active_menu[this.menulevel++]=id;
		obj.style.left=x+"px";
		obj.style.top=y+"px";
	}
}


function ClosePanes(mb)
{
var i,pane;
	pane=this.mbparents[mb];
	if(pane)
	{
		for(i=this.active_menu.length-1;i>=0;i--)
			if(this.active_menu[i]==pane)
			{
				this.PopDownMenu(this.active_menu[i+1]);
				break;
			}
	}
}


function PopDownMenu(id)
{
var obj,i,nlevel,del;
	del=0;
	nlevel=this.menulevel;
	for(i=0;i<this.menulevel;i++)
	{
		if(this.active_menu[i]==id)
		{
			del=1;
			nlevel=i;
		}
		if(del)
		{
			obj=document.getElementById(this.active_menu[i]);
			if(obj)
			{
				obj.style.top=-2000+"px";
//				obj.style.top=0+"px";
			}
		}
	}
	this.menulevel=nlevel;
}


function PopDownAllMenu()
{
	if(this.menulevel>0)
		this.PopDownMenu(this.active_menu[this.topidx]);
}


function setActiveMenu(id)
{
	this.active_menu[0]=id;
}


function PreparePopDownAllMenu()
{
	this.tid=window.setTimeout(this.name+".PopDownAllMenu()",100);
}
function UnPreparePopDownAllMenu()
{
	window.clearTimeout(this.tid);
}


function TopMenu(name,quickpopup,xshift,yshift)
{
	this.name=name;
	this.topidx=1; // 1=topmenu, 0=menu
	this.menulevel=this.topidx;
	this.quickpopup=quickpopup;
	this.xshift=xshift;
	this.yshift=yshift;
	this.mbparents=new Array();
	this.active_menu=new Array();
	this.tid=0;
	this.ClosePanes=ClosePanes;
	this.PopDownMenu=PopDownMenu;
	this.PopDownAllMenu=PopDownAllMenu;
	this.PopUpMenu=PopUpMenu;
	this.setActiveMenu=setActiveMenu;
	this.PreparePopDownAllMenu=PreparePopDownAllMenu;
	this.UnPreparePopDownAllMenu=UnPreparePopDownAllMenu;
}

//--------------------------------------------------------------------



