

(function($) {

    $.fn.imgCenter = function() {

        return this.each(function() {

            var self = $(this);
            var parent = self.parent();

            self.width(parent.width());

            if (self.height() < parent.height()) {
                self.height(parent.height());
                self.width("auto");
            }

            self.css("margin-left", -(self.width() - parent.width()) / 2);
            self.css("margin-top", -(self.height() - parent.height()) / 2);
            
        });

    };

})(jQuery);
