/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact

Script altered by Brad Simpson, bsimpson@evolutionmultimedia.net, 3.20.2006

*/

var boxW;												// image width (used to test page boundaries // should probably use DIV width instead)
var boxH;												// image height
var offsetfrommouse=[0,0]							// image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var showInt = null;												// Interval that controls delay timeout
var showDelay = 100;											// amount in milliseconds to delay before showing popup

// Create initial floating div
if (document.getElementById || document.all)
	var stuff = '';
	stuff += '<div id="trailimageid" style="position:absolute;visibility:hidden;left:0px;top:0px;z-index:5000;width:140px;height:165px;">';
	stuff += '</div>';
	document.write(stuff);


// Show floating div
// clr should be a color name, like "caribeVersilia"
function showtrail(c, h, i) {
	clearTimeout(showInt);
	
	if(c == null){
		offsetfrommouse[1] = -140; // y
	} else {
		offsetfrommouse[1] = -180; // y
	}
	
	document.onmousemove=followmouse
	
	// Show div after a brief delay
	showInt = setTimeout("changeContents('" + c + "','" + h + "', '" + i + "')", showDelay);
}


// Hide floating div
function hidetrail(){
	clearTimeout(showInt);
	
	gettrailobj().visibility="hidden"
	document.onmousemove=""
}



// Change contents of floating div
// clr should be a color name, like "caribeVersilia"
function changeContents(clr, html, img) {
	clearTimeout(showInt);
	gettrailobj().visibility="visible"

	var stuff = "";
	if(clr != "null") {
		
		// Set size of box
		getTrailDIV().style.width = "140px";
		getTrailDIV().style.height = "165px";
		if(img != "") {
				stuff += '<div id="bubble"><p>' + html + '<img src="' + img + '" alt="image" /></p></div>';
		} else {
				stuff += '<div id="bubble"><p>' + html + '</p></div>';
		}

	} else {

		// Set size of box
		getTrailDIV().style.width = "200px";
		getTrailDIV().style.height = "auto";
		
		stuff = '<div id="popupHTML">' + html + '</div>';
	}
	
	
	getTrailDIV().innerHTML =  stuff;
}

// Return a reference to the floating DIV
function getTrailDIV() {
	if (document.getElementById)
		return document.getElementById("trailimageid")
	else if (document.all)
		return document.all.trailimagid
}

// Return a reference to the floating DIV's style property
function gettrailobj(){
	if (document.getElementById)
		return document.getElementById("trailimageid").style
	else if (document.all)
		return document.all.trailimagid.style
}

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


// e is the mousemove event
function followmouse(e) {
	
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	
	boxW = parseInt(getTrailDIV().style.width);
	boxH = parseInt(getTrailDIV().style.height);
	
	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+boxW+3>docwidth || ycoord+boxH> docheight) {
		gettrailobj().display="none";
	} else { 
		gettrailobj().display="";
		gettrailobj().left=xcoord+"px";
		gettrailobj().top=ycoord+"px";
	}
	
}


