/**
 *
 * PLUGIN: jquery.autoResizeImages
 * BY: Mattias Norell
 * VERSION: 0.5 (based on jQuery 1.4.4)
 * BROWSERS: Safari 4, Chrome 7, Firefox 3.6
 * ABOUT: Auto resize images.
 * HOW-TO: $(img).autoResizeImages({maxSize:500});
 *
 **/
(function($){ 
    jQuery.fn.autoResizeImages = function(options) {
        var defaults = {
			maxSize:-1,
			orientation:'horizontal'
        };
		
        var options = $.extend(defaults, options);
		
		return this.each(function(){
			if($(this).width() > $(this).height() && options.orientation == 'horizontal'){
				if($(this).width() > parseFloat(options.maxSize)){
					var ratio = $(this).width() / $(this).height();
					$(this).css("width",options.maxSize);
					$(this).css("height",options.maxSize / ratio);
				}
			}else{
				if($(this).height() > parseFloat(options.maxSize) && options.orientation == 'portrait'){
					var ratio = $(this).height() / $(this).width();
					$(this).css("height",parseFloat(options.maxSize));
					$(this).css("width",parseFloat(options.maxSize) / ratio)
				}	
			}
		});
    };
})(jQuery); 
