// JavaScript Document

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact

Modified by Brad Simpson
	* Need to detect if it's near the edge
	
*/

function get(id) {
	if (document.getElementById)
		return document.getElementById(id);
	else if (document.all)
		return document.all.id;
}

var trailimage=["/js/blank.gif", 1, 1] //image path, plus width and height
var offX = 20;
var offY = -120;
var offsetfrommouse=[offX,offY] //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.

document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;left:0px;top:0px;width:1px;background:#FFF url(\'/js/ajax-loader.gif\') no-repeat center center;"><img style="display:block;" /><p style="margin:0;"></p></div>')

//image path, plus width and height
function settrailimage(i,w,h) {
	get("trailimageid").style.width = w + "px";
//	get("trailimageid").style.height = h + "px";
	get("trailimageid").firstChild.src = i;

	get("trailimageid").firstChild.style.width = w + "px";
	if(h != "") {
		get("trailimageid").firstChild.style.height = h + "px";
	}
//	alert(get("trailimageid").firstChild.style.height);
	
//	trailimage = [i, w, h];
}

function gettrailobj(){
	return get("trailimageid").style
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


var par = null;
function showtrail(o){
	get("trailimageid").style.backgroundColor = "#FFFFFF";
	get("trailimageid").style.padding = "8px";
	get("trailimageid").style.height = "auto";
	offsetfrommouse=[offX,offY];
	
	gettrailobj().visibility="visible";
	par = get(o); // get object that called this
}


function hidetrail(){
	gettrailobj().visibility="hidden"
	get("trailimageid").firstChild.src = "/js/blank.gif";
	get("trailimageid").firstChild.style.width = "1px";
	get("trailimageid").style.width = "1px";
	get("trailimageid").style.height = "1px";
	get("trailimageid").style.padding = "0px";
	get("trailimageid").style.backgroundColor = "transparent";
	offsetfrommouse=[0,0];
	
// disabling onmouse move messes up the x,y for some reason
//	document.onmousemove=""
}

function followmouse(e){
//	get("trailimageid").childNodes[1].innerHTML = par + " / " + e.pageY + " / " + truebody().scrollHeight + " / " + e.offsetY + " / " + e.screenY + " / " + e.clientY + " / " + e.layerY;
//	get("trailimageid").childNodes[1].nodeValue = "testing";
var xcoord=offsetfrommouse[0]
var ycoord=offsetfrommouse[1]
if (typeof e != "undefined"){
xcoord+=e.pageX
ycoord+=e.pageY
}
else if (typeof window.event !="undefined"){
xcoord+=truebody().scrollLeft+event.clientX
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 (xcoord+trailimage[1]+3>docwidth || ycoord+trailimage[2]> docheight)
//gettrailobj().display="none"
//else 
gettrailobj().display=""
gettrailobj().left=xcoord+"px"
gettrailobj().top=ycoord+"px"
}

function init() {
	document.onmousemove=followmouse;
}

if (displayduration>0)
setTimeout("hidetrail()", displayduration*1000)



init();


