t=setTimeout("callme()",200);
$(document).ready(function(){
	$("area,.popup img").mouseover(function(){
		clearTimeout(t);						 
		if($(this).attr("shape")=="poly")
		{
		cods  =  $(this).attr("coords");
		brokenstring=cods.split(",");
		offsetT = parseInt(brokenstring[1]);
		offsetL = parseInt(brokenstring[0]);
		offW = parseInt(brokenstring[2]-brokenstring[0]);
		offH = parseInt(brokenstring[5]-brokenstring[3]);
		}
		else
		{
		offsetT = $(this).offset().top;
		offsetL = $(this).offset().left;
		offW = $(this).width();
		offH = $(this).height();
		}
		//alert(offsetT+"--"+offsetL+"--"+offW+"--"+offH);
		tooltipID = $(this).attr("class");
		contDiv = $("#"+tooltipID).html();
		//alert(contDiv);
		dDivW = $("#"+tooltipID).innerWidth();
		$("#"+tooltipID).width(dDivW);
		imgW = getOriginalWidthOfImg($("#"+tooltipID+" img").attr("src"));
		if($("#"+tooltipID+" object").width() != null)
		{
			dDivW = $("#"+tooltipID+" object").width();
			$("#"+tooltipID).width(dDivW);
		}
		else if(imgW > 100)
		{
			dDivW = imgW;
			$("#"+tooltipID).width(dDivW);	
		}
		else
		{
			dDivW = 220;
			$("#"+tooltipID).width(dDivW);
		}
		dDivH = $("#"+tooltipID).innerHeight();
		parentW = $(this).closest("table").width();
		parentH = $(this).closest("table").height();
		rErrW = parentW-offsetL;
		if(rErrW < dDivW)
		{
			DivoutL = dDivW-rErrW;
			posL = 	offsetL-(DivoutL+15);
		}
		else
		{
			if(offsetL > dDivW/2)
			{
			posL = 	(offsetL+(offW/2))-(dDivW/2);	
			}
			else
			{
			posL = 	offsetL;	
			}
		}
		$("#floatingDiv").css({"width":offW,"height":offH,"top":offsetT,"left":offsetL}).html(contDiv);
		rErrH = parentH-offsetT;
		if(dDivH > parentH || (dDivH/2)-offsetT > 0 )
		{
			posT = 	0;		
		}
		else
		{
			if(rErrH < dDivH)
			{
				DivoutH = dDivH-rErrH;
				posT = 	offsetT-(DivoutH+15);
			}
			else
			{
				if(offsetT > dDivH/2)
				{
				posT = 	(offsetT+(offH/2))-(dDivH/2);
				}
				else
				{
				posT = 	offsetT;	
				}
			}	
		}
		$("#floatingDiv").show().animate({width:dDivW,height:dDivH,top:posT,left:posL},10);
	});
	$("#floatingDiv").mouseover(function(){
		clearTimeout(t);							   
	});
	$("#floatingDiv").mouseout(function(){
		t=setTimeout("callme()",200);
	});
	$("area,.popup img").mouseout(function(){
		t=setTimeout("callme()",200);
	});
	
});
function callme()
{
	$('#floatingDiv').hide();	
}
function getOriginalWidthOfImg(img_element) {
	var img = new Image();
	img.src = img_element;
	return img.width;
}

