var Tabs = Class.create({

	tabs : null,
	selectedTabId : '',
	namesHash : new Hash(),
	
	initialize :
	function ( tabs, selectedTabId)
	{
		this.tabs = tabs.clone();
		this.selectedTabId = selectedTabId;
		this.namesHash = this.namesHash.clone();	
		
		var thisObject = this;
		
		this.selectTab();
	},
	
	onClickTitle:
	function( event )
	{
		var element = Event.element( event );
		i = 0;
		
		if( element.tagName != 'H2' ) element = element.parentNode;
		
		this.selectedTabId = this.namesHash.get( element.id );
		this.selectTab();
	},
	
	selectTab:
	function(  )
	{
		var thisObject = this;
		this.tabs.each(
			function( s )
			{
				var title 	= "tab" + s + "Title";
				var content = "tab" + s + "Content";
				thisObject.namesHash.set( title, s );
				
				$( title ).observe( "click", thisObject.onClickTitle.bind( thisObject ));
				if( $( title ).hasClassName( 'on' ) )
				{
					$( title ).removeClassName( 'on' );
				}
				if( $( content ) == null ) alert( content );
				$( content ).hide();
			}
		);
		
		$( "tab" + this.selectedTabId + "Title" ).addClassName( 'on' );
		$( "tab" + this.selectedTabId + "Content").show();
	}
});
