Rotator = new Class({
     
	options : {
	    fade : 500,
	    timer : 4500
	},
     
	initialize: function(options){
	    var self = this;
     
	    this.idx = 0;
	    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', {
		    'id': 'background_rotation_image',
		    'src': this.images[this.idx]}
		).injectInside(this.options.imgBox);
	    this.changeImage();
	    this.topImg.setProperty('src',this.images[this.idx]);
	    this.fx = new Fx.Tween(this.botImg, {property: 'opacity', duration:this.options.fade, onComplete: this.wait.bind(this)});
	    this.waitID = this.fade.delay(this.options.timer/2,this);
	},
     
	fade : function(){
	    this.fx.start(1,0.01);
	},
     
	wait : function(){ 
	    this.botImg.setProperty('src', this.images[this.idx]);
	    this.botImg.setStyles({'opacity': 1});
	    this.changeImage();
	    this.topImg.setProperty('src',this.images[this.idx]);
	    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 );
