(function($) {
    var imgList = [];
    $.extend({
        preload: function(imgArr, option,count) {
            var setting = $.extend({
                init: function(loaded, total) {},
                loaded: function(img, loaded, total) {},
                loaded_all: function(loaded, total) {}
            }, option);
            //var total = imgArr.length;
            var total = count;
            var loaded = 0;
            var id = 0;
            setting.init(0, total);
            for(var i = 0; i < count; i++) {
                var temp = imgArr.novita[i];
                var filename = temp.filename;
                var pdf = temp.pdf;
                var video = temp.video;
                imgList.push($("<img />")
                .attr("src", "/images/documenti/" + filename)
                .attr("pdf",pdf)
                .attr("video",video)
                .css("display","none")
                .attr("class","preload slideshow")
                .attr("id","slshow" + id++)
                .load(function() {
                    loaded++;
                    setting.loaded(this, loaded, total);
                    if(loaded == total) {
                        setting.loaded_all(loaded, total);
                    }
                }));
            }
        }
    });
})(jQuery);
