// global vars
var object = null;
var mouseX, mouseY;

/**
 * Get the current position of the mouse.
 * @param event Mouse event.
 */
function pos (event)
{
  // grab the event
  if (!event)
    var event = window.event || window.Event;

  // get the mouse position
  if ('undefined' != typeof event.pageX)
  {
    mouseX = event.pageX;
    mouseY = event.pageY;
  }
  else
  {
    mouseX = event.clientX+document.body.scrollLeft;
    mouseY = event.clientY+document.body.scrollTop;
  }
}

// tell mozilla to start listening
if (window.Event && document.captureEvents)
  document.captureEvents (Event.MOUSEMOVE);

// assign the mouse handler
document.onmousemove = pos;

/**
 * Move the current active tooltip.
 */
function move ()
{
  if (object != null)
  {
    object.style.top        = mouseY+"px";
    object.style.left       = mouseX+15+"px";
    object.style.visibility = "visible";
  }
}

/**
 * Update the tooltip contents.
 * @param tooltip Name of the tooltip. Null to hide the current active tooltip.
 * @param heading The heading of the tooltip.
 * @param content Tooltip content.
 */
function update (tooltip, heading, content)
{
  // hide the tooltip
  if (tooltip == null)
  {
    if (object != null)
    {
      object.style.visibility = "hidden";
      object = null;
    }
    return;
  }

  // hide the previous tooltip
  if (object != null)
    object.style.visibility = "hidden";

  // show the tooltip
  object = document.getElementById (tooltip);
  if (object != null)
  {
    object.style.visibility = "hidden";
    object.innerHTML = '<TABLE CLASS="trans" BORDER="0" CELLSPACING="2" CELLPADDING="0" WIDTH="150">'+
                       '<TR><TD>'+
                       '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">'+
                       '<TR><TD CLASS="tooltiptitle">'+heading+'</TD></TR>'+
                       '</TABLE>'+
                       '</TD></TR>'+
                       '<TR><TD>'+
                       '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">'+
                       '<TR><TD CLASS="tooltipcontent">'+content+'</TD></TR>'+
                       '</TABLE>'+
                       '</TD></TR>'+
                       '</TABLE>';

  }
}

