var Direction = 'down'
var link = new Array()
var Current = null
var timer = null
var delay = 500
var opacitytimer = null
var opacitytimerstart = false
var opacitytimedelay= 20
function StopTimer()
{    if (timer!=null)
    {
      	clearTimeout(timer)
		timer = null;
	}
}
function TimerToHide(table)
{

	clearTimeout(timer)
	timer  = setTimeout("HideAll()", delay)
}
function HideAll()
{	if (link==null) return
	for(i=0;i<link.length;i++)
	{
		aid = link[i].id.split('_')
       	var table = document.getElementById(aid[1])
    	if (table == null) continue
		table.style.left = 0;
		table.style.top = 0;
        table.style.display = 'none'
		table.style.opacity=0.0
        if (table.filters!=null)
				table.filters(0).opacity=0.0

	}
	link = new Array();
}
function RemoveAfter(id)
{	has = false;
	link2 = new Array()
	for(i=0;i<link.length;i++)
	{
			if(link[i].id == id.id)
			{
				 has=true
				 continue
			}
			if (has)
			{
				aid = link[i].id.split('_')
            	var table = document.getElementById(aid[1])
       			if (table == null) continue
                table.style.display = 'none'
			}
	}
}
function ContainsInLink(id)
{	has = false;
	if (link==null) return
	for(i=0;i<link.length;i++)
			if(link[i].id == id.id)
				 has=true
  return has;
}
function Hide(parent)
{	if(parent==-1)
		HideAll();
}
function RemoveLast()
{
			if(link[link.length-1]==null) return
			aid = link[link.length-1].id.split('_')
           	var table = document.getElementById(aid[1])

            table.style.display = 'none'
}
function SetFrom(linkfrom)
{	if (linkfrom!=null)
		Current = linkfrom
}
function ShowTimer(id)
{	var table = document.getElementById(id)
    if (table.filters!=null)
    {		if (parseFloat (table.filters(0).opacity)+10>=100) opacitytimerstart=false
		table.filters(0).opacity=parseFloat (table.filters(0).opacity)+15
    }
	else
	{

		if (parseFloat (table.style.opacity)+0.1>=1) opacitytimerstart=false
		table.style.opacity= parseFloat (table.style.opacity)+0.1
	}

	if (opacitytimerstart)
		opacitytimer = setTimeout("ShowTimer("+id+")",opacitytimedelay)
}
function Open(from, id)
{	var table = document.getElementById(id)
	var div = document.getElementById('debug')
	StopTimer()

    if (link==null) link = new Array()
    if (!ContainsInLink(from))
      	  	link[link.length] = from
		if (Current!=null)
		{
            if (from.offsetParent.offsetParent.id == Current.offsetParent.offsetParent.id)
			{					a = Current.id.split('_')
			   	 	var tablefrom = document.getElementById(a[1])
        	     	if (tablefrom != null)
        	     	{        	     		  if (tablefrom.filters!=null)
			    				tablefrom.filters(0).opacity=0
    					  else
    							tablefrom.style.opacity=0.0
                          tablefrom.style.display='none'
        	     	}
				}
		}

    RemoveAfter(from)
	if (from == null || table==null) return
	table.style.display=''
	var point = getPosition(from);
  	if (link.length>1)
   	{
		if (point["left"]>512)
			direction_ = "left"
		else
			direction_ = "right"
   	}
   	else
   		direction_ = Direction

   if (direction_=="left")
	{	table.style.left = point["left"]  - table.offsetWidth-7;
		table.style.top = point["top"]-4;
	}
   	if (direction_=="right")
	{
		table.style.left = point["left"] +  from.offsetParent.offsetWidth;
		table.style.top = point["top"]-4;
	}
	if (direction_=="down")
	{
		table.style.left = point["left"];
		table.style.top = point["top"]+from.offsetHeight+2;
	}
	opacitytimerstart = true;
   	opacitytimer = setTimeout("ShowTimer("+id+")",opacitytimedelay)


}
function findPosY(obj)
{
    var curtop = 0;
    while (obj.offsetParent)
    {
        curtop += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return curtop;
}
function getPosition(obj)
{ var left=document.body.scrollLeft,top=document.body.scrollTop; while(obj)
{ left+=obj.offsetLeft-obj.scrollLeft;
top+=obj.offsetTop-obj.scrollTop;
if(obj.style.borderTopWidth!='')
top+=parseInt(obj.style.borderTopWidth);
if(obj.style.borderLeftWidth!='')
left+=parseInt(obj.style.borderLeftWidth);
obj=obj.offsetParent; }
return {left:left,top:top};
}
