var offsetfrommouse=[10,-10];

function showTrail(img, host, w, h, title)
{
    document.onmousemove=followmouse;
        
    gettrailobj().display = 'block';	
	
	if (250 < w)
	{
		dif = (250 * 100) / w;
		newH = Math.round((h * dif) / 100);
		h = newH;
		w = 250;
	}

	if (250 < h)
	{
		dif = (250 * 100) / h;
		newW = Math.round((w * dif) / 100);
		h = newH;
		w = newW;
	}
	
	var extra = 0; if(title != "") extra = 30; 
	offsetfrommouse[1] = h * (-1) - 15 - extra;
		
	//document.getElementById("trail").innerHTML = "<div id='popup_thumb' style='width:" + w + "px;height:" + h + "px;'><img class='loading' src='" + host + "/images/loading.gif' border='0' alt='' /></div>";
	document.getElementById("trail").innerHTML = "<div id='popup_thumb'><div style='width:" + w + "px;height:" + h + "px;'></div></div>";

	var ajax = new sack();
    ajax.setVar("image", img);
	ajax.setVar("host", host);
	ajax.setVar("w", w);
	ajax.setVar("h", h);
	ajax.setVar("t", title);
	ajax.requestFile = host+"/modules/produktai/trail.php";	
	ajax.method = 'POST';
	ajax.element = 'trail';
	ajax.runAJAX();	
}
//----------------------------------------------------------

function gettrailobj()
{
	if (document.getElementById) return document.getElementById("trail").style;
	else if (document.all) return document.all.trailimagid.style;
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function hideTrail()
{
	
	gettrailobj().display = 'none';
	document.getElementById("trail").innerHTML = "";
	document.onmousemove = '';	
}

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
	}
	
	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().display="";
	gettrailobj().left=xcoord+"px";
	gettrailobj().top=ycoord+"px";
}

