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.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('img_box');
                this.fx = new Fx.Style(this.options.topImg, 'opacity', {duration:this.options.fade, onComplete: this.wait.bind(this) });
                this.fade();	
        },
 
        fade : function(){
        		this.botImg.setProperty('src',this.images[this.idx]);
                this.fx.start(1,0);
        },
 
        wait : function(){ 
                this.topImg.src = this.images[this.idx];
                this.topImg.setStyles({'opacity': 1, 'visibility' : 'visible'});
                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 );
