var Preloader_XRC = {
  callbacks: [],
  images: [],
  names: [],
  loadedImages: [],
  imagesLoaded: 0,

  add: function(image, name){
    //DebugText("add(" + typeof image + ") = " + image.length);
    if (typeof image == 'string') this.images.push(image);
    if (typeof image == 'array' || typeof image == 'object'){
      for (var i=0; i< image.length; i++){
        this.images.push(image[i]);
        this.names.push(name);
      }
    }
  },
  onFinish: function(func){
    if (typeof func == 'function') this.callbacks.push(func);
    if (typeof func == 'array' || typeof func == 'object'){
      for (var i=0; i< func.length; i++){
        this.callbacks.push(func[i]);
      }
    }
  },
  load: function(){
    //DebugText("load()");
    for(var i=0; i<this.images.length; i++){
      this.loadedImages[i] = new Image();
      this.loadedImages[i].onload = function(){ Preloader_XRC.checkFinished.apply(Preloader_XRC) }
      this.loadedImages[i].src = this.images[i];
    }
  },

  checkFinished: function(){
    this.imagesLoaded++;
    //DebugText("Loaded: " + this.imagesLoaded);
    if (this.imagesLoaded == this.images.length) this.fireFinish();
  },
  fireFinish: function(){
    for (var i=0; i<this.callbacks.length; i++){
      this.callbacks[i]();
    }
    this.images = [];
    this.loadedImages = [];
    this.imagesLoaded = 0;
    this.callbacks = [];
  },

  getWidth: function(name)
  {
     for (var i = 0; i < this.names.length; i++)
     {
        if (this.names[i] == name)
        {
           return(this.loadedImages[i].width);
        }
     }
  },
  getHeight: function(name)
  {
     for (var i = 0; i < this.names.length; i++)
     {
        if (this.names[i] == name)
        {
           return(this.loadedImages[i].height);
        }
     }
  }
}

Preloader_XRC.add("images/topbannernew.jpg");
Preloader_XRC.add("images/stars.jpg");
Preloader_XRC.add("images/lettherebelight.jpg");
Preloader_XRC.add("images/sponsor/castle.jpg");
Preloader_XRC.add("images/sponsor/teamassociated.jpg");
Preloader_XRC.add("images/sponsor/aka.gif");
Preloader_XRC.add("images/sponsor/mdx.gif");
Preloader_XRC.add("images/sponsor/harrington.gif");
Preloader_XRC.add("images/sponsor/rclights.gif");
Preloader_XRC.add("images/sponsor/teamtekin.gif");
Preloader_XRC.add("images/sponsor/extremerc.gif");
Preloader_XRC.add("images/mussers_logo.jpg");
Preloader_XRC.add("images/harrington_logo.jpg");

Preloader_XRC.load();

