/********************************************************************
   Tooltop 1.1                                             2002-05-19

   Tooltip functions of IE 4 or higher, NS 4 and NS 6.

   // Markus Gemstad
   gemstad@hotmail.com
   http://www.gemstad.com (references, samples etc)
********************************************************************/


/** Settings *******************************************************/

var g_sImagePath    = "";   // The path to the space.gif image used in the tooltip html code
var g_iShowTipIn    = 0; // Delay (in milliseconds) before tooltip appears
var g_iHideTipIn    = 10000; // Delay (in milliseconds) before tooltip goes away
var g_iToolTipWidth = 150;  // Maximum width of the tooltip (in pixels)

// Don't touch these
var g_bIE            = (document.all);
var g_bNS4           = (document.layers);
var g_bNS6           = (!document.all && document.getElementById);
var g_sEventX        = (g_bNS4 || g_bNS6) ? "event.pageX" : "event.offsetX";
var g_sEventY        = (g_bNS4 || g_bNS6) ? "event.pageY" : "event.offsetY";
var g_iTipTimeOutID  = null;
var g_iShowTimeOutID = null;
var g_bShowing       = false;
/*******************************************************************/


// Call this one on mouseOver
function activateToolTip(iLeft, iTop, sTip)
{
   deActivateToolTip();
   setToolTip(sTip);
   var iTimeOut = (g_bShowing) ? 100 : g_iShowTipIn;
   if(g_bIE) // Fixes coordinates in IE
   {
      var oObj = event.srcElement.offsetParent;
      while(oObj.tagName != "BODY")
      {
         iLeft += oObj.offsetLeft;
         iTop  += oObj.offsetTop;
         oObj   = oObj.offsetParent;
      }
      iTop = iTop - document.all["divToolTip"].clientHeight
      if ((iLeft + document.all["divToolTip"].clientWidth) > (document.body.clientWidth + document.body.scrollLeft))
            iLeft = (document.body.clientWidth + document.body.scrollLeft) - document.all["divToolTip"].clientWidth;

      if (iTop < document.body.scrollTop)
            iTop = iTop + document.all["divToolTip"].clientHeight;

   }
   g_iTipTimeOutID = setTimeout("showToolTip("+iLeft+","+iTop+");", iTimeOut);
}

// Call this one on mouseOut
function hideToolTip()
{
   var oDiv = getDivRef("divToolTip");

   deActivateToolTip();
   g_iShowTimeOutID = setTimeout("g_bShowing=false;", 200);

   // Move out of screen
   if(g_bNS4)
   {
      oDiv.moveTo(-1000, -1000);
      oDiv.visibility = "hide";
   }
   else if(g_bIE || g_bNS6)
   {
      oDiv.style.left = -1000;
      oDiv.style.top  = -1000;
      oDiv.style.visibility = "hidden";
   }
}

function setToolTip(sTip)
{
   var oDiv    = getDivRef("divToolTip");
   var sHtml   = createToolTipHtml(sTip);

   if(g_bNS4)
   {
      oDiv.document.open();
      oDiv.document.writeln(sHtml);
      oDiv.document.close();
      // Fixes ns4 problem width width
      if(oDiv.clip.width > g_iToolTipWidth)
      {
         sHtml = createToolTipHtml(sTip, g_iToolTipWidth);
         oDiv.document.open();
         oDiv.document.writeln(sHtml);
         oDiv.document.close();
      }
   }
   else if(g_bIE || g_bNS6)
      oDiv.innerHTML   = sHtml;
}

function showToolTip(iLeft, iTop)
{
   var oDiv    = getDivRef("divToolTip");

   if(g_bNS4)
   {
      oDiv.moveTo(iLeft, iTop);
      oDiv.visibility = "show";
   }
   else if(g_bIE || g_bNS6)
   {
      oDiv.style.left  = iLeft;
      oDiv.style.top   = iTop;
      oDiv.style.visibility = "visible";
   }
   g_iTipTimeOutID = setTimeout("hideToolTip();", g_iHideTipIn);
   g_bShowing   = true;
}

function createToolTipHtml(sTip, iWidth)
{
   var sWidth  = (iWidth == null) ? "" : " width="+iWidth;
   var sWidth2 = (iWidth == null) ? "" : " width="+(iWidth-12);
   var sHtml   = "";

// rob ToolTip-a debeline 1  
   sHtml += "<table border=0 cellpadding=5 cellspacing=0" + sWidth + "><tr><td>";
   sHtml += "<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor=#000000 colspan=3><img src=\""+g_sImagePath+"space.gif\" width=2 height=1></td></tr>";
   sHtml += "<tr><td bgcolor=#000000 width=1><img SRC=\""+g_sImagePath+"space.gif\" width=1 height=13></td>";
   sHtml += "<td" + sWidth2 + ">" + sTip + "</TD>";   
   sHtml += "<td bgcolor=#000000 WIDTH=1><img src=\""+g_sImagePath+"space.gif\" width=1 height=13></td></tr>";
   sHtml += "<tr><td bgcolor=#000000 colspan=3><img SRC=\""+g_sImagePath+"space.gif\" width=2 height=1></td></tr></table>";
   sHtml += "</td></tr></table>";

// brez robu debeline 1    
// sHtml += "<table border=0 cellpadding=5 cellspacing=0 bgcolor=transparent" + sWidth + "><tr><td" + sWidth2 + ">";
// sHtml += sTip;
// sHtml += "</td></tr></table>";

   return sHtml;
}

function deActivateToolTip()
{
   if(g_iTipTimeOutID != null)
      clearInterval(g_iTipTimeOutID);
   if(g_iShowTimeOutID != null)
      clearInterval(g_iShowTimeOutID);
}

// Generic function to get reference to div
function getDivRef(sDiv)
{
   var oDiv = null;
   if(g_bNS4) // ns4
      oDiv = document.layers[sDiv];
   else if(g_bIE)
      oDiv = document.all(sDiv);
   else if(g_bNS6)
      oDiv = document.getElementById(sDiv);
   return oDiv;
}
