/*
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", 0, 0] //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 < 400){
			xcoord -= 500; // Move to the left side of the cursor
		}
	
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord = e.pageY - Math.max(0,(110 + 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 < 400){
			xcoord -= 500; // Move to the left side of the cursor
		}
		
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord = event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		}
	}
	
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

function showtrail(imagename, imagenum, license, caption, showthumb, brand, imageid){
	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;
		}
	}
	
	document.onmousemove=followmouse;
		
	newHTML = '<div id="trailimageid" style="position:absolute;padding: 5px; background: #FFF; border: 1px solid #cccccc;">'
	newHTML = newHTML + '<img src="' + imagename + '" border="0">';
	newHTML = newHTML + '<div class=v8 style=text-align:left;><b>'+ imagenum + '</b>&nbsp;(' + license + ')' +'</div>';
	if (caption) {
		newHTML = newHTML +'<div class=v11 style=margin:3px 0;text-align:left;>' + unescape(caption) +'<div>'
	}
	
	if (brand) {
		newHTML = newHTML +'<div class=v8 style=margin:7px 0;text-align:left;text-transform:lowercase>'+ unescape(brand) +'</div>';
	}
		
	newHTML = newHTML + '</div>'
		
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility = "visible";		
	
}

function showtrailmin(imagename) {
	document.onmousemove=followmouse;	
	newHTML = '<div id="trailimageid" style="position:absolute;padding: 5px; background: #FFF; border: 1px solid #cccccc;"><img src="' + imagename + '" border="0"></div>'
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility = "visible";		
	
}