var pimg  = new Image(); 

function ResizeImage()
{
	var R = Math.round((740 / 518)*Math.pow(10,3))/Math.pow(10,3);
	var R1= Math.round((pimg.width / pimg.height)*Math.pow(10,3))/Math.pow(10,3);
	if (R > R1) // need to trim height
	{
		var newW = 740;
		var newH = Math.round(740 / R1);
		var TopTrim = Math.round((newH - 518)/2);
		var BtmTrim = newH - 518 - TopTrim;
		//document.getElementById('PorjectImg').src = pimg.src;
		document.getElementById('PorjectImg').width = newW;
		document.getElementById('PorjectImg').height = newH;
		
		document.getElementById('ImgTD').style.borderBottom = '1px solid #FFFFFF';
		document.getElementById('ImgTD').style.borderTop = '1px solid #FFFFFF';
		
		document.getElementById('ImgDiv').style.marginTop = (TopTrim * -1);
		document.getElementById('ImgDiv').style.marginBottom = (BtmTrim * -1);
		}
		else // need to trim width
		{
		var newH = 518;
		var newW = Math.round(518 * R1);
		
		var LeftTrim = Math.round((newW - 740)/2);
		var RightTrim = newW - 740 - LeftTrim;
		//document.getElementById('PorjectImg').src = pimg.src;
		document.getElementById('PorjectImg').width = newW;
		document.getElementById('PorjectImg').height = newH;
		
		document.getElementById('ImgTD').style.borderLeft = '1px solid #FFFFFF';
		document.getElementById('ImgTD').style.borderRight = '1px solid #FFFFFF';
	
		document.getElementById('ImgDiv').style.marginLeft = (LeftTrim * -1);
		document.getElementById('ImgDiv').style.marginRight = (RightTrim * -1);
	}
	
}

function preloader(imgpath) 
{
	pimg.src = imgpath;
	if (pimg.width > 0)
	{
		ResizeImage();
	}
}