
function resizeImage(whichId, max) {
	
  var image = document.getElementById(whichId);

	image.removeAttribute('width');
	image.removeAttribute('height');
	var width = image.naturalWidth || image.width;
	var height = image.naturalHeight || image.height;

	ratio = Math.min( max / width, max / height );
	
	if (width > max) {
		width = ratio * width;
		height = ratio * height;		
	}

	image.width = width;
	image.height = height;
}
