var offsetfrommouse=[5,0]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 270;	// maximum image size.
var curleft = 0;	// current left side of image
var curtop = 0;     // current top of the image
var curimagewidth = 0;  // current width of image onmouseover

if (document.getElementById || document.all){
	document.write('<div id="hoverImageId">');
	document.write('</div>');
}

function gettrailobj(){
	if (document.getElementById)
		return document.getElementById("hoverImageId").style
	else if (document.all)
		return document.all.hoverImageId.style
}

function gettrailobjnostyle(){
	if (document.getElementById)
		return document.getElementById("hoverImageId")
	else if (document.all)
		return document.all.hoverImageId
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showHover(imagename,title,description,showthumb,height,width) {

	curimagewidth = width;

	if (height > 0){
		currentimageheight = height;
	}
	

		document.onmouseover=followmouse;

		newHTML = '<div style="padding: 5px; border: 1px solid #000; background-color: #BBB;">';
		newHTML = newHTML + '<h2>' + title + '</h2>';
		newHTML = newHTML + 'Description: ' + description + '<br/>';

		if (showthumb > 0){
			newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;"><img src="' + imagename + '" border="0"></div>';
		}

		newHTML = newHTML + '</div>';

		gettrailobjnostyle().innerHTML = newHTML;

		gettrailobj().visibility="visible";

	
}

function hideHover() {
	gettrailobj().visibility="hidden"
	document.onmouseover=""
	gettrailobjnostyle().left="95px"
}

function followmouse(e) {
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - curleft - curimagewidth < 400){
			xcoord = curleft - xcoord - 400;
		}
		else {
			xcoord += curleft + curimagewidth;
		}
		if (docheight - e.pageY < (currentimageheight + 200)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){	
		if (docwidth - curleft - curimagewidth < 400) {
			xcoord = curleft + truebody().scrollLeft - xcoord - 400;
		}
		else {
			xcoord += truebody().scrollLeft + curleft + curimagewidth;
		}

		//if (docheight - event.clientY < (currentimageheight + 110)){
		//	ycoord += event.clientY + truebody().scrollTop - Math.max(0,(currentimageheight + event.clientY - docheight));
		//} else {
		//	ycoord += truebody().scrollTop + event.clientY;
		//}
		if (curtop + currentimageheight > docheight) {
			ycoord += docheight - currentimageheight - 200;
		}
		else {
			ycoord += truebody().scrollTop + curtop;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

function findPosX(obj) {
    var tempcurleft = 0;
    if (obj.offsetParent) {
        while (1) {
            tempcurleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        tempcurleft+=obj.x;
    }
	curleft = tempcurleft;
}

function findPosY(obj) {
    var tempcurtop = 0;
    if (obj.offsetParent) {
        while (1) {
            tempcurtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        tempcurtop+=obj.y;
    }
    curtop = tempcurtop;
}