function ImageCache() {
  if (this.onInstance) this.onInstance.apply(this, arguments);
}





/* Encapsulation */ (function() {


// -------
// ImageCache
// -------

// onInstance
//

ImageCache.prototype.onInstance = function() {
  var containerId = "imageCacheContainer";
  var container = document.getElementById(containerId);

  if (!container) {
    container = document.createElement("div");
    container.id = containerId;
    container.style.position = "absolute";
    container.style.top = "0";
    container.style.left = "0";
    container.style.width = "0";
    container.style.height = "0";
    container.style.overflow = "hidden";
    container.style.visibility = "hidden";

    var body = document.getElementsByTagName("body")[0];
    body.appendChild(container);
  }

  this.container = container;
  this.queue = [];
  this.processHandle = 0;
}



// add
//

ImageCache.prototype.add = function() {
  var url, i=0;
  while (url = arguments[i++]) this.queue.push(url);
}



// fetch
//

ImageCache.prototype.fetch = function() {
  var delay = 2000;
  var self = this;
  setTimeout(function() {self.spawnProcessor()}, delay);
}



// processQueue
//

ImageCache.prototype.processQueue = function() {
  var url = this.queue.shift();
  if (!url) {
    clearInterval(this.processHandle);
    this.processHandle = 0;
    return;
  }

  var img = document.createElement("img");
  img.src = url;
  this.container.appendChild(img);
}



// spawnProcessor
//

ImageCache.prototype.spawnProcessor = function() {
  if (this.processHandle) return;
  var interval = 50;
  var self = this;
  this.processHandle = setInterval(function() {self.processQueue()}, interval);
}





})(); /* Encapsulation */
