code: function preloader(items, preloadFunction, callback) {
  
      var itemc = 0;
      var loadc = 0;
  
      // called by preloadFunction to notify result
      function _check(err, id) {
          updateProgress(1);
          if (err) {
              alert('Failed to load ' + id + ': ' + err);
          }
          loadc++;
          if (itemc == loadc) callback();
      }
  
      if (items.constructor == Array) {
          itemc = items.length;
          loadc = 0;
          progressTotalCount += items.length;
          // queue each item for fetching
          items.forEach(function (item) {
              preloadFunction(item, _check);
          });
      } else {
          // object
          for (var key in items) {
              itemc++;
              progressTotalCount++;
              preloadFunction(items[key], _check);
          }
      }
  }
docs: Generic preloader handler, it calls preloadFunction for each item and passes function to it that it must call when done.