
var divw=0;
var divh=0;

if (document.getElementById || document.all) document.write('<div id="imgtrailer" style="position:absolute;visibility:hidden;z-index:200;"></div>');
function imgTrail() {
	return document.getElementById('imgtrailer');
}


function trailOff() {
	document.onmousemove="";
	imgTrail().style.visibility="hidden";
}

function trailOn(thumbimg,imgtitle,thw,thh) {	
	if (thumbimg != "") thumbimg2 = '<img src="thumb.php?pic='+thumbimg+'&max_x='+thw+'&max_y='+thh+'" border="0" style="margin-top:2px;">';
	else thumbimg2 = "";
			
	if (imgtitle != "") imgtitle2 = '<div class="tekst maly">'+imgtitle+'<div>';
	else imgtitle2 = "";
		
	imgTrail().style.left="-500px";
	divthw = parseInt(thw) + 4;
	imgTrail().innerHTML = '<div style="position:relative; background-color: #ffdb00; border: 1px solid black; width:'+divthw+'px; z-index:200; text-align:center;">'+thumbimg2+''+imgtitle2+'</div>';
	imgTrail().style.visibility="visible";
	divw = parseInt(thw)+25;
	divh = parseInt(thh)+130;
	document.onmousemove=followmouse;
}

function followmouse(e) {
	var docwidth = document.all ? truebody().scrollLeft+truebody().clientWidth : pageXOffset + window.innerWidth - 15;
	var docheight= document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight);

	if(typeof e != "undefined") {
		
		if(docwidth < 15+e.pageX+divw) xcoord = e.pageX-divw-5;
		else xcoord = 15+e.pageX;
		
		if(docheight < 15+e.pageY+divh) ycoord = 15+e.pageY-Math.max(0,(divh + e.pageY - docheight - truebody().scrollTop - 30));
		else ycoord = 15+e.pageY;
			
	} else if (typeof window.event != "undefined") {
	
		if(docwidth < 15+truebody().scrollLeft+event.clientX + divw) xcoord = truebody().scrollLeft-5+event.clientX-divw;
		else xcoord = truebody().scrollLeft+15+event.clientX;

		if(docheight < 15+truebody().scrollTop+event.clientY + divh) ycoord = 15+truebody().scrollTop+event.clientY-Math.max(0,(divh + event.clientY - docheight - 30));
		else ycoord = truebody().scrollTop+15+event.clientY;
	}

	imgTrail().style.left = xcoord+"px";
	imgTrail().style.top = ycoord+"px";
}
