/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15, 15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var actualobject=[0, 0];
var borderColor = '#707070';
var preloaderWidth = 20;
var preloaderHeight = 50;
var fObjectShowOnSide = '';

function gettrailobj(){
	// ### Objekt zur?ckgeben
	if (document.getElementById)
		return document.getElementById("preview_image");
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function hidetrail(){
	clearTimeout(timeDisplay);
	gettrailobj().style.display="none";
	gettrailobj().innerHTML = '';
	actualobject[0] = 0;
	actualobject[1] = 0;
}

var timeDisplay = 0;
function getTrail (imgURL, imgTitle, imgWidth, imgHeight, showOnSide) {
	actualobject[0] = (imgWidth+20);
	actualobject[1] = (imgHeight+20);
	fObjectShowOnSide = showOnSide;
	timeDisplay = setTimeout("displayTrail('"+imgURL+"', '"+imgTitle+"', "+imgWidth+", "+imgHeight+");", 250)
}

function displayTrail (imgURL, imgTitle, imgWidth, imgHeight) {
	document.onmousemove=followmouse;
	
	gettrailobj().style.width = (imgWidth+20)+'px';
	gettrailobj().style.height = (imgHeight+20)+'px';
	
	previewContent = '<div style="padding: 10px;">';
	previewContent += '<div id="loader" style="position: absolute; z-index: 200; left: 50%; top: 50%; margin-top: -'+(preloaderWidth/2)+'px; margin-left: -'+(preloaderHeight/2)+'px;"><img src="/images/preview-loader.gif" alt=""/></div>';
	// previewContent += '<div style="font-weight: bold; color: '+borderColor+'; font-family: Arial; font-size: 14px;">'+imgTitle+'</div>';
	previewContent += '<div><img src="'+imgURL+'" onload="hideLoader();" /></div>';
	previewContent += '</div>';
	
	gettrailobj().innerHTML = previewContent;
	gettrailobj().style.display = "inline";
}

function hideLoader () {
	document.getElementById('loader').style.display = 'none';
}

function followmouse(e){
	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;
	}
	
	// ### Zu weit rechts?
	if ((xcoord+actualobject[0]+offsetfrommouse[0]+5) > screen.availWidth || fObjectShowOnSide == 'left')
		xcoord = xcoord - actualobject[0] - offsetfrommouse[0] - offsetfrommouse[0] - 5;
	
	// ### Zu weit unten?
	iExactHeight = truebody().clientHeight;
	if (window.innerHeight > 0)
		iExactHeight = window.innerHeight;
	if ((ycoord + actualobject[1] + offsetfrommouse[1]) > (iExactHeight+truebody().scrollTop))
		ycoord = (iExactHeight +truebody().scrollTop) - actualobject[1] - offsetfrommouse[1];
	
	// ### Noch alles ok?
	if (xcoord > 0)
	{	
		// ### Einblenden?
		if (actualobject[0] > 0)
			gettrailobj().style.display = "inline";
		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);
		gettrailobj().style.left=xcoord+"px";
		gettrailobj().style.top=ycoord+"px";
	}
	else
	{
		// ### Ausblenden!
		gettrailobj().style.display = "none";
	}
}