/**
 * 
 *
 * @version $Id: hover_detail_layer.js,v 1.1 2007/10/05 09:13:26 tomek Exp $
 * @copyright 2007 
 **/
var offsetFromCursor = [15,15];
var hideTimeOut = 0; //0 = infinity
var hdlHeight = 0;
var hdlWidth = 0;
var imgObj = null;

if(document.getElementById || document.all)
{
	document.write('<div id="hoverDetailLayer" style="position:absolute"></div>');
}

function getHDLstyle()
{
	if(document.getElementById)
		return document.getElementById("hoverDetailLayer").style;
	else if(document.all)
		return document.all.hoverDetailLayer.style;
}

function getHDL()
{
	if (document.getElementById)
		return document.getElementById("hoverDetailLayer");
	else if (document.all)
		return document.all.hoverDetailLayer;
}

function realBody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
/*
function imgPreload(imgPath)
{
  imgObj = new Image();
	imgObj.src = imgPath;

	setTimeout('imgCheckSize()', 100);
}

function imgCheckSize()
{
	if(imgObj == null)
	  return;
	else if(!imgObj.complete)
	{
	  setTimeout('imgCheckSize()', 100);
	  return;
	}
	
	hdlHeight = imgObj.height;
	hdlWidth = imgObj.width;
	//alert(hdlHeight);
	//alert(hdlWidth);
}
*/
function showHDL(imgPath, title, description)
{
	document.onmousemove = mouseListener;
  //imgPreload(imgPath);
  
	var content = '<div class="hdlcontainer">';
	if(title.length > 0)
		content += '<div class="hdltitle">' + title + '</div>';
	if(description.length > 0)
		content += '<div class="hdldescr">' + description + '</div>';
	content += '<div class="hdlimgcontainer">';
	content += '<img src="' + imgPath + '" class="hdlimg"></div>';
	content += '</div>';
	
	getHDL().innerHTML = content;
	getHDLstyle().display = "inline";
}

function hideHDL()
{
	getHDLstyle().innerHTML = " ";
	getHDLstyle().display = "none";
	document.onmousemove = null;
	getHDLstyle().left = "-500px";
	hdlHeight = 0;
	hdlWidth = 0;
	imgObj = null;
}

function mouseListener(e)
{
	var _x = offsetFromCursor[0];
	var _y = offsetFromCursor[1];
	
	var availWidth = document.all? realBody().scrollLeft + realBody().clientWidth : pageXOffset + window.innerWidth - 15;
	var availHeight = document.all? Math.min(realBody().scrollHeight, realBody().clientHeight) : Math.min(window.innerHeight);
	
	if(typeof e != "undefined")
	{
	  if(availWidth - e.pageX < getHDL().offsetWidth + 20)
			_x = e.pageX - _x - getHDL().offsetWidth;
		else
			_x += e.pageX;
		if(availHeight - e.pageY < getHDL().offsetHeight + 20)
			_y += e.pageY - Math.max(0,(getHDL().offsetHeight + e.pageY - availHeight - realBody().scrollTop)) - 20;
			//_y += e.pageY - _y - getHDL().offsetHeight;
		else
			_y += e.pageY;
	}
	else if(typeof window.event != "undefined")
	{
		if(availWidth - event.clientX < getHDL().offsetWidth + 20)
			_x = event.clientX + realBody().scrollLeft - _x - getHDL().offsetWidth;
		else
			_x += realBody().scrollLeft + event.clientX;
		if (availHeight - event.clientY < getHDL().offsetHeight + 20)
			_y += event.clientY + realBody().scrollTop - Math.max(0,(getHDL().offsetHeight + event.clientY - availHeight)) - 20;
			//_y += realBody().scrollTop + event.clientY - _y - getHDL().offsetHeight;
		else
			_y += realBody().scrollTop + event.clientY;
	}
 	
	var availWidth = document.all ? realBody().scrollLeft + realBody().clientWidth : pageXOffset + window.innerWidth - 15;
	var docheight = document.all? Math.max(realBody().scrollHeight, realBody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
	if(_y < 0)
		_y = _y*-1;

	getHDLstyle().left=_x+"px";
	getHDLstyle().top=_y+"px";

}
