var saveWidth = 0;
var saveHeight = 0;

function scaleImg(what)
{

var ratio = 1;

what = document.getElementById(what);

if (what.width > maxWidth || what.height > maxHeight)
{
if ((maxHeight / what.height) <= (maxWidth / what.width))
{
saveWidth = what.width;
saveHeight = what.height;
ratio = what.width / what.height;
what.height = maxHeight;
what.width = maxHeight * ratio;
what.style.cursor = "pointer";
}
else
{
saveWidth = what.width;
saveHeight = what.height;
ratio = what.height / what.width;
what.height = maxWidth * ratio ;
what.width = maxWidth;
what.style.cursor = "pointer";
}
}
else if (saveWidth > maxWidth || saveHeight > maxHeight)
{
what.width = saveWidth;
what.height = saveHeight;
what.style.cursor = "pointer";
}

}