/**
 * JavaScript für die Tabs
 */
 
/**
 * Klasse für das Registrieren von Tabs
 *
 * @param string tabs_id ID des UL-Elements, das die Tabs enthält
 */
function Tabs( tabs_id )
{
	this.id 		= tabs_id;
	this.tabs 		= [];
	
	/**
	 * Initialisiert die Tabs
	 */
	this.init = function()
	{
		var tab_ul = document.getElementById( this.id );
		
		if ( !tab_ul )
			return;
		
		var self = this;
		
		for ( i = 0; tab_ul.childNodes[i]; ++i )
		{
			var li_child = tab_ul.childNodes[i]; 
			if ( li_child.tagName != 'LI' )
				continue;
				
			for ( j = 0; li_child.childNodes[j]; ++j )
			{
				var a_child = li_child.childNodes[j];
				if ( a_child.tagName != 'A' )
					continue;
					
				a_child.onclick = function( event ) 
				{ 
					if ( !event )
						event = window.event;
						
					var elem = !event.target ? event.srcElement : event.target;
					self.activate( elem );  
				};
					
				this.tabs.push( a_child );
			}
		}
		
		this.activate( this.tabs[0] );
	}
	
	/**
	 * Aktiviert einen Tab
	 *
	 * @param object tab Tab-Link-Objekt
	 */
	this.activate = function( tab )
	{
		var active_id = this.getTabId( tab );
		
		for( i = 0; this.tabs[i]; ++i )
		{
			var tab_id 	= this.getTabId( this.tabs[i] );
			var tab_div = document.getElementById( 'tab_' + tab_id );
			
			if ( active_id == tab_id )
			{
				this.tabs[i].className = 'active';
				if ( tab_div )
					tab_div.style.display = '';
			}
			else
			{
				this.tabs[i].className = '';
				if ( tab_div )
					tab_div.style.display = 'none';
			}
		}	
	}
	
	/**
	 * Gibt die ID zu einem Tab zurück
	 *
	 * @return string
	 */
	this.getTabId = function( tab )
	{
		var matches = tab.href.match( /#(.*)$/, '' );
		return matches[1];
	}
}