//Copyright 2007 Last Mile Synergy, LLC
//All rights reserved. Republication or redistribution of content is prohibited
//without the prior written consent of Last Mile Synergy, LLC.

document.write('<div id="tooltip" z-index="100" style="position:absolute;"></div>');

var ie = document.all;
var firefox = document.getElementById && !document.all;
var enable_tooltip = false;
var tooltip_object = document.all["tooltip"];
var offsetX = 12; // x offset of tooltip
var offsetY = 22; // y offset of tooltip

function showtooltip(tooltip_text, tooltip_width, tooltip_color) {
  if (typeof tooltip_width!="undefined") document.all["tooltip"].style.width=tooltip_width+"px";
  if (typeof tooltip_color!="undefined" && tooltip_color!="") document.all["tooltip"].style.backgroundColor=tooltip_color;
  document.all["tooltip"].innerHTML=tooltip_text;
  enable_tooltip=true;
  return false;
}

function position_tooltip(e) {
  if (enable_tooltip){
    var nondefaultpos=false;
    var curX= (firefox) ? e.pageX : event.clientX+document.body.scrollLeft;
    var curY= (firefox) ? e.pageY : event.clientY+document.body.scrollTop;
    //how close is the mouse to the corner of the window
    var winwidth= (ie) ? document.body.clientWidth : window.innerWidth-20;
    var winheight= (ie) ? document.body.clientHeight : window.innerHeight-20;
    var rightedge= (ie) ? winwidth-event.clientX-offsetX : winwidth-e.pageX-offsetX-20;
    var bottomedge= (ie) ? winheight-event.clientY-offsetY : winheight-e.pageY-offsetY-20;
    var leftedge=(offsetX<0) ? offsetX*(-1) : -1000;

    //will the box fit the distance between the cursor and the edge of the screen
    if (rightedge<document.all["tooltip"].offsetWidth) {
      //move the horizontal position of the menu to the left by it's width
      document.all["tooltip"].style.left=curX-document.all["tooltip"].offsetWidth+"px";
      nondefaultpos=true;
    }
      else if (curX<leftedge)
        document.all["tooltip"].style.left="5px";
      else {
        //position offsetX of the menu where the mouse is positioned
	document.all["tooltip"].style.left=curX+offsetX+"px";
    }

    //will the box fit the distance between the cursor and the bottom of the screen
    if (bottomedge<document.all["tooltip"].offsetHeight) {
      document.all["tooltip"].style.top=curY-document.all["tooltip"].offsetHeight-offsetY+"px";
      nondefaultpos=true;
    }
      else{
        document.all["tooltip"].style.top=curY+offsetY+"px";
    }
    document.all["tooltip"].style.visibility="visible";
  }
}

function hidetooltip() {
  enable_tooltip=false;
  document.all["tooltip"].style.visibility="hidden";
  document.all["tooltip"].style.left="0px";
  document.all["tooltip"].style.backgroundColor='';
  document.all["tooltip"].style.width='0px';
}

document.onmousemove=position_tooltip;
