var ua = navigator.userAgent.toLowerCase();
var divw = 0;
var divh = 0;

if(document.getElementById || document.all)	document.write('<div id="imgpop" style="position: absolute; visibility: hidden"></div>')

function popup(fisier, dim_x, dim_y)
{
	if(dim_x == 0) dim_x = screen.width - 50;
	else dim_x += 25;
	if(dim_y == 0) dim_y = screen.height - 150;
	else dim_y += 25;
	poz_x = (screen.width / 2) - (dim_x / 2);
	poz_y = (screen.height / 2) - (dim_y / 2);
	stil = "copyhistory=no, directories=no, location=no, menubar=no, resizable=no, scrollbars=yes, status=no, toolbar=no, width=" + dim_x + ", height=" + dim_y + ", left=" + poz_x + ", top=" + poz_y + ", screenX=" + poz_x + ", screenY=" + poz_y;
	fereastra = window.open(fisier, 'popup', stil);
	fereastra.document.write('<div style="cursor: pointer" onclick="self.close()"><img src="' + fisier + '"></div>');
	fereastra.document.close();
	fereastra.focus();
}

function gettrailobject()
{
	if(document.getElementById) return document.getElementById("imgpop");
	else if(document.all) return document.all.trailimagid;
}

function gettrailobj()
{
	if(document.getElementById)	return document.getElementById("imgpop").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 trailOff()
{
	document.onmousemove = '';
	gettrailobj().visibility = "hidden";
}

function trailOn(img, thw, thh)
{
	if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1)
	{
		gettrailobj().left = "-500px";
		divthw = parseInt(thw) + 2;
		gettrailobject().innerHTML = '<div style="background: #eeeeee; border: 1px solid #000000; padding: 10px; width: ' + divthw + 'px"><div style="background: #ffffff url(imagini/loading.gif) no-repeat; border: 1px solid #cccccc">' + '<img src="' + img + '" border="0" width="' + thw + '" height="' + thh + '"></div></div>';
		gettrailobj().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;
	}
	gettrailobj().left = xcoord + "px";
	gettrailobj().top = ycoord + "px";
}
