/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var trailimage=["test.gif", 250, 250] //image path, plus width and height
var offsetfrommouse=[15,15] //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 trailid = "trailimageid";
var imageheight = 0;	
var imagewidth = 0;

function gettrailobj(){
	if($(trailid))	
		return $("trailimageid").style
	else 
		return null;
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail(){
	gettrailobj().visibility="hidden";
	document.onmousemove="";
	gettrailobj().left="-5000px"
	imageheight = 0;
}

function followmouse(e) {
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	
	var width = imagewidth + 33;

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < width){
			xcoord = e.pageX - xcoord - width; 
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (imageheight+ 35 )){
			ycoord += e.pageY - Math.max(0,( imageheight+ 35 + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < width){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - width; 
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (imageheight + 35 )){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,( imageheight + 35 + event.clientY - docheight));
		} 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)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	
}

function showtrail(img, title,height, width,border) {
	if(!border )
		border = 10;
	
	document.onmousemove=followmouse;
	
	imageheight = height+border;
	imagewidth = width+border;
	//Logger.info("height: "+height);
	
	var content = '<div style="padding: 3px; background-color: #ffffff; border: 1px solid #f1f1f1;">';
	if(title)
		content += '<strong style="font-size:12px;">'+title+'</strong><br/>';
	content += '<div align="center" style="padding: 5px 2px 2px 2px;"><img src="' + img + '" border="0"/></div>';
	content += '</div>';
	
	$(trailid).innerHTML = content;
	gettrailobj().visibility="visible";
}





