var TipCreator = new Object();
var hasIframe = (document.all && !window.opera)?1:0;
TipCreator._topDivZIndex = 10000;
TipCreator._oBody = null;
TipCreator._oHelperIframe = null;
TipCreator._TipCreatorDiv = null;
TipCreator._mousePos = new Object();


TipCreator._init = function()
{

	TipCreator._oBody = document.body;
	if(!TipCreator._oBody)
	TipCreator._oBody = document.getElementsByTagName("BODY").item(0);


	if(hasIframe){
		TipCreator._oHelperIframe = document.createElement("IFRAME");
		TipCreator._oHelperIframe.style.border = 0;
		TipCreator._oHelperIframe.width = 0;
		TipCreator._oHelperIframe.height = 0;
		TipCreator._oHelperIframe.style.position = "absolute";
		TipCreator._oBody.appendChild(TipCreator._oHelperIframe);
	}

	TipCreator._TipCreatorDiv = document.createElement("DIV");
	TipCreator._TipCreatorDiv.style.border = 0;
	TipCreator._TipCreatorDiv.width = 0;
	TipCreator._TipCreatorDiv.height = 0;
	TipCreator._TipCreatorDiv.style.position = "absolute";
	TipCreator._oBody.appendChild(TipCreator._TipCreatorDiv);

	TipCreator._attachToEvent(document, 'onmousemove', TipCreator._mousemove);
}


TipCreator._getToolTipDivWidth = function()
{

	var tableWidth = "" + document.getElementById("TipCreatorTable").offsetWidth;
	if(tableWidth.indexOf('px') > -1){
		return parseInt(tableWidth.substring(0, tableWidth.infexOf('px')));
	} else {
		return tableWidth;
	}
}

TipCreator._getToolTipDivHeight = function()
{
	var tableHeight = "" + document.getElementById("TipCreatorTable").offsetHeight;
	if(tableHeight.indexOf('px') > -1){
		return parseInt(tableHeight.substring(0, tableHeight.infexOf('px')));
	} else {
		return tableHeight;
	}
}

TipCreator._mousemove = function(e)
{
	if(typeof(e) == 'undefined')e = event;
	TipCreator._mousePos.Y = e.clientY;
	TipCreator._mousePos.X = e.clientX;
	if(TipCreator._TipCreatorDiv.style.visibility == 'visible'){
		TipCreator._fixTipPosition();
	}
}


TipCreator._fixTipPosition = function()
{

	var scl = (document.all||window.opera)?
	[TipCreator._oBody.scrollTop,TipCreator._oBody.scrollLeft]:[pageYOffset,pageXOffset];
	var clt = (document.all||window.opera)?
	[TipCreator._oBody.offsetHeight,TipCreator._oBody.offsetWidth]:[innerHeight,innerWidth];

	if(TipCreator._mousePos.Y > Math.round(clt[0] / 2)){


		TipCreator._TipCreatorDiv.style.top = TipCreator._mousePos.Y - TipCreator._getToolTipDivHeight() + scl[0];
	} else {

		TipCreator._TipCreatorDiv.style.top = TipCreator._mousePos.Y + scl[0];
	}


	if(TipCreator._mousePos.X > Math.round(clt[1] / 2)){
		TipCreator._TipCreatorDiv.style.left = TipCreator._mousePos.X - TipCreator._getToolTipDivWidth() + scl[1];
	} else {

		TipCreator._TipCreatorDiv.style.left = TipCreator._mousePos.X + 5 + scl[1];
	}
	if(hasIframe){
		TipCreator._oHelperIframe.style.top = TipCreator._TipCreatorDiv.style.top;
		TipCreator._oHelperIframe.style.left = TipCreator._TipCreatorDiv.style.left;}
}

TipCreator._attachToEvent = function(obj, name, func) 
{
	name = name.toLowerCase();

	if(obj.addEventListener) {
		if(name.length > 2 && name.indexOf("on") == 0) name = name.substring(2, name.length);
		obj.addEventListener(name, func, false);
	} else if(typeof(obj.attachEvent) != "undefined"){
		obj.attachEvent(name, func);
	} else {
		if(obj[name] != null){

			var oldOnEvents = obj[name];
			obj[name] = function(e) {
				try{
					func(e);
					eval(oldOnEvents);
				} catch(e){}
			};
		} else {
			obj[name] = func;
		}
	}
}


TipCreator.showToolTip = function(titolo, voto,genere,uscita,durata, immagine)
{
	if(hasIframe)TipCreator._oHelperIframe.style.zIndex = TipCreator._topDivZIndex++;
	var divContent = "<table id='TipCreatorTable' style='border:1px solid black;background-color:"+
	"LightGoldenrodYellow' cellspacing='0' cellpading='0'><tr>";
	if(immagine != "" && immagine != null) divContent+="<td><img src='"+immagine+"' width='51' height='75'></td>"		
	divContent+="<td><span class='arial_small' style=\"color: black;\">";	
	if(titolo != "") divContent+= "<b>Titolo: </b>"+titolo;
	if(voto != "") divContent+="<br><b>Voto: </b>"+voto;
	if(genere != "") divContent+="<br><b>Genere: </b>"+genere;
	if(uscita != "") divContent+="<br><b>Uscita: </b>"+uscita;
	if(durata != "") divContent+="<br><b>Durata: </b>"+durata;	
	divContent+="</span></td></tr></table>";
	
	TipCreator._TipCreatorDiv.innerHTML = divContent;
	TipCreator._mousePos
	TipCreator._TipCreatorDiv.style.zIndex = TipCreator._topDivZIndex++;
	if(hasIframe){
		TipCreator._oHelperIframe.style.top = TipCreator._TipCreatorDiv.style.top;
		TipCreator._oHelperIframe.style.left = TipCreator._TipCreatorDiv.style.left;
		TipCreator._oHelperIframe.width = TipCreator._getToolTipDivWidth();
		TipCreator._oHelperIframe.height = TipCreator._getToolTipDivHeight();
		TipCreator._oHelperIframe.style.visibility = 'visible';
	}
	TipCreator._fixTipPosition();
	TipCreator._TipCreatorDiv.style.visibility = 'visible';
}


TipCreator.hideToolTip = function()
{
	if(hasIframe){
		TipCreator._oHelperIframe.style.visibility = 'hidden';}
		TipCreator._TipCreatorDiv.style.visibility = 'hidden';
}


TipCreator._attachToEvent((window.opera)?document:window, 'onload', TipCreator._init);