Rotator = new Class({
 
        options : {
                fade : 1500,
                timer : 2500
        },
 
        initialize: function(options){
        		var self = this;
 
        		this.idx = 1;
                this.setOptions(this.options, options);
 
                this.topImg = $(this.options.topImg);
                this.imgBox = $(this.options.imgBox);
                this.images = this.options.images;
               	this.images.unshift(this.topImg.src);
 
               	new Asset.images(this.images, {
               		onComplete : function(){
               				self.loaded();
               		}
               	});
 
        },
 
        loaded : function(){
        		    var self = this;
                this.botImg = new Element('img').setProperties({'id':'background_rotation_image','src' : this.images[this.idx]})
                								.injectInside(this.imgBox);
                this.waitID = this.fade.delay(this.options.timer,this);
                
        },
 
        fade : function(){
            $(this.options.topImg).fade('show');
            this.botImg.setProperty('src',this.images[this.idx]);
            this.fx = new Fx.Tween(this.options.topImg,{property: 'opacity', duration:this.options.fade, onComplete: this.wait.bind(this) });
            this.fx.start(1,0);
        },
 
        wait : function(){ 
                
                $(this.options.topImg).fade('hide');
                $(this.options.topImg).src = this.images[this.idx];
                this.changeImage();
                this.wait.bind(self);
                this.waitID = this.fade.delay(this.options.timer,this);
        },
 
 
        changeImage : function(){
           this.idx = ( this.idx == this.images.length-1 ) ? 0 : ++this.idx;
        }
});
 
Rotator.implement( new Options );
