function SequentialPreloader(id,images,callbackObj)
{
  this.current = 0;
  this.isDone = false;
  this.pause = false;
  if(id == null || images == null)
    return;
  this.id = id;
  this.callbackObj = callbackObj;
  this.images = images;
  this.init();
}
SequentialPreloader.prototype.setImages=function(images)
{
  this.images = images;
}
SequentialPreloader.prototype.setId=function(id)
{
  this.id = id;
}
SequentialPreloader.prototype.setCallbackObj=function(callbackObj)
{
  this.callbackObj = callbackObj;
}
SequentialPreloader.prototype.init = function()
{
  if(this.id == null || this.images == null)
    return;
  this.aImages = new Array;
  this.current = 0;
  this.isDone = false;
  this.pause = false;
  this.numImgs = this.images.length;
  for ( var i = 0; i < this.numImgs; i++ ){
    var tmpImg = new Image();
    tmpImg.onload=SequentialPreloader.prototype.onload;
    tmpImg.seqPreLdr = this;
    tmpImg.stop=false;
    tmpImg.index=i;
    this.aImages.push(tmpImg);
  }
  this.aImages[0].src=this.images[0];
}
SequentialPreloader.prototype.onload = function()
{
  if(this.seqPreLdr.pause && !this.stop)
    return;
  var obj = this;
// The setTimeout is used to prevent a Stack Overflow in IE
  setTimeout(function(){
    if(obj.seqPreLdr.callbackObj != null && obj.seqPreLdr.callbackObj.imageLoad)
      obj.seqPreLdr.callbackObj.imageLoad(obj.seqPreLdr.id,obj.index,obj);
    if(obj.index < (obj.seqPreLdr.numImgs-1)){
      obj.seqPreLdr.current = obj.index+1;
      obj.seqPreLdr.aImages[obj.seqPreLdr.current].src=obj.seqPreLdr.images[obj.seqPreLdr.current];
    }else{
      obj.seqPreLdr.isDone = true;
      if(obj.seqPreLdr.callbackObj != null && obj.seqPreLdr.callbackObj.onload)
        obj.seqPreLdr.callbackObj.onload(obj.seqPreLdr.id,obj.seqPreLdr.aImages);
    }
  });
}
SequentialPreloader.prototype.stop = function()
{
  this.pause = true;
}
SequentialPreloader.prototype.go = function()
{
  this.pause = false;
  if(this.aImages != null && this.aImages[this.current].complete)
    this.aImages[this.current].onload();
}
SequentialPreloader.prototype.setImages = function(images)
{
  for ( var i = 0; i < this.numImgs; i++ )
    this.aImages[i].stop=true;
  this.images = images;
  this.init();
}

