(function($) {
	
var pic_real_width;
var pic_real_height;

	
	
	$.fn.aeImageResize = function(options) {
		var params = jQuery.extend({
			height: 9,
			width: 9
		}, options);

		this.each(function() {
						   
			$(this).load(function() {
    // Remove attributes in case img-element has set width and height
    $(this).removeAttr("width")
           .removeAttr("height")
           .css({ width: "", height: "" }); // Remove css dimensions as well

    pic_real_width = this.width;
    pic_real_height = this.height;
});


						   
						   
						   
			var height = params.height,
				width = params.width,
				img_height = pic_real_height,
				img_width = pic_real_width,
				m_ceil = Math.ceil,
				m_floor = Math.floor;
				
	if (img_height >= img_width) {
		if (img_width>width) {
				width=width;
				height = m_floor(m_ceil(img_height / img_width  * width));

}else{
					width=img_width;
					height=img_height;
				} 
	
	} else {
			
			
			if (img_width>width) {
				width=width;
				height = m_floor(m_ceil(img_height /img_width * width));
				}else{
					width=img_width;
					height=img_height;
				} 
			
					}
		
			
			

			


		
			$(this).attr({
				'height': height,
				'width': width
			});
		});
	};
})(jQuery);
