/*
* Resize, A resize plugin for jQuery
* Intructions: $(seletor).resize(max_size)
* By: Carlos Alessandro Sena de Freitas - veneinzuela@gmail.com
* Version: 1.0
* Updated: September 1st, 2011
*
* Updated specifically for TMN2010 by Marc, October 23rd, 2011
* Licensed under the GNU - General Public License
* You may obtain a copy of the License at
*
* http://www.gnu.org/copyleft/gpl.html
*
* Function renamed to resizeImg to solve a conflict with the (window) resize event
*/
(function ($) {
    $.fn.resizeImg = function (max_size) {
        return this.each(function () {
            $(this).load(function () {
                // only resize when image is in fact larger than the max size
                if ($(this).height < max_size && $(this).width < max_size) {
                    return;
                }
                // find if it's in landscape or portrait orientation
                if ($(this).height() > $(this).width()) {
                    var h = max_size;
                    var w = Math.floor($(this).width() / $(this).height() * max_size);
                }
                else {
                    var w = max_size;
                    var h = Math.floor($(this).height() / $(this).width() * max_size);
                }
                // apply new css rules
                $(this).css({ 'height': h, 'width': w });
            });
        });
    };
})(jQuery);
