var tooltip_timeout = ""; 
var tooltip_show = false;
var ev = "";
var tooltip_id = "";
var loading_image = new Image();
loading_image.src = "/imgs/loading_image.gif";

function tipShow() {
	
	if (tooltip_show==true) {
		
		infotooltip = eval(document.getElementById(tooltip_id+"value").value);	
		infotooltip = infotooltip[0];
				
		clearTimeout(tooltip_timeout);
		
		/* $("#tooltip")
			.css("top",(ev.pageY - xOffset) + "px")
			.css("left",(ev.pageX + yOffset) + "px")
			.show();	 */
		
		mx = 790;
			
		$("#tooltip")
			.css("top",(ev.pageY - xOffset) + "px")
			.css("left",(mx + yOffset) + "px")
			.show();	
			
			
		$("#tooltip_description").text(infotooltip.nome);
		$("#tooltip_views").text(infotooltip.views);
		$("#tooltip_data").text(infotooltip.data);
		$("#tooltip_votos").text(infotooltip.votos);
		$("#tooltip_width").css('width',infotooltip.width+"px");
		$("#tooltip_image").attr({src:loading_image.src});
		$("#tooltip_image").attr({src:"/images/"+infotooltip.image,alt:infotooltip.nome});
	
	}

}

function tipHide() {
	
	if (!tooltip_show) {
		
		clearTimeout(tooltip_timeout);
		$("#tooltip").hide();
	
	}

}

this.tooltip = function(){	
	
	xOffset = 30;
	yOffset = -280;		
				
	$("a.tooltip").hover(function(e){		

		tooltip_show = true;	
		ev = e;
		tooltip_id = this.getAttribute("id");
		clearTimeout(tooltip_timeout);
		tooltip_timeout = setTimeout("tipShow()",500);
			
    },
	function(){
		
		tooltip_show = false;
		clearTimeout(tooltip_timeout);
		tooltip_timeout = setTimeout("tipHide()",200);
		
		
    });	
    
	$("#tooltip").hover(function(e){
		$("#tooltip").show();
		tooltip_show = true;
			
	},
	function(){		
		tooltip_show = false;
		tooltip_timeout = setTimeout("tipHide()",200);
    });	
};

$(document).ready(function(){
	tooltip();
});