function resizeImgSub(img, nWidth) {
	if (img.width > nWidth) {
		img.visibleImgObj.width = nWidth;
		img.visibleImgObj.height = Math.round((img.height * nWidth) / img.width);
	}
	else {
		img.visibleImgObj.width = img.width;
		img.visibleImgObj.height = img.height;
	}
}

function resizeImg(imgObj, nWidth) {
	var imgOriginal = new Image();
	imgOriginal.visibleImgObj = imgObj;
	imgOriginal.onload = function() { resizeImgSub(this, nWidth); }  
	imgOriginal.src = imgObj.src;
}
