(function ($) {
  $.fn.rsz = function (options) {
    var defaults = {
      maxWidth: 110,
      // Max width for the image
      maxHeight: 115 // Max height for the image
    };
    var options = $.extend(defaults, options);
    return this.each(function () {
      obj = $(this);
      // Nulling widht and height
      var width = 0;
      var height = 0;
      // Get image parameters, and calculate scale
      var width = obj.width();
      var height = obj.height();
      var x_scale = width / options.maxWidth;
      var y_scale = height / options.maxHeight;
      if (y_scale > x_scale) {
        new_height = Math.ceil(height * (1 / y_scale));
        new_width = Math.ceil(width * (1 / y_scale));
        obj.css("height", new_height);
        obj.css("width", new_width);
      } else {
        new_height = Math.ceil(height * (1 / x_scale));
        new_width = Math.ceil(width * (1 / x_scale));
        obj.css("height", new_height);
        obj.css("width", new_width);
      }
    });
  };
})(jQuery);