/* changes an image to fit within a certain widthxheight */

function ensureDimensions(oImg, iWidth, iHeight) {
	if (oImg.width && oImg.height) {
		/* the image has these properties */
		if (oImg.width > oImg.height) {
			fixWidth(oImg, iWidth);
			fixHeight(oImg, iHeight);
		} else {
			fixHeight(oImg, iHeight);
			fixWidth(oImg, iWidth);
		}
	}
}

function fixWidth(oImg, iWidth) {
	if (oImg.width > iWidth) {
		oImg.width = iWidth;
		oImg.height = oImg.height * (iWidth / oImg.width);
	}
}

function fixHeight(oImg, iHeight) {
	if (oImg.height > iHeight) {
		oImg.height = iHeight;
		oImg.width = oImg.width * (iHeight / oImg.height);
	}
}
