var RotatingFeature = new Class({
	Implements: Options,
	first_run: true,
	current_fade_in: 0,
	options: {
		pause: 10000,
		loop: true,
		onComplete: Class.empty,
		onStart: Class.empty
	},
	initialize: function(container,options) {
		this.setOptions(options);
		this.container = $(container);
		this.imgs = this.container.getElements('img');
		this.imgs.setStyles({
		'position':'absolute',
		'top':0,
		'left':0,
		'opacity':0,
		'display':''
		});
		this.imgs[0].setStyle('opacity',1);
		this.el = new Element('div',{'styles': {
		'position':'relative'
		}});
		this.el.injectInside(this.container);
		this.el.adopt(this.imgs);
		this.next = 0;
		//this.start();
	},
	start: function() {
		if(!this.first_run)this.show();
		else first_run = false;

		this.periodical =this.show.bind(this).periodical(this.options.pause);
	},
	stop: function() {
		$clear(this.periodical);
	},
	show: function() {
		if (!this.options.loop && this.next==this.imgs.length-1)
		{
			this.stop();
		}

		this.next = (this.next==this.imgs.length-1)?0:this.next+1;
		var prev = (this.next==0)?this.imgs.length-1:this.next-1;

		this.imgs[this.next].fade('in');
		this.imgs[prev].fade('out');

		//	alert(this.next);
		//$('feature_'+this.next).addClass('active');

		//$('feature_'+prev).removeClass('active');
		this.current_fade_in = this.next;


	},
	showFeature: function(feature_id)
	{

		this.stop();
		if (!this.options.loop && this.next==this.imgs.length-1)
		{
			this.stop();
		}



		this.imgs[feature_id].fade('in');
		//$('feature_'+feature_id).addClass('active');

		if(this.current_fade_in != feature_id)
		{
			if(this.current_fade_in >= 0)
			{
				this.imgs[this.current_fade_in].fade('out');
				//$('feature_'+this.current_fade_in).removeClass('active');
			}
		}

		this.current_fade_in = feature_id;

		//this.imgs[prev].fade('out');
	}

});
