var mod_m2_tabs = new Class({
	
	Implements: [Events, Options],
	
	options: {
		targetDiv:'myDiv'		
	},
	
	show_panel: function(index) {			
		this.tabs[this.curr_panel_index].getParent('li').setProperty('class','tab_off');	
		this.tabs[index].getParent('li').setProperty('class','tab_on');
		this.curr_panel_index=index;
		this.next_panel=this.panels[index];
		this.last_panel.fade(0);		
	},	
	forward_panel: function() {							
		this.curr_panel_index=(this.curr_panel_index+1) % this.panels.length;		
		this.show_panel(this.curr_panel_index);		
	},		
	panel_events: function(curr_el) {							
		if (curr_el.get('opacity')=='0') {														
			this.last_panel.setStyle('display','none');						
			this.next_panel.setStyle('display','block');
			this.next_panel.fade(1);						
			this.last_panel=this.next_panel;							
		}		
	},
		
	initialize: function(options) {
		
		// Init options
		
		this.setOptions(options);
		
		this.tabs=$$(this.options.targetDiv+' .tabs_container .tabs li a');
		this.panels = $$(this.options.targetDiv+' .panels .panel');									
		
		// Init tabs
		
		this.tabs.each(function(curr_el,i) {								
				curr_el.addEvent('click', this.show_panel.bind(this,i));								
		},this);
		
		// Init panels
		
		this.panels.each(function(curr_el,i) {				
				
				if (i!=0)  { 					
					curr_el.setStyle('display','none'); 
					curr_el.set('opacity',0);					
				}															
				
				curr_el.get('tween').addEvent('complete',this.panel_events.bind(this,curr_el));
				
		},this);
		
		this.last_panel=this.panels[0];
		this.curr_panel_index=0;		
	}	
});
