/*//////////////////// piichi preloadimages.js [110624] */


(function($) {
  $.preLoadImages = {
    loaded:   new Array, //Images that have been loaded
    loading:  null,      //Image currently loading
    unloaded: new Array, //Images not yet loaded
    run: function () {
      //Load all the arguments into unloaded
      $(arguments).each(function(i,url) {
        $.preLoadImages.unloaded.push(url);
      });

      //Load the first image from unloaded, wait till its done loading,
      //then load another
      $.preLoadImages.interval = setInterval(function() {
        var loading = $.preLoadImages.loading;
          if(loading && loading.complete) {
            $.preLoadImages.loaded.push(loading);
            $.preLoadImages.loading = null;
          }
          else {
            var unloadedCount = $.preLoadImages.unloaded.length;
            if (! loading && unloadedCount > 0) {
              var newImage = document.createElement('img');
              newImage.src = $.preLoadImages.unloaded.shift();
              $.preLoadImages.loading = newImage;
            }
            else if (unloadedCount == 0) {
              clearInterval($.preLoadImages.interval)
            }
          }
      }, 100);
    }
  }
})(jQuery)


/*var cache = [];
$.preLoadImages = function() {
var args_len = arguments.length;
	for (var i = args_len; i--;) {
	  var cacheImage = document.createElement('img');
	  cacheImage.src = arguments[i];
	  cache.push(cacheImage);
	}
}

$.preLoadImages = function(){for(var i = 0; i<arguments.length; i++) { $("<img />").attr("src", arguments[i]);}}
*/
		
