var ImageRotator = Class.create({
	data: null,
	speed: 2,
	current: 0,
	rotate: false,
	rand: true,
	container: '#feature .textElement',
	selector: '#feature .textElement img',
	initialize: function(){
		//if(!$('adminbar'))
			this.getImages();
	},
	getImages: function(){
		$$(this.container)[0].hide();
		//$$(this.container)[0].style.position='relative';
		this.data = $$(this.selector);
		this.data.each( function(image,index){ 
			image.id = 'image_'+index;
			//image.style.position='absolute';
			//if( index!= 0 )
			image.hide();
		});
		if(this.rand)
			this.setRandomImage();
		if(this.rotate)
			setTimeout('IR.showNext()',this.speed*1000);
		$$(this.container)[0].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(); });