function TIP_BOX()
{
  this.text = '';
  this.obj = 0;
  this.objstyle = 0;
  this.active = false;
  
  //appearance of the tip box
  this.bgColor = '#F8DFAE';
  this.fontColor = '#05930C';
  this.borderColor = '#05930C';
  this.cursorDistance = 10;
  this.fontSize = '12px';

  this.init = function()
  {
    this.obj = getElement('Tip_Box');
    if(document.layers)
      this.objstyle = this.obj;
    else 
      this.objstyle = this.obj.style;
      
  }

  this.create = function()
  {
    if(!this.obj) this.init();

    if(document.layers)
    {
      this.obj.document.write(this.text);
      this.obj.document.close();
    }
    else
    {
      this.obj.innerHTML = this.text;
    }

    this.objstyle.color = this.fontColor;
    this.objstyle.border = '1px solid ' + this.borderColor;
    this.objstyle.padding = '2px';
    this.objstyle.backgroundColor = this.bgColor;
    this.objstyle.fontSize = this.fontSize;

    this.show();
  }

  this.show = function()
  {
    var ext = (document.layers ? '' : 'px');
    var left = mouseX;

    if(left + this.cursorDistance > winX)
      left -= this.cursorDistance;
    else
      left += this.cursorDistance;

    this.objstyle.left = left + ext;
    this.objstyle.top = mouseY + this.cursorDistance + ext;

    if(!this.active)
    {
      this.objstyle.visibility = 'visible';
      this.active = true;
    }
  }

  this.hide = function()
  {
    if(this.objstyle)
      this.objstyle.visibility = 'hidden';
    this.active = false;
  }
}

var tipbox = 0;
var mouseX = 0;
var mouseY = 0;
var winX = 0;

if(document.layers)
{
  document.write('<layer id="Tip_Box"></layer>');
  document.captureEvents(Event.MOUSEMOVE);
}
else
  document.write('<div id="Tip_Box" style="position:absolute; z-index:99"></div>');

document.onmousemove = getMousePosition;

function getMousePosition(e)
{
  if (!e) var e = window.event;
  if (e.pageX || e.pageY)
	{
		mouseX = e.pageX;
    mouseY = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
	}

  if(document.body && document.body.offsetWidth)
    winX = document.body.offsetWidth - 25;
  else if(window.innerWidth)
    winX = window.innerWidth - 25;
  else
    winX = screen.width - 25;

  if(tipbox && tipbox.active) tipbox.show();
}

function tip_box(text)
{
  if(text)
  {
    tipbox = new TIP_BOX();
    tipbox.text = text;
    tipbox.create();
  }
  else if(tipbox)
    tipbox.hide();
}

function getElement(id)
{
  if(document.all)
    return document.all[id];
  else if(document.layers)
    return document.Tip_Box;
  else
    return document.getElementById(id);
}
