function getCoords(id)
{
	var anObj = document.getElementById(id)
	var objRes = new Object();
	
	objRes.left = 0;
	objRes.top = 0;
	objRes.width = 0;
	objRes.height = 0;
	
	objRes.width+=anObj.offsetWidth;
	objRes.height+=anObj.offsetHeight;

	for(var i = anObj; i != null; i = i.offsetParent){
		objRes.left += parseInt(i.offsetLeft);
		objRes.top += parseInt(i.offsetTop);
	}
	
	return objRes;
}
/* menu action  start */
/* menuitem class defenition start */
function itemdelay(s,t){
		if(this.timer!=-1){
				clearTimeout(this.timer);
				this.timer=-1;
		}
		this.timer=setTimeout(s,t);
}
function itemcanceldelay(){
	if(this.timer!=-1){
		clearTimeout(this.timer);
		this.timer=-1;
	}
}
function itemopen(){
	if(this.open)
		return 0;
	if(this.hid){
		this.hid=false;
		this.speed=0;
		this.accel=this.saccel;
		this.cy=0;
		this.Draw();
		this.obj.style.display="block";
	}else if(this.accel<0){
		this.accel=-this.accel;
	}
}
function itemhide(){
	if(this.hid)
		return 0;
	if(this.op){
		this.op=false;
		this.speed=0;
		this.accel=-this.saccel;
	}else if(this.accel>0){
		this.accel=-this.accel;
	}
}
function itemdraw(){
	this.obj.style.top=this.cy-this.h+this.y-35+'px';
}
function itemgo(){
	if(this.hid || this.op)
		return 0;
	this.speed+=this.accel;
	this.cy+=this.speed;
	if(this.cy<1){
		this.hid=true;
		this.cy=0;
		this.obj.style.display="none";
	}else if(this.cy>this.h){
		this.cy=this.h;
		this.op=true;
	}
	this.Draw();
}
function iteminit(x,y){
	this.obj.style.display="block";
	var o=getCoords(this.id);
	this.obj.style.display="none";
	this.h=o.height+35;
	this.x=x;
	this.y=y;
	this.obj.style.left=x+'px';
	this.Draw();
}
function itemdopen(){
	this.Delay("popup.ary['"+this.id+"'].Open()",150);
}
function itemdhide(){
	this.Delay("popup.ary['"+this.id+"'].Hide()",750);
}
function popupitem(n,id){
	this.timer=-1;
	this.saccel=1;
	this.n=n;
	this.x=0;
	this.y=0;
	this.id=id;
	this.cy=0;
	this.speed=0;
	this.accel=0;
	this.hid=true;
	this.op=false;
	this.to=0;
	this.h=0;
	this.obj=document.getElementById(id);
	this.Open=itemopen;
	this.Hide=itemhide;
	this.dOpen=itemdopen;
	this.dHide=itemdhide;
	this.Init=iteminit;
	this.Go=itemgo;
	this.Draw=itemdraw;
	this.Delay=itemdelay;
	this.Cancel=itemcanceldelay;
}
/* menuitem class defenition end */
/*  popup class defenition  start*/
function additem(n,id){
	this.ary[id]=new popupitem(n,id);
}
function popupinit(x,y){
	this.x=x;
	this.y=y;
	for(var i in this.ary){
		this.ary[i].Init(this.x+this.w*this.ary[i].n,this.y);
	}
}
function popupgo(){
	for(var i in this.ary){
		this.ary[i].Go();
	}
}
function popuphide(id){
	this.ary[id].dHide();
//	for(var i in this.ary)
/*		if(i!=id){
			this.ary[i].Cancel();
			this.ary[i].Hide();
		}else
			this.ary[i].dHide();
*/}
function popupopen(id){
	for(var i in this.ary){
		if(this.ary[i].id==id)
			this.ary[i].dOpen();
		else
			this.ary[i].dHide();
	}
}
function popupget(id){
	return this.list[id];
}
function popupmenu(w){
	this.x=0;
	this.y=0;
	this.w=w;
	this.ary=new Array();
	this.Add=additem;
	this.Init=popupinit;
	this.Go=popupgo;
	this.Open=popupopen;
	this.Hide=popuphide;
	this.Get=popupget;
}
/*  popup class defenition end */
/*  menu action  end */

var popup;
function mtrace(){
	popup.Go();
	setTimeout("mtrace()",10);
}
/* global method   */
function mcreate(w){
	popup=new popupmenu(w);
}
// use in body OnLoad
function mstart(id){
	var p=getCoords(id);
	popup.Init(p.left,p.top+p.height);
	mtrace();
}
// use for open
function mopen(id){
	popup.Open(id);
	
	var els = document.getElementsByTagName('select');
	
	for (var i = 0; i < els.length; ++i)
	{
		els[i].style.visibility = 'hidden';
	}
	
}
// use for close
function mhide(id){
	popup.Hide(id);
	
	var els = document.getElementsByTagName('select');
	
	for (var i = 0; i < els.length; ++i)
	{
		els[i].style.visibility = 'visible';
	}
}
// use for adding
function madd(n,id){
	popup.Add(n,id);
	document.writeln("<div style='width:"+popup.w+"px; height:35px;'><img src='pics/empty.gif' style='width:"+popup.w+"px; height:35px;' /></div>");
}

