
(function($) {
    $.fn.resizeToScale = function(options) {
        var settings = {
            width: 50,
            height: 50
        };

        if (options) {
            $.extend(settings, options);
        }
        var functions = {
            zoomDimensions: function(elem, w_max, h_max) {

                w = elem.width;
                h = elem.height;

                widthRatio = (w_max / w);
                heightRatio = (h_max / h);

                ratio = widthRatio < heightRatio ? widthRatio : heightRatio;

                w_new = w * ratio;
                h_new = h * ratio;
                return { width: w_new, height: h_new }
            }
        }

        w_max = settings.width;
        h_max = settings.height;

        return this.each(function() {
            $(this).each(function(i, elem) {
                $(elem).css(functions.zoomDimensions(elem, w_max, h_max));
            });
        });
    };

    $.fn.image = function(src) {
        return this.each(function() {
            var i = new Image();
            i.src = src;
            this.appendChild(i);
        })
    };
})(jQuery);

