
var Switcher = new Class({

  options: {
		duration: 200,
		wait: 5000
	},

  initialize: function(container){
		
		this.container = $(container);
		
		this.buttons = this.container.getElements('ul li');
		
		this.slides = this.container.getElements('div.info-text p');
		
		this.current = 0;
		
		this.count = this.buttons.length;
		
		this.timer = null;
		
		this.slideFx = new Array();
		this.slides.each(function(slide, index){
		  this.slideFx[index] = new Fx.Style(slide, 'opacity', { duration: this.options.duration, wait: false });
			if (index != 0) this.slideFx[index].set(0);
		}, this);
		
		this.container.addClass('ready');
		
		this.buttons.each(function(button, index){
		  button.addEvent('click', function(event){
				$clear(this.timer);
			  this.show(index);
			}.bind(this));
		}, this);
		
		this.timer = this.show.periodical(this.options.wait, this);
		
	},
	
	show: function(index){
		if (index == undefined) index = (this.current+1)%this.count;
		if (this.current != index){
			this.slideFx[this.current].start(0);
			this.buttons[this.current].removeClass('active');
			this.slideFx[index].start(1);
			this.buttons[index].addClass('active');
			this.current = index;
		}
	}

});

window.addEvent('domready', function() {
	
	if ($('block-bikes')) new Switcher('block-bikes');
	
});