var ImageRotator = Class.create({
	data: null,
	speed: 8,
	current: 0,
	rotate: true,
	rand: false,
	container: 'javascript_rotator',
	selector: '#javascript_rotator .element',
	initialize: function(){
			if( !$('adminbar') ){
				$(this.container).addClassName('active-rotator');
				this.getImages();
			}
	},
	getImages: function(){
		$(this.container).hide();
		this.data = $$(this.selector);
		this.data.each( function(image,index){ 
			image.id = 'image_'+index;
			if( index!= 0 )
				image.hide();
		});
		if(this.rand)
			this.setRandomImage();
		if(this.rotate)
			setTimeout('IR.showNext()',this.speed*1000);
		$(this.container).show();
	},
	setRandomImage: function(){
		var randnum = Math.floor(Math.random()*(this.data.length));
		this.current=randnum;
		$('image_'+randnum).show();
	},
	showNext: function(){
		Effect.Fade('image_'+this.current)
		if( this.current >= ($$(this.selector).length-1) ){
			this.current = 0;
		}else{
			++this.current;
		}
		Effect.Appear('image_'+this.current);
		setTimeout('IR.showNext()',this.speed*1000);
	}
});

document.observe('dom:loaded',function(){ IR = new ImageRotator(); });