imagePreload = Class.create({
  initialize: function(url, params, replace) {
    this.id = '_preload_' + String(Math.random()).substring(2,15);
    this.orientation = 'FIT';
    this.image_size = 60
    
    if(params){
      if (typeof params.onload == 'function') this.onLoad = params.onload;
      if (typeof params.onerror == 'function') this.onError = params.onerror;
      if (typeof params.id == 'string') this.image_id = params.id;
      if (typeof params.orientation == 'string') this.orientation = params.orientation;
      if (typeof params.size == 'string') this.image_size = params.size;
    }
    
    if(replace == undefined || !replace){
      document.write('<span id="' + this.id + '"></span>');
      this.element = $(this.id);
    }else{
      this.element = $(this.image_id);
    }
    
    this.image = new Image();
    this.image.onload = this.onLoad.bindAsEventListener(this);
    this.image.onerror = this.onError.bindAsEventListener(this);
    this.image.name = url;
    this.image.src = url;
    this.image.id = this.image_id;
  },

  onLoad: function(e){
    this.element.insert(this.image);
    this.element.insert('<p><b>Image:</b>' + this.image.src + '</p>');
    this.element.insert(this.image.width + 'x' + this.image.height);
  },

  onError: function(e){
  }
});
