/**
 * ImageResize
 *
 * ImageResize.js is (c) 2011 Lemax d.o.o.
 * http://www.lemax.net/
 *
 */
(function(window, undefined) {
	ImageResize = function() { }
	ImageResize.bestFitInside = function(destWidth, destHeight, image) {
		image.style.display = "block";
		image.style.visibility = "visible";
		var destRatio = destWidth / destHeight;
		var targetRatio = image.width / image.height;
		if (destRatio == targetRatio) {
			image.width = destWidth;
			image.height = destHeight;
			return;
		}
		if (destRatio > targetRatio) {
			var w = parseInt(destHeight * targetRatio);
			image.width = w;
			image.height = destHeight;
			image.style.left = parseInt((destWidth - w) / 2) + "px";
			return;
		}
		var h = parseInt(destWidth / targetRatio);
		image.width = destWidth;
		image.height = h;
		try{image.style.top = parseInt((destHeight - h) / 2) + "px";}catch(e){}
	}
	ImageResize.bestFitOutside = function(destWidth, destHeight, image) {
		image.style.display = "block";
		image.style.visibility = "visible";
		var destRatio = destWidth / destHeight;
		var targetRatio = image.width / image.height;
		if (destRatio == targetRatio) {
			image.width = destWidth;
			image.height = destHeight;
			return;
		}
		if (destRatio < targetRatio) {
			var w = parseInt(destHeight * targetRatio);
			image.width = w;
			image.height = destHeight;
			image.style.left = parseInt((destWidth - w) / 2) + "px";
			return;
		}
		var h = parseInt(destWidth / targetRatio);
		image.width = destWidth;
		image.height = h;
		try{image.style.top = parseInt((destHeight - h) / 2) + "px";}catch(e){}
		return;
	}
	window.ImageResize = ImageResize;
})(window);


