/**
 * Preload
 *
 * @package WordPress
 * @subpackage Supreme
 */

(function($) {

    $.preload = function(images, option) {
            
        var setting = $.extend({
            init: function(loaded, total) {},
            loaded: function(img, loaded, total) {},
            loadedAll: function(loaded, total) {}
        }, option),

        total = images.length,

        loaded = 0;

        setting.init(0, total);

        for (var i = 0; i < total; i++) {

            $('<img />').load(function() {
                loaded++;
                setting.loaded(this, loaded, total);
                if(loaded == total) {
                    setting.loadedAll(loaded, total);
                }
            }).attr('src', images[i]);

        }

    };

})(jQuery);

