
var trailimage=["test.gif", 100, 99]; //image path, plus width and height
var offsetfrommouse=[-275,0]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=1; //duration in seconds image should remain visible. 0 for always.
var currentimageheight=235;

if (document.getElementById || document.all) document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;left:0px;top:0px;width:1px;height:1px;"></div>')


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

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

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

function showtrail(imagename){
	document.onmousemove=followmouse
	
	newHTML='<img src="'+imagename+'" style="border:1px solid #ffffff;padding:3px;">';
	gettrailobjnostyle().innerHTML=newHTML;
	gettrailobj().visibility="visible";
}

function hidetrail(){
	gettrailobj().visibility="hidden"
	document.onmousemove=""
//	gettrailobj().left="-50px"
}

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.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 400){
			xcoord = e.pageX - xcoord - 350; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight)){
			ycoord += e.pageY - Math.max(0,(55 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}		
//		xcoord+=e.pageX
//		ycoord+=e.pageY
	}
	else if (typeof window.event !="undefined"){
		xcoord+=truebody().scrollLeft+event.clientX
		ycoord+=truebody().scrollTop+event.clientY
	}
	
//	if (xcoord+trailimage[1]+3>docwidth || ycoord+trailimage[2]> docheight) gettrailobj().display="none"
//	else gettrailobj().display=""


//	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)
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

