var offsetfrommouse = [15,15];
var currentimageheight;

if (document.getElementById || document.all){
	document.write('<div id="trailimageholder" style="position:absolute; visibility:hidden; border:1px #C0C0C0 solid; background:#404040 url(http://www.pantonov.com/images/24-1-404040.gif) no-repeat center center; z-index:2000"></div>');
}

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

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

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

function showtrail(imagename){
	document.onmousemove = followmouse;
	gettrailobjnostyle().innerHTML = '<img src="' + imagename + '" alt="" style="border:0; display:block"/>';
	currentimagewidth = gettrailobjnostyle().clientWidth;
	currentimageheight = gettrailobjnostyle().clientHeight;
	gettrailobj().visibility = 'visible';
}

function hidetrail(){
	gettrailobj().visibility = 'hidden';
	document.onmousemove = '';
	gettrailobj().left = '-500px';
}

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(document.body.offsetHeight,window.innerHeight);
	if (typeof e != 'undefined'){
		if (docwidth - e.pageX < currentimagewidth + 17){
			xcoord = e.pageX - xcoord - currentimagewidth + offsetfrommouse[0] - 10; // Move to the left side of the cursor
		}
		else{
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < currentimageheight + 17){
			ycoord += e.pageY - ycoord - currentimageheight - offsetfrommouse[1];
		}
		else{
			ycoord += e.pageY;
		}
	}
	else{
//		if (typeof window.event != "undefined"){
			if (docwidth - event.clientX < currentimagewidth + 17){
				xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimagewidth + offsetfrommouse[0] - 10; // Move to the left side of the cursor
			}
			else{
				xcoord += truebody().scrollLeft+event.clientX
			}
			if (docheight - event.clientY < currentimageheight + 17){
				ycoord += event.clientY + truebody().scrollTop - ycoord - currentimageheight - offsetfrommouse[1];
			}
			else{
				ycoord += truebody().scrollTop + event.clientY;
			}
//		}
	}
	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';
}