// Balloons
// By Mark Morley (mark@islandnet.com)
//
// Implements pop-up help "balloons" on when the mouse pointer moves over
// certain objects.
//
// SETTINGS:   xoff/yoff - the X,Y location of the top left corner of the
//                         balloon, relative to the mouse pointer.
//
//             showdelay - The length of time to wait before actually
//                         displaying the balloon.  1=250 ms, 4=1 s, etc.
//
//             hidedelay - The length of time to wait before hiding the
//                         balloon.  1=250 ms, 4=1 s, etc.
//
//             top       - The HTML code that forms the 'top' portion of
//                         the balloon contents.
//
//             bottom    - The HTML code that forms the 'bottom' portion of
//                         the balloon contents.

var xoff = 20;
var yoff = 0;
var showdelay = 4;
var hidedelay = 1;
var top = "<table border=1 cellspacing=0 cellpadding=0><tr bgcolor=FFFFFF><td align=center>"
var bottom = "</td></tr></table>";
var xtrack = 0
var ytrack = 0
// Nothing below here should need to be changed

var tick = 0;
var showing = false;
var nn = false;
var ie = false;
var ver = 0;
if( document.layers )
   nn = true;
else if( document.all )
{
   ie = true;
   if( navigator.appVersion.indexOf( "MSIE 5" ) >= 0 )
      ver = 5;
   else if( navigator.appVersion.indexOf( "MSIE 4" ) >= 0 )
      ver = 4;
}

document.onmousemove = trackmouse;
if( nn )
   document.captureEvents( Event.MOUSEMOVE );

function trackmouse( e )
{
   var x = 0;
   var y = 0;

   if( nn )
   {
      x = e.pageX;
      y = e.pageY;
   }
   else if( ie )
   {
      x = event.x;
      y = event.y;
      if( ver >= 5 )
      {
         x += document.body.scrollLeft;
         y += document.body.scrollTop;
      }
   }
   x += xoff;
   y += yoff;
	xtrack = x;
   ytrack = y;
  // if( nn )
  // {
  //    document.balloon.left = x;
  //    document.balloon.top = y;
  // }
  // else if( ie )
   //{
  //   balloon.style.left = x;
   //   balloon.style.top = y;
  // }
}

function timer( t )
{
   if( t > 0 )
      tick = t;
   if( tick > 0 )
   {
      tick--;
      if( tick == 0 )
      {
         if( nn )
            document.balloon.visibility = showing ? "show" : "hide";
         else if( ie )
            balloon.style.visibility = showing ? "visible" : "hidden";
      }
      setTimeout( "timer()", 250 );
   }
}

function showballoon( width, height,data )
{
   showing = true;
  if( nn )
   {
      document.balloon.left = xtrack;
      document.balloon.top = ytrack;
   }
  // else if( ie )
  // {
  //    balloon.style.left = x;
   //   balloon.style.top = y;
   //}
   
   if( nn )
   {
      document.balloon.document.write( top + data + bottom );
      document.balloon.document.close();
      if( showdelay > 0 )
         timer( showdelay );
      else
         document.balloon.visibility = "show";
   }
   else if( ie )
   {
		//alert(xtrack + "\n" + ytrack + "\n" + document.all("balloon").style.pixelLeft + " // " + balloon.style.pixelTop);
      document.all("balloon").posWidth = width;
	  document.all("balloon").posHeight = height;	
	  document.all("balloon").innerHTML = top + data + bottom;
	  if ((document.all("balloon").posWidth + xtrack) < document.body.clientWidth)
 	  		balloon.style.posLeft = xtrack;
	  else
	  		balloon.style.posLeft = (xtrack - xoff - document.all("balloon").posWidth);
	  if ((document.all("balloon").posHeight + ytrack) < document.body.clientHeight)
	        balloon.style.posTop = ytrack;
	  else
	  		balloon.style.posTop = (ytrack - yoff - document.all("balloon").posHeight);
      if( showdelay > 0 )
         timer( showdelay );
      else
         balloon.style.visibility = "visible";
	//	 alert(document.body.clientWidth + " // " + document.body.clientHeight);
	//alert( (xtrack-xoff) + " // " + ytrack + "\n" + balloon.style.posLeft + " // " + balloon.style.posTop + "\n" + width + " // " + height)
   }
}

function hideballoon()
{
   showing = false;
   if( hidedelay )
      timer( hidedelay );
   else
   {
      tick = 0;
      if( nn )
         document.balloon.visibility = "hide";
      else if( ie )
         balloon.style.visibility = "hidden";
   }
}

if( nn )
   document.balloon.visibility = "hide";
else if( ie )
   balloon.style.visibility = "hidden";


