/*Javascript for Bubble Tooltips by Alessandro Fulciniti
http://pro.html.it - http://web-graphics.com */

// http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

var imgOrgWidth = 100;
var imgOrgHeight = 60;
var show = false;

function enableTooltips(id)
{
	var imgs,i,h;
	if(!document.getElementById || !document.getElementsByTagName) return;
	h=document.createElement("div");
	h.id="btc";
	h.setAttribute("id","btc");
	h.style.position="absolute";

	document.getElementsByTagName("body")[0].appendChild(h);
	if(id==null) 
	{
		imgs=document.getElementsByTagName("img");
	} 
	else 
	{
		imgs=document.getElementById(id).getElementsByTagName("img");
	}
	for(i=0;i<imgs.length;i++)
	{
		if (imgs[i].className=='preview')
		{
			
			Prepare(imgs[i]);
		}
	}
}

function Prepare(el)
{
	var img = el.cloneNode(false);
	img.setAttribute("class",'showtime');	
	img.setAttribute("width",imgOrgWidth);	
	img.setAttribute("height",imgOrgHeight);	

	var tooltip;
	tooltip=CreateEl("div","tooltip");
	tooltip.appendChild(img);
	tooltip.appendChild(document.createElement("br"));
	tooltip.appendChild(document.createTextNode(el.getAttribute("alt")));
	tooltip.onmouseout=hideTooltip;
	setOpacity(tooltip);
	
	el.tooltip=tooltip;
	el.onmouseover=showTooltip;
}

function showTooltip(e)
{
	if(show)
	{
		hideTooltip(e);
	}
	var imgSmall = document.getElementById(this.id);
	var pos = { 'x':imgSmall.offsetParent.offsetLeft, 'y':imgSmall.offsetParent.offsetTop }
	
	pos['x'] -= Math.round((imgOrgWidth-this.width)/2);
	pos['y'] -= Math.round((imgOrgHeight-this.height)/2);
	
	document.getElementById("btc").appendChild(this.tooltip);
	document.getElementById("btc").style.top= pos['y']+"px";
	document.getElementById("btc").style.left= pos['x']+"px";
	show = true;
}

function hideTooltip(e)
{
	var d=document.getElementById("btc");
	if(d.childNodes.length>0) d.removeChild(d.firstChild);
	show = false;
}

function setOpacity(el)
{
	el.style.filter="alpha(opacity:95)";
	el.style.KHTMLOpacity="0.95";
	el.style.MozOpacity="0.95";
	el.style.opacity="0.95";
}

function CreateEl(t,c)
{
	var x=document.createElement(t);
	x.className=c;
	x.style.display="block";
	return(x);
}

Event.observe(window, "load", function(){enableTooltips()});
