// TOOLTIP.JS   Copyright (c) 2004-2005 Rene Durik
var ttId = null;
var ttTimer = 0;
var ttStart;

function tooltipClearTimer()
{
  if (ttTimer)
  {
    clearTimeout(ttTimer);
    ttTimer = 0;
  }
}

function tooltipDisplay(id)
{
  if (ttTimer)
	clearTimeout(ttTimer);
	
  var e = getEvent();
  var x = mouseX(e);
  var y = mouseY(e);

  var vw = getViewWidth();
  var vh = getViewHeight();
  var vx = getScrollX();
  var vy = getScrollY();

  var tt = getById(id);
  var w = getObjWidth(tt);
  var h = getObjHeight(tt);
  if (x + w + 8 > vw + vx)
  {
    x = x - w - 8;
    if (x < 0)
      x = 0;
  }
  else
    x = x + 8;
  if (y + h + 12 > vh + vy)
  {
    y = y - h - 12;
    if (y < vy)
      y = vh + vy - h;
  }
  else
    y = y + 12;
	
  if (ttId == id)
  {
    setObjX(tt, x);
    setObjY(tt, y); 
    
    var w = getObjWidth(tt);
    var h = getObjHeight(tt);
	tt.style.clip = "rect(0px," + w + "px, " + h + "px,0px)";
  }
  else
  {
    if (ttId)
    {
      ott = getById(ttId);
      hideObj(ott);
    }

    setObjX(tt, x);
    setObjY(tt, y);      
	tt.style.clip = "rect(0px 0px 0px 0px)";    showObj(tt);

    ttId = id;
    ttTimer = setTimeout("tooltipShow()", 100);
  }
}

function infoDisplay(id)
{
  var vw = getViewWidth();
  var vh = getViewHeight();
  var vx = getScrollX();
  var vy = getScrollY();

  var tt = getById(id);
  var w = getObjWidth(tt);
  var h = getObjHeight(tt);
	
  setObjX(tt, vw - 325);
  setObjY(tt, 5); 
  tt.style.clip = "rect(0px 0px 0px 0px)";  showObj(tt);

  ttId = id;
  ttTimer = setTimeout("tooltipShow()", 100);
}

function tooltipKill(t)
{
  if (ttTimer)
	clearTimeout(ttTimer);
  ttTimer = setTimeout("tooltipHide()", t);
}

function tooltipShow()
{
  clearTimeout(ttTimer);

  ttStart = (new Date()).getTime();
  ttTimer = setTimeout("tooltipRollout()", 10);
}

function tooltipRollout()
{
  clearTimeout(ttTimer);

  var tt = getById(ttId);
  var w = getObjWidth(tt);
  var h = getObjHeight(tt);
  var e = 300 - (new Date()).getTime() + ttStart;
  if (e > 0)
  {
    var cw = w - Math.round( e * e * w / 90000 );
    var ch = h - Math.round( e * e * h / 90000 );
    tt.style.clip = "rect(0px," + cw + "px," + ch + "px,0px)";
    ttTimer = setTimeout("tooltipRollout()", 10);    
  }
  else
  {
	tt.style.clip = "rect(0px," + w + "px, " + h + "px,0px)";
  }
}

function tooltipHide()
{
  clearTimeout(ttTimer);

  ttStart = (new Date()).getTime();
  ttTimer = setTimeout("tooltipRollup()", 10);
}

function tooltipRollup()
{
  clearTimeout(ttTimer);

  var tt = getById(ttId);
  var w = getObjWidth(tt);
  var h = getObjHeight(tt);
  var e = 200 - (new Date()).getTime() + ttStart;
  if (e > 0)
  {
    var cw = Math.round( e * e * w / 40000 );
    var ch = Math.round( e * e * h / 40000 );
    tt.style.clip = "rect(0px," + cw + "px, " + ch + "px,0px)";
    ttTimer = setTimeout("tooltipRollup()", 10);    
  }
  else
  {
	tt.style.clip = "rect(0px,0px, " + h + "px,0px)";
	ttId = null
  }
}

