// Rotator
// Dat Chu - CBL Lab
var Rotator = Class.create();

Rotator.prototype = {
	prev: '',
	next: '',
	targets: '',
	effects: '',
	delay: 6000,
	initialize: function(targets, isStartRandom){
		this.targets = targets;
		this.buildEffects((isStartRandom?true:false));
        	this.rotate.periodical(this.delay);
	},
	buildEffects: function(isStartRandom){
		//random starting point
		this.prev = (!isStartRandom) ? 0 : (Math.floor(Math.random() * this.targets.length));
		this.next = (this.prev+1) % this.targets.length;
		eff = new Array;
		for(i=0;i<this.targets.length;i++)
		{
			eff[i] = new Fx.Opacity(this.targets[i],{duration:1000});
			if (i!=this.prev) eff[i].hide();
		}
		this.effects = eff;
	},
	rotate: function(){
		this.effects[this.prev].toggle(); //hide prev
		this.effects[this.next].toggle(); //show next
		//repeat
		this.prev = this.next;
		this.next = (this.next +1) % this.effects.length;
	}
};
