﻿image1 = new Image();
iLoop = 0;
iMaxWidth = 0;
iMaxHeight = 0;
sTarget = "";

function WaitComplete()
{
	if (image1.complete)
	{
		setTimeout('Resize()', 100);
		return;
	}
		
	iLoop = iLoop + 1;
	if (iLoop < 1000)
		setTimeout('WaitComplete()', 100);
}

function Resize()
{
	iWidth = image1.width;
	iHeight = image1.height;
	
	if (iHeight > iMaxHeight)
	{
		fAspectRatio = image1.width / image1.height;
		iHeight = iMaxHeight;
		iWidth = iMaxHeight * fAspectRatio;
	}
	if (iWidth > iMaxWidth)
	{
		fAspectRatio = image1.width / image1.height;
		iWidth = iMaxWidth;
		iHeight = iMaxWidth / fAspectRatio;
	}
	
	image = document.getElementById(sTarget);
	
	image.src = image1.src;
	image.width = Math.round(iWidth);
	image.height = Math.round(iHeight);
}

function View(imgsrc, target, maxwidth, maxheight)
{
	image1 = new Image();
	image1.src = imgsrc;
	
	sTarget = target;
	iMaxWidth = maxwidth;
	iMaxHeight = maxheight;	

	image = document.getElementById(sTarget);
	image.src = '../Images/Preload.gif';
	image.width = 50;
	image.height = 50;
	
	iLoop = 0;
	WaitComplete();
}
