var Tab = Class.create();

Tab.prototype = {
	initialize: function( fullMenu, tab, fullMenuItemClass, backClass, menuLine ){
		
		this.fullMenu = $( fullMenu );
		this.menuLine = $( menuLine );
		this.tab = $( tab );
		this.currentTab = null;
		
		$A(document.getElementsByClassName(fullMenuItemClass)).each(function(el){
			Event.observe(el,"click",this.onClick.bind(this, el),false);
		}.bind(this));

		$A(document.getElementsByClassName(backClass)).each(function(el){
			Event.observe(el,"click",this.onBackClick.bind(this),false);
		}.bind(this));
	},
	
	onBackClick: function(event){
		Event.stop(event);
		this.tab.hide();
		this.fullMenu.show();
	},

	onClick: function(el, event){
		Event.stop(event);
		var key = el.readAttribute( '_param' );
		var lineClass = el.readAttribute( '_class' );
		
		this.setTab( key, lineClass );
	},
	
	setTab: function( key, lineClass ){
		this.menuLine.className = lineClass;
		if( this.fullMenu.visible() ){
			this.fullMenu.hide();
			this.tab.show();
		}
		
		if( this.currentTab ){
			$( 'tab-' + this.currentTab ).hide();
			$( 'tab-bottom-' + this.currentTab ).hide();
		}
		
		$( 'tab-' + key ).show();
		$( 'tab-bottom-' + key ).show();
		
		this.currentTab = key;
	}
};
