﻿function Tooltip()
{
	this.init();
}

Tooltip.prototype.init = function()
{
	var aImages = document.getElementsByTagName('img');
	for (t = 0; t < aImages.length; t++)
	{
		if (aImages[t].className == 'tooltip')
		{
			aImages[t].marker = aImages[t].alt;
			aImages[t].alt = '';
			aImages[t].onmouseover = this.show;
			aImages[t].onmouseout = this.hide;
		}
	}
};

Tooltip.prototype.show = function(e)
{
	var caller;
	if (!e)
	{
		caller = window.event.srcElement;
		e = window.event;
	}
	else
		caller = e.target;

	aPos = findPos(caller);

	var winheight = window.document.documentElement.clientHeight;

	if (winheight == 0)
		winheight = window.innerHeight;

	/*For opera, clientheight seems to be set at the size of the first body-child..*/
	if (winheight < window.innerHeight)
		winheight = window.innerHeight;


	var eTooltip = document.getElementById("tooltip");

	eTooltip.style.top = aPos[1] + 'px';
	eTooltip.style.left = (aPos[0] + 20) + 'px';

	eTooltip.style.display = 'block';
	document.getElementById(caller.marker).style.display = 'block';
};

Tooltip.prototype.hide = function()
{
	document.getElementById("tooltip").style.display = 'none';
	document.getElementById("tt_address").style.display = 'none';
	document.getElementById("tt_phone").style.display = 'none';
	document.getElementById("tt_zipcode").style.display = 'none';
};

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			// JEL has some objects with 'position:relative', this messes up the position of the tooltip
			if (obj.id == "areaGTO" || obj.id == "wrapper")
				break;
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			//alert(obj.tagName + "\n" + obj.id + "\n" + curtop);
		}
		while (obj = obj.offsetParent);

		return [curleft, curtop];
	}
	return false;
}