/*########################
# made by bretik Â© 2007  #
# www.bretik.com         #
# ICQ#113378073          #
########################*/

/**
 * -----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * bretik <bretik@gmail.com> wrote this file.  As long as you retain this notice
 * you can do whatever you want with this stuff. If we meet some day, and you
 * think this stuff is worth it, you can buy me a beer in return. bretik
 * -----------------------------------------------------------------------------
 */

/**
 * ------------------------------------------
 * HERE YOU CAN UPDATE ALL REQUIRED VARIABLES
 * ------------------------------------------
 */

// tooltipAll:
//    true - all elements with title atribute will be tooltipped
//         (excluding elemnts with css class set in var noToopltipClass)
//    false - only elements with css class set in var toopltipClass wil be tooltipped
var tooltipAll = true;

// Array of HTML tags on which the tooltip should displayed
//   if empty, tooltip is applied on all elements with title attribute
var tagArray = new Array(); // tooltip will be applied to all elements
//var tagArray = new Array('div', 'span', 'a', 'img'); // apply tooltip only to listed elements

// css class of tooltip div
var css = "tooltip";

// All elements with this css class will be tooltipped
var tooltipClass = "showtooltip";

// All elements with this css class won't be tooltipped
var noTooltipClass = "hidetooltip";

// tooltip div ID - no need to change if you're not using this ID anywhere else
var tooltipId = "bublina";

// maximal width of tooltip
var maxWidth = 300;

// prevents displaying original title implemented by browser
var resetTitle = true;

// possition correction
//    here, you can relatively correct position of tooltip
var correctX = 5;
var correctY = 25;

/**
 * ---------------------------------------------
 * IF YOU DON'T KNOW, WHAT'RE YOU DOING
 * BETTER NOT CHANGE ANYTHING UNDER THIS COMMENT
 * ---------------------------------------------
 */

var mouseX = 0;
var mouseY = 0;

// show tooltip onmouseover
function showTooltipDiv(text)
{
  // get or create div
  tooltip = document.getElementById(tooltipId);
  if(tooltip == null)
  {
     var tooltip = document.createElement('div');
    tooltip.setAttribute('id', tooltipId);
    document.body.appendChild(tooltip);
  }

  tooltip.innerHTML = text;
  tooltip.cssClass = css;
  tooltip.style.display = 'block';
  tooltip.style.position = 'absolute';

  if(tooltip.clientWidth > maxWidth)
  {
    tooltip.style.width = maxWidth + 'px';
    tooltip.style.overflow = 'hidden';
  }

  resetTooltipPosition();
}

// remove tooltip div onmouseout
function hideTooltipDiv()
{
  tooltipDiv = document.getElementById(tooltipId);
  if(tooltipDiv != null)
  {
     tooltip.style.display = 'none';
    tooltip.style.width = '';
  }
}

// re-set tooltip posistion
function resetTooltipPosition(e)
{
  change = false;

  if(e != null && e != 'undefined')
  {
    mousex = e.pageX;
    mousey = e.pageY;
    change = true;
  }
  else if(typeof(window["event"]) != "undefined")
  {
    mousex = event.clientX + document.body.scrollLeft;
    mousey = event.clientY + document.body.scrollTop;
    change = true;
  }

  if(change && typeof(window["tooltipId"]) != "undefined")
  {
     tooltip = document.getElementById(tooltipId);
     if(tooltip != null)
     {
       tooltip.style.top = (mousey - correctY) + 'px';
       tooltip.style.left = (mousex + correctX) + 'px';
     }
   }
}

// set tooltips
var all = document.all ? document.all : document.getElementsByTagName('*');
function setTooltip()
{
  for (e = 0; e < all.length; e++)
  {
    elm = all[e];

    if(elm != null && elm.title != null && typeof(elm.title) != 'undefined' && elm.title != "")
    {
       showTooltip = tooltipAll;
      //alert(elm.tagName + " (" + elm.childNodes.length + ") - has title");
      // element name
      tagArrayLength = tagArray.length;
      if(tagArrayLength > 0)
    	{
        showTooltip = false;
         for(i = 0; i < tagArrayLength; i++)
         {
           if(elm.tagName.toLowerCase() == tagArray[i].toLowerCase())
         	{
            showTooltip = true;
        		}
      	}
    	}

       // element css class
      className = "";
      if(elm.className != null)
        className = elm.className;

      if(className.indexOf(noTooltipClass) >= 0)
         showTooltip = false;
      if(className.indexOf(tooltipClass) >= 0)
         showTooltip = true;

      // add actions
      if(showTooltip)
    	{
         elm.onmouseover = new Function("showTooltipDiv('" + elm.title + "')");
         elm.onmouseout = new Function('hideTooltipDiv()');
        if(resetTitle)
          elm.setAttribute("title", "");
    	}
    }
  }
}

// init the tooltip
function initTooltip()
{
  // mousemove listener
  if(document.all)
    document.body.onmousemove = new Function('resetTooltipPosition()');
  else
    document.body.addEventListener('mousemove', resetTooltipPosition, false);

  setTooltip();
}

