/*
	Class:    	Servizi Tab
	Author:   	Marco Dell'Anna
	Website:    #
	Version:  	1.0
	Date:     	07/09/2010
	Built For:  MooTools 1.2
*/

var Tabs = new Class({
	active:"",
	activeId:"",
	Implements: Options,
    options: { 
			itemleave:""
	  },
	//Function run when class is created
	initialize : function(a, options){
		this.setOptions(options);
		this.tab    = $$('#' + a + " a") 
		this.panels = Array();
		this.tab.each(function(el,indice){
			// Aggiunge link id Name
			this.panels.push( $( el.getAttribute('href',2).substr(1) ) );
			
			// Visualizza Pannello
			el.addEvent('click', function(e){
				e.stop()
				//Attiva pannello
				this.setActivePanels( indice );
			}.bind( this ));
			
		}.bind( this ))
		
		// Attica pannello
		this.setActivePanels( 0 );
	},
	
	setActivePanels: function( id ){
		// Imposta elemento attivo
		this.activeId = id;
		
		this.hideAllPanels();
		this.hideAllTabs();
		// Set Attivo
		this.tab[id].addClass("active-tab");
		this.panels[id].setStyle("display","block").set('opacity',0).fade("in");
	},	

	hideAllPanels: function(){
		$each( this.panels, function(e, i){
			e.setStyle("display","none");
			e.hide();
		});
	},
	
	hideAllTabs: function(){
		$each( this.tab, function(e, i){
			e.removeClass("active-tab");
		});
	}
});
