/*==================================================================================================

FILE : /rsc/js/tooltips.js

CREATED : 20 December 2003

LAST MODIFIED : 20 August 2004

AUTHOR : Warren Hedley

DESCRIPTION : The showTooltip() and hideTooltip() functions can be used in mouseover and mouseout
  event handlers on an event to associate a "tooltip" with it, that appears when the user moves
  the mouse over the element. This is useful for hiding information in a page and making it
  available to the user interactively. This was tested with all of the most popular browser and
  operating systems combinations and seems to work well as of December 2003. The tooltip is placed
  on the side of the cursor that points towards the center of the browser window, increasing the
  likelihood that the entirety of the tooltip will be visible (although this doesn't work in
  Safari, which doesn't seem to make the window width available).

  If updates are required, a good place to start looking is http://www.quirksmode.org/.

  Parts of the script were originally taken from http://home.cogeco.ca/~ve3ll/jspop.htm .

  As of August 2004, support for Netscape 4 has been discontinued. We have to jump through a few
  hoops to get IE 5.0 and IE 5.2 on the Mac working properly (that's why there are 2 <div>
  elements). Opera 6 doesn't seem to work, but things are find in Opera 7.

==================================================================================================*/

var overTooltip = "0";
var tcx = -1, tcy = -1;
var ttDebugConsole = null;

function ttDebug(msg)
{
  if (false) // set to true to enable debugging
  {
    if ((ttDebugConsole == null) || (ttDebugConsole.closed))
    {
      ttDebugConsole = window.open("", "console", "width=600,height=300,resizable");
      ttDebugConsole.document.open("text/plain");
    }
    ttDebugConsole.document.writeln(msg + "<br />\n");
  }
}

function showTooltip(text)
{
  if (false)
  {
    ttDebug('showTooltip(' + text + ')');
    ttDebug('mouse at ' + tcx + ',' + tcy);
    ttDebug('document.width = ' + document.width + ', window.width = ' + window.width +
        ', document.body.offsetWidth = ' + (document.body ? document.body.offsetWidth : "n/a") +
        ', document.body.clientWidth = ' + (document.body ? document.body.clientWidth : "n/a"));
  }

  var screenCenter = (document.width == null ? document.body.clientWidth : document.width) / 2;
  var toolTipX = tcx < screenCenter ? tcx + 15 : tcx - 15 - 400;
  var toolTipY = tcy - 5;

  if (!document.layers) // Netscape 4 is no longer supported
  {
    var tooltip = document.getElementById("tooltip");
    tooltip.innerHTML = text;
    var tooltipContainer = document.getElementById("tooltipContainer");
    tooltipContainer.style.left = toolTipX + 'px';
    tooltipContainer.style.top = toolTipY + 'px';
    ttDebug('DOM: tooltip at ' + tooltipContainer.style.left + ',' + tooltipContainer.style.top);
  }
}

function hideTooltip()
{
  ttDebug('hideTooltip()');
  if (overTooltip == "0")
  {
    if (!document.layers) // Netscape 4 is no longer supported
    {
      var tooltipContainer = document.getElementById("tooltipContainer");
      tooltipContainer.style.top = "-1000px";
      tooltipContainer.style.left = "-1000px";
    }
  }
}

// Thanks to http://www.quirksmode.org/ for the following.

function mouseMoveHandler(evt)
{
  if (!evt) var evt = window.event;
  if (evt.pageX || evt.pageY)
  {
    tcx = evt.pageX;
    tcy = evt.pageY;
    // window.status = 'page: ' + tcx + ':' + tcy;
  }
  else if (evt.clientX || evt.clientY)
  {
    // IE sometimes gets an "object required" error when the page loads without
    // this check (body element not created yet?)
    if(document.body)
    {
      tcx = evt.clientX + document.body.scrollLeft;
      tcy = evt.clientY + document.body.scrollTop;
    }
    // window.status = 'client: ' + tcx + ':' + tcy;
  }
  else
  {
    // window.status = 'Error: unable to process mouse position';
  }
}

if (document.all)
  document.onmousemove = mouseMoveHandler;
if (document.addEventListener)
  document.addEventListener('mousemove', mouseMoveHandler, true);
