(function($) {
	$.fn.resizeImage = function(settings) {
		var defaults = {
			maxHeight: 100,
			maxWidth: 100,
			onFinish: function() {}
		};

		var o = $.extend(defaults, settings || {});
	
		return this.each(function(e) {
			var ratio = o.maxHeight / o.maxWidth;
			
			if ( $(this).height() / $(this).width() > ratio){
				// height is the problem
				if ($(this).height() > o.maxHeight){
					$(this).css("width",Math.round($(this).width()*(o.maxHeight/$(this).height())));
					$(this).css("height", o.maxHeight);
				}
			} 
			else {
				// width is the problem
				if ($(this).width() > o.maxHeight){
					$(this).css("height", Math.round($(this).height()*(o.maxWidth/$(this).width())));
					$(this).css("width", o.maxWidth);
				}
			} 
		});
	}
})(jQuery);
