var IFD_htimer = null;
var IFD_stimer = null;
var IFD_a = null;

function ShowIFD(a, type, id, img)
{
	if(IFD_stimer != null)
		clearTimeout(IFD_stimer);
		
	IFD_a = a;
	
	IFD_stimer = setTimeout("ShowIFD_real('"+type+"', "+id+", '"+(img?'true':'false')+"');", 1*1000);
}

function ShowIFD_real(type, id, img)
{
	HideIFD();
	if(IFD_stimer != null)
		clearTimeout(IFD_stimer);
	
	var Ypos = IFD_a.offsetTop;
	var Xpos = IFD_a.offsetLeft;
	var parentEl=IFD_a.offsetParent;
	while (parentEl!=null)
	{
		Xpos += parentEl.offsetLeft;
		Ypos += parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
	}
	
	$("#info_div").css('left', Xpos  + "px");
	$("#info_div").css('top', (Ypos+20) + "px");
	
	$.get("info", {type: type, id: id, hide_img:img},
  			function(data)
		  	{
				if(data == "")
				{
					return;
				}
				
				$("#info_div").html(data);
				$("#info_div").css('display', "");
				
				setPositionIFD();
				
				HideIFD_Timer(15);
		  	}
	);
}

function setPositionIFD()
{
	var x = parseInt($("#info_div").css('left'));
	var y = parseInt($("#info_div").css('top'));
				
	var w = $("#info_div").get(0).offsetWidth;
	var h = $("#info_div").get(0).offsetHeight;
				
	x -= w/2;
				
	var de = document.documentElement;
    var b = document.body;
    var rx = x + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
    var ry = y - (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	
	if(rx+w > (screen.width-50))
		x -= (x + w) - screen.width + 50;
	else if(rx < 20)
		x = 20;
	if(ry+h > (screen.height*0.7))
		y -= h+20;
	
	$("#info_div").css('left', x+"px");
	$("#info_div").css('top', y+"px");
}

function HideIFD_Timer(sec)
{
	if(IFD_htimer != null)
		clearTimeout(IFD_htimer);
	
	IFD_htimer = setTimeout("HideIFD();", sec*1000);
}

function HideIFD_onout()
{
	if(IFD_stimer != null)
		clearTimeout(IFD_stimer);
	
	HideIFD_Timer(0.5);
}

function HideIFD()
{
	if(IFD_htimer != null)
		clearTimeout(IFD_htimer);
	IFD_htimer = null;
	
	
	try{
	
	
	$("#info_div").html("");
	$("#info_div").css('display', "none");
	
	}catch(e){}
}