// JavaScript Document
/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[-200,10]; //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 = 200;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="previewimageid">');
	document.write('</div>');
}

function getpreviewobj(){
if (document.getElementById)
return document.getElementById("previewimageid").style
else if (document.all)
return document.all.previewimageid.style
}

function getpreviewobjnostyle(){
if (document.getElementById)
return document.getElementById("previewimageid")
else if (document.all)
return document.all.previewimageid
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//I <3 istockphoto.com


function showpreview(imagename){
	currentimageheight = 200;

	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 4px; background: url(images/bg_preview.png); ">';
	newHTML = newHTML + '<img src="' + imagename + '" />';
	newHTML = newHTML + '</div>';
	getpreviewobjnostyle().innerHTML = newHTML;
	getpreviewobj().visibility="visible";
}
function showhints(texthint){
	currentimageheight = 20;

	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 2px 4px; background: #CC0000;">';
	newHTML = newHTML + '<p>' + texthint + '</p>';
	newHTML = newHTML + '</div>';
	getpreviewobjnostyle().innerHTML = newHTML;
	getpreviewobj().visibility="visible";
}
function hidepreview(){
	getpreviewobj().visibility="hidden"
	document.onmousemove=""
	getpreviewobj().left="-500px"
}

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.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	//if (document.all){
	//	getpreviewobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	getpreviewobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 600){
			xcoord = e.pageX - xcoord - 600; // Move to the left side of the cursor
		} else {
			if (e.pageX < 200){
				xcoord = e.pageX + 10; // Move to the left side of the cursor
			} else {
				xcoord += e.pageX;
			}
		}
		if (docheight - e.pageY < (currentimageheight + 30)){
			ycoord += e.pageY - Math.max(0,(30 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 600){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 600; // Move to the left side of the cursor
		} else {
			if (event.clientX < 200){
				xcoord = event.clientX + truebody().scrollLeft + 10; // Move to the left side of the cursor
			} else {
				xcoord += truebody().scrollLeft+event.clientX
			}
		}
		if (docheight - event.clientY < (currentimageheight + 30)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(30 + currentimageheight + 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; }
	getpreviewobj().left=xcoord+"px"
	getpreviewobj().top=ycoord+"px"

}