function fixPNG(element)
{
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		var src;
		
		if (element.tagName=='IMG')
		{
			if (/\.png$/.test(element.src))
			{
				src = element.src;
				element.src = "/elements/spacer.gif";
			}
		}
		else
		{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
}

nn4 = (document.layers) ? true : false;
ie4 = (document.all) ? true : false;
dom = (document.createTextNode)? true : false;

// 
function popupWindow(fileUrl, winW, winH, winN, scrollB) {
	var winWidth = (winW)? winW : 800;
	var winHeight = (winH)? winH : 520;
	var winName = (winN)? winN : 'popupWin'
	var scrollBars = (scrollB)? scrollB : 'auto'
	if (nn4 || ie4 || dom) {
		if (screen.width < winWidth + 50) { winWidth = screen.width - 50; scrollbars = 'yes' }
		if (screen.height < winHeight + 100) { winHeight = screen.height - 100; scrollbars = 'yes' }
		posX = Math.round((screen.width - winWidth) / 2);
		posY = Math.round((screen.height - winHeight) / 2);
		posCode = (nn4)? "screenX="+posX+",screenY="+posY : "left="+posX+",top="+posY;
	} else {
		posCode = "";
	}
	var popupWin = window.open(fileUrl, winName, "menubar=no,toolbar=no,scrollbars=" + scrollBars + ",status=yes,resizable=yes,width=" + winWidth + ",height=" + winHeight + "," + posCode);
	if (popupWin) popupWin.focus();
}

// 
function popupPic(winW, winH, winTitle, winFile) {
	var winWidth = (winW)? winW : 740;  // size X
	var winHeight = (winH)? winH : 520; // size Y 520
	if (nn4 || ie4 || dom) {
		if (screen.width < winWidth + 50) { winWidth = screen.width - 50; scrollbars = 'yes' }
		if (screen.height < winHeight + 100) { winHeight = screen.height - 100; scrollbars = 'yes' }
		posX = Math.round((screen.width - winWidth) / 2);
		posY = Math.round((screen.height - winHeight) / 2)-60;
		posCode = (nn4)? "screenX="+posX+",screenY="+posY : "left="+posX+",top="+posY;
	} else {
		posCode = "";
	}
	var w=window.open(winFile, '', config='height='+winHeight+',width='+winWidth+',menubar=0,statusbar=0,scrollbars=1,resizable=1,dependent=1,'+posCode);
	w.document.open();
	w.document.write('<html><head><title>'+winTitle+' '+winWidth+'x'+winHeight+' </title></head><body style="background:white; height:100%; margin:0; padding:0;"><table style="width:100%; height:100%; text-align:center;"><tr><td><a href="#" style="display:block;" onclick="javascript:window.close();"><img src="'+winFile+'" alt="'+winTitle+'" title="'+winTitle+'" border="0" style=""></a></td></tr></table></body></html>');
	if (w) w.focus();
	w.document.close();
}

var ua = navigator.userAgent.toLowerCase();
var divw=0;
var divh=0;
var xto;

if (document.getElementById || document.all)
	document.write('<div id="imgtrailer" style="position:absolute;visibility:hidden;"></div>')

function gettrailobject()
	{
	if (document.getElementById)
		return document.getElementById("imgtrailer")
	else if (document.all)
		return document.all.trailimagid
	}

function gettrailobj()
	{
	if (document.getElementById)
		return document.getElementById("imgtrailer").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()
	{
		if (xto && xto > 0)
		{
			clearTimeout(xto);
		}

		document.onmousemove='';
		gettrailobj().visibility="hidden";
	}

function trailOn(engine_size,engine_power,engine_type,transmission,drive,country,control_wheel,thw,thh){
		if (navigator.userAgent.indexOf("Opera")==-1)
	{
		
		gettrailobj().left="-500px";
		divthw = parseInt(thw) + 2;
		smthw = parseInt(thw) + 2;			
		halfthh = 50;
		halfthh = Math.ceil(parseInt(thh)/2);
		topx = halfthh - 9;
		smthh = parseInt(thh) + 2;	
		if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1)
			gettrailobject().innerHTML = '<div class="shadow"><table style="width:200px; height:130px; border:1px solid #B2B2B2; font-family:Arial, Helvetica, sans-serif; font-size:11px;" cellpadding="0" cellspacing="0"><tr><td style="background:#F5F5F5; color:#178AA9; text-align:right; width:80px; padding:1px;">Объём дв.:</td><td style="background:#F5F5F5; padding-left:10px;">'+engine_size+'</td></tr><tr><td style="background:#ECECEC; color:#178AA9; text-align:right; width:80px; padding:1px;">Мощность:</td><td style="background:#ECECEC; padding-left:10px;">'+engine_power+' л.с.</td></tr><tr><td style="background:#F5F5F5; color:#178AA9; text-align:right; width:80px; padding:1px;">Тип дв.:</td><td style="background:#F5F5F5; padding-left:10px;">'+engine_type+'</td></tr><tr><td style="background:#ECECEC; color:#178AA9; text-align:right; width:80px; padding:1px;">КПП:</td><td style="background:#ECECEC; padding-left:10px;">'+transmission+'</td></tr><tr><td style="background:#F5F5F5; color:#178AA9; text-align:right; width:80px; padding:1px;">Привод:</td><td style="background:#F5F5F5; padding-left:10px;">'+drive+'</td></tr><tr><td style="background:#ECECEC; color:#178AA9; text-align:right; width:80px; padding:1px;">Страна:</td><td style="background:#ECECEC; padding-left:10px;">'+country+'</td></tr><tr><td style="background:#F5F5F5; color:#178AA9; text-align:right; width:80px; padding:1px;">Руль:</td><td style="background:#F5F5F5; padding-left:10px;">'+control_wheel+'</td></tr></table></div>';

		if (navigator.userAgent.indexOf("MSIE")!=-1)
			gettrailobject().innerHTML = '<table style="width:200px; height:130px; border:1px solid #B2B2B2; font-family:Arial, Helvetica, sans-serif; font-size:11px; FILTER: progid:DXImageTransform.Microsoft.Shadow(color=\'gray\', Direction=150, Strength=5);" cellpadding="0" cellspacing="0"><tr><td style="background:#F5F5F5; color:#178AA9; text-align:right; width:80px; padding:1px;">Объём дв.:</td><td style="background:#F5F5F5; padding-left:10px;">'+engine_size+'</td></tr><tr><td style="background:#ECECEC; color:#178AA9; text-align:right; width:80px; padding:1px;">Мощность:</td><td style="background:#ECECEC; padding-left:10px;">'+engine_power+' л.с.</td></tr><tr><td style="background:#F5F5F5; color:#178AA9; text-align:right; width:80px; padding:1px;">Тип дв.:</td><td style="background:#F5F5F5; padding-left:10px;">'+engine_type+'</td></tr><tr><td style="background:#ECECEC; color:#178AA9; text-align:right; width:80px; padding:1px;">КПП:</td><td style="background:#ECECEC; padding-left:10px;">'+transmission+'</td></tr><tr><td style="background:#F5F5F5; color:#178AA9; text-align:right; width:80px; padding:1px;">Привод:</td><td style="background:#F5F5F5; padding-left:10px;">'+drive+'</td></tr><tr><td style="background:#ECECEC; color:#178AA9; text-align:right; width:80px; padding:1px;">Страна:</td><td style="background:#ECECEC; padding-left:10px;">'+country+'</td></tr><tr><td style="background:#F5F5F5; color:#178AA9; text-align:right; width:80px; padding:1px;">Руль:</td><td style="background:#F5F5F5; padding-left:10px;">'+control_wheel+'</td></tr></table>';
		
		//setTimeOut
		
		gettrailobj().visibility="visible";
		divw = parseInt(thw)+30;
		divh = parseInt(thh)+60;
		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"
}
