// JavaScript Document

var oHoverDiv;
var oHoverImg;
mouseLocation = new Point(-500,-500);

function Point(x,y) {  this.x = x; this.y = y; }
var isIE7=false;
var myregex = /MSIE 7./i;
var myArray = navigator.appVersion.match(myregex);
if(myArray) {
	if(myArray.length > 0) isIE7=true;
}


/* 
Example:
function test()
{
  if (document.layers) getMouseLoc;     //NS
  else if (document.all) getMouseLoc(); //IE
  alert(mouseLocation.x+","+mouseLocation.y);
}
in the BODY:
<a href="#" onmouseover="test()">test</a>
*/

var hoverTimer;
function checkDiv() {
	if(!oHoverDiv) {
		oHoverDiv=document.createElement("div");
		oHoverDiv.setAttribute("id","HoverDiv");
		oHoverDiv.style.display="none";
		oHoverDiv.style.position="absolute";
		//oHoverDiv.style.width="430px";
		//oHoverDiv.style.height="300px";
		oHoverDiv.style.width="auto";
		oHoverDiv.style.height="auto";
		oHoverDiv.style.zIndex=100;
		oHoverDiv.style.backgroundColor="#E0E0E0";
		oHoverImg=document.createElement("img");
		//oHoverImg.style.width="500px";
		//oHoverImg.style.height="300px";
		oHoverImg.style.border="solid 2px black";
		oHoverDiv.appendChild(oHoverImg);
		var bodyRef = document.getElementsByTagName("body").item(0);
		bodyRef.appendChild(oHoverDiv);
		//document.body.insertBefore(oHoverDiv,document.getElementById("divFooter"));
	}
}
function showHover(sImage) {
	oHoverDiv.style.display="block";
	var widthOffset=oHoverDiv.offsetWidth + 10;
	if(widthOffset<1) widthOffset=480;
	if(mouseLocation.x>600) oHoverDiv.style.left=(mouseLocation.x-widthOffset) + "px"
	else oHoverDiv.style.left=(mouseLocation.x+60) + "px";
	if(hoverTimer) {
		window.clearTimeout(hoverTimer);
		hoverTimer=null;
	}
	
}
function registerHoverElement(oElementID,sImage) {
	var oElement=document.getElementById(oElementID);
	if(!oElement) return null;
	oElement.onmouseover=function(e) {
		if(!e) e=window.event;
		if(!document.all)  //NS
		{
			mouseLocation.x = e.pageX;
			mouseLocation.y = e.pageY;
		}
		else               //IE
		{
			if(isIE7) {
				mouseLocation.x = event.x + document.documentElement.scrollLeft;
				mouseLocation.y = event.y + document.documentElement.scrollTop;
			}
			else {
				mouseLocation.x = event.x + document.body.scrollLeft;
				mouseLocation.y = event.y + document.body.scrollTop;
			}
		}
		checkDiv();
		oHoverDiv.style.top=(mouseLocation.y -30) + "px";
		if(mouseLocation.x>600) oHoverDiv.style.left=(mouseLocation.x-480) + "px"
		else oHoverDiv.style.left=(mouseLocation.x+60) + "px";
		//alert(mouseLocation.x + " -560 = ".oHoverDiv.style.left);
		oHoverImg.src=sImage;
		hoverTimer=window.setTimeout(showHover,1000,sImage);
	}
	oElement.onmouseout=function(e) {
		if(hoverTimer) {
			window.clearTimeout(hoverTimer);
			hoverTimer=null;
		}
		if(oHoverDiv) oHoverDiv.style.display="none";
		if(oHoverImg) oHoverImg.src="/images/spacer.gif";
	}
	oElement.onmousemove=function(e) {
		checkDiv();
		if(!e) e=window.event;
		if(!document.all)  //NS
		{
			mouseLocation.x = e.pageX;
			mouseLocation.y = e.pageY;
		}
		else               //IE
		{
			if(isIE7) {
				mouseLocation.x = event.x + document.documentElement.scrollLeft;
				mouseLocation.y = event.y + document.documentElement.scrollTop;
			}
			else {
				mouseLocation.x = event.x + document.body.scrollLeft;
				mouseLocation.y = event.y + document.body.scrollTop;
			}
		}
		oHoverDiv.style.top=(mouseLocation.y -30) + "px";
		var widthOffset=oHoverDiv.offsetWidth + 10;
		if(widthOffset<1) widthOffset=480;
		if(mouseLocation.x>600) oHoverDiv.style.left=(mouseLocation.x-widthOffset) + "px"
	}
}