﻿var PACKFLASH = {};

PACKFLASH.imageResize = function() {};

PACKFLASH.imageResize.prototype = {
    resizeImagesToWidth: function(container, width) {
        var container_to_resize = '#' + container;
        var max_width = width;

        jQuery(container_to_resize).each(function() {
            var width = jQuery(this).width();
            var height = jQuery(this).height();

            //If the width exceeds max set above, resize it.
            if (width > max_width) {
                var ratio = (height / width);
                var new_width = max_width;
                var new_height = (new_width * ratio);

                jQuery(this).height(new_height).width(new_width);
            }
        }
        );
    },

    resizeImagesToHeight: function(container, height) {
        var container_to_resize = '#' + container;
        var max_height = height;

        jQuery(container_to_resize).each(function() {
            var width = jQuery(this).width();
            var height = jQuery(this).height();

            //If the height exceeds max set above, resize it.
            if (height > max_height) {
                var ratio = (width / height);
                var new_height = max_height;
                var new_width = (new_height * ratio);

                jQuery(this).height(new_height).width(new_width);
            }
        }
        );
    }
};
