/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
Modified by: CZ. Thanks to javascriptkit.com
*/

var cursor = { x:0, y:0 };  // cursor position absolut to HTML - page
var scrolledleft = 0; 
var scrolledtop = 0; 
var trailsize_x = 0;  // size of displayed
var trailsize_y = 0;  // size of displayed
var browser_IE = true;

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</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 showtrail(infocode, x_size_val, y_size_val){

	if("" == infocode) return;
	trailsize_x = x_size_val;  // width of displayed info
	trailsize_y = y_size_val;  // height of displayed info
	document.onmousemove=followmouse;

	cameraHTML = '';

	newHTML = '<div style="';
	if(trailsize_x > 0) { newHTML = newHTML + 'width:'+trailsize_x+'px; ' };
	newHTML = newHTML + ' padding: 10px; background-color: #2c2c2c; color:#FFFFFF;">';

	newHTML = newHTML + infocode;

	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}


function hidetrail(){
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove=""
	gettrailobj().left="-1500px"

}

function followmouse(e){

	// size of actual browser window (compatible in all browsers)
	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 (typeof e != "undefined"){  
		// used by FIREFOX, Opera, Chrome, Safari
		// e.pageX == cursor position - margin-left
		// e.pageY == cursor position - margin-top
		// pageXOffset == scrolled (hidden) space to left-margin
		// pageYOffset == scrolled (hidden) space to top-margin
        cursor.x = e.pageX; 
        cursor.y = e.pageY; 
		scrolledleft = pageXOffset;
		scrolledtop = pageYOffset;
		browser_IE = false;
		
	} else if (typeof window.event != "undefined"){  
		// used by IE
		// event.clientX == cursor position - margin-left - relative (to browser window) 
		// event.clientY == cursor position - margin-top - relative (to browser window) 
		// truebody().scrollLeft == scrolled (hidden) space to left-margin
		// truebody().scrollTop == scrolled (hidden) space to top-margin
        cursor.x = event.clientX + truebody().scrollLeft; // relative cursor position + hidden srolling space
        cursor.y = event.clientY + truebody().scrollTop;  // relative cursor position + hidden srolling space
		scrolledleft = truebody().scrollLeft;
		scrolledtop = truebody().scrollTop;
	}

	// position X value
	if((docwidth - (cursor.x - scrolledleft)) > (trailsize_x + 20 + 40)) {	// more than 350 pixel on right side, + 20 for padding  
		pos_x = cursor.x + 30;  // distance from mouse
	} else {
		pos_x = cursor.x - trailsize_x - 40;  // distance from mouse
	}
	gettrailobj().left=pos_x +"px";

	// position Y value
	if(cursor.y < 0) { cursor.y = cursor.y * -1; }

	if((docheight - (cursor.y - scrolledtop)) > (trailsize_y + 20 + 20)) {
		pos_y = cursor.y;
	} else {
		pos_y = (docheight + scrolledtop) - (trailsize_y + 20 + 20) ;
	}
	gettrailobj().top=pos_y +"px";
}


