var Tabs = new Class({	
	Implements: Options,
	options: {
		duration:400,
		transition: Fx.Transitions.Quint.easeInOut
	},
	current:$empty,
	initialize: function(container, options){
		this.setOptions(options || {});
		
		this.container = $(container);

		this.buttons = this.container.getElement('.tab_buttons').getChildren();
		this.tabs = this.container.getElements('.tab');
		
		this.current = this.buttons[0];
		this.buttons.addClass('tab_unselected');
		this.buttons[0].addClass('tab_selected');
		
		this.tabs.addClass('tab_hide');
		this.tabs[0].removeClass('tab_hide');
		
		this.tabs_panel = this.container.getElement('.tab_panels');
		
		this.fx = new Fx.Tween(this.tabs_panel,{ link:'chain', property:'opacity', duration:this.options.duration, transition: this.options.transition });
		//Binding buttons
		this.buttons.each(function(el,idx){
			el.addEvent('click',function(){
				this.switchtab(el,idx);
			}.bindWithEvent(this));
		}.bind(this));
	},
	switchtab:function(el,idx){
		if(idx < this.tabs.length){
			this.fx.start(0).chain(function(){
				this.current.morph('.tab_unselected'); 
				el.morph('.tab_selected');
				this.current = el;
				this.tabs.addClass('tab_hide');
				this.tabs[idx].removeClass('tab_hide');
				this.fx.start(1);
			}.bind(this));
		}
	}
});