function ImageLoader(array,onStep,onComplete)
{
    this.tempImage = new Image();
    this.tempImage.iterator = 0;
    this.tempImage.images = array;
    this.tempImage.onStep = onStep;
    this.tempImage.onComplete = onComplete;
    
    $(this.tempImage).addEvent('load',function(){
                //alert(this + " " + this.parent);
                this.onStep();
                this.loadNext();
            });
    $(this.tempImage).addEvent('error',function(){
                alert("Image '"+ this.src +"' error!");
                this.iterator++;
                if(this.images[this.iterator] != undefined)
                {
                 //   $('info').innerHTML += this.images[this.iterator];                        
                    this.loadImage(this.images[this.iterator]);                
                }
                else
                {
                    this.onComplete();
                }
            });
    
    this.tempImage.loadImage = function loadImage(src){
                                this.src = src;
                };
    this.tempImage.loadNext = function(){
            this.iterator++;
            if(this.images[this.iterator] != undefined)
            {
                //$('info').innerHTML += this.images[this.iterator];                        
                this.loadImage(this.images[this.iterator]);                
            }
            else
            {
                this.onComplete();
            }
        }
    this.tempImage.loadAll = function(){
            var imgObjects = new Array();
            for(var i=0;i<this.images.length;i++)
            {
                var tmp = new Image();
                tmp.src = this.images[i];
                //imgObjects.push(new Image())
            }
            this.onComplete();
        }
}
ImageLoader.prototype.startLoading = function startLoading()
                {
                    //$('info').innerHTML += "Starting loading: <small> "+  this.tempImage.images.toString().replace(",","<p>")+"<BR>";
                    this.tempImage.iterator = 0;
                    this.tempImage.loadNext();
                };
ImageLoader.prototype.startLoadingS = function startLoadingS()
                {                    
                    this.tempImage.loadAll();
                };
                
ImageLoader.prototype.getI = function getI()
                {
                    return this.tempImage.iterator;
                }
ImageLoader.prototype.getAll = function getAll()
                {
                    return this.tempImage.images.length;
                }
