/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var trailimage=["../images/pix.gif", 300, 400] //image path, plus width and height
var offsetfrommouse = [10,-25] //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 currentimageheight = 450;	// maximum image size.

if (document.getElementById || document.all)
document.write('<div id="trailimageid" style="position:absolute;visibility:visible;left:0px;top:0px;width:1px;height:1px"><img src="'+trailimage[0]+'" border="0" width="'+trailimage[1]+'px" height="'+trailimage[2]+'px"></div>')

function gettrailobj(){
	if (document.getElementById)
		return document.getElementById("trailimageid").style
	else if (document.all)
	return document.all.trailimagid.style
}

function gettrailobjnostyle(){
	if (document.getElementById)
		return document.getElementById("trailimageid")
	else if (document.all)
		return document.all.trailimagid
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail(){
	gettrailobj().visibility="hidden"
	document.onmousemove=""
}

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"){
		xcoord += e.pageX
		ycoord += e.pageY
		
		if (docwidth - e.pageX < 300){
			xcoord -= 550; // Move to the left side of the cursor
		}
	
		if (docheight - e.pageY < currentimageheight){
			ycoord -= currentimageheight/2			//e.pageY - Math.max(0,(currentimageheight + e.pageY - docheight - truebody().scrollTop));
		}

	} else if (typeof window.event !="undefined"){
		xcoord += truebody().scrollLeft+event.clientX
		ycoord += truebody().scrollTop+event.clientY
		
		if (docwidth - event.clientX < 300){
			xcoord -= 550; // Move to the left side of the cursor
		}
		
		if (docheight - event.clientY < currentimageheight){
			ycoord -= currentimageheight/2						//event.clientY + truebody().scrollTop - Math.max(0,(currentimageheight + event.clientY - docheight));
		}
	}
	
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

function showtrail(imagename, imagenum, license, caption, showthumb, brand, imageid){

		document.onmousemove=followmouse;
		newHTML = '<div id="trailimageid" style="position:absolute;padding: 5px; background: #FFF; border: 1px solid #cccccc;white-space:nowrap;text-align:center" class="v9"><img src="' + imagename + '" border="0">';
		var lencaption = caption.length;
		
		var len = 85;
		if (caption) {
  			var trunc = caption;
  				if (trunc.length > len) {

    				/* Truncate the content of the P, then go back to the end of the previous word to ensure that we don't truncate in the middle of a word */
    				trunc = trunc.substring(0, len);
    				trunc = trunc.replace(/\w+$/, '');
   					caption = trunc;
  					////}
				}
		}
		newHTML = newHTML + '<br><b>'+ imagenum + '</b>&nbsp;(' + license + ')<br>' + unescape(caption) +'<br>&copy;&nbsp;'+ brand +'</div>';

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().visibility = "visible";		
	
}