/*########################
# 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 = 10;
var correctY = 50;

/**
 * ---------------------------------------------
 * 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)
{
	var x;
	var y;

	if (navigator.appName=="Microsoft Internet Explorer" || navigator.appName=="Opera")
	{
		x = window.event.x+9;
		y = window.event.y+50;
	}

	if (navigator.appName=="Netscape")
	{
		x = e.screenX+11;
		y = e.screenY-115;
	}

	x =  x + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	y =  y + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);

   tooltip = document.getElementById(tooltipId);
   if(tooltip != null)
   {
	   tooltip.style.top = (y - correctY) + 'px';
	   tooltip.style.left = (x + correctX) + 'px';
   }
}

// init the tooltip
var all = document.all ? document.all : document.getElementsByTagName('*');
function initTooltip()
{
	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)
			{
				if(document.all)
					elm.onmousemove = new Function('resetTooltipPosition()');
				else
					elm.addEventListener('mousemove', resetTooltipPosition, false);

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

