/*
Image Rescale - Rescale all attached images
Works for IE7, FF3, Chrome, Safari, Opera
By: Chonla
Create Date: 13 August 2009
URL: http://blog.chonla.com
*/

(function($) {
	$.fn.imgrescale = function(options)
	{
		var defaults = {
			width: 50,
			height: 50
		};
		options = $.extend(defaults, options);
		this.each(function() {
			var o = $(this);
			var w = o.width();
			var h = o.height();

			var ratio = w/h;

			var width = 0;
			var height = 0;

			if (w < h)
			{	// tall image
				width = Math.round(options.height * ratio);
				height = Math.round(width / ratio);
			}
			else
			{	// wide image
				height = Math.round(options.width / ratio);
				width = Math.round(height * ratio);
			}

			o.width(width).height(height);
		});
	};
})(jQuery);

