/* Credits:
Max Jacob, {xzoert} "myGuru();"
Arno Peck, Lorenzo Becchi 
his friends
*/

// Tabbatore

		var TBX_onstyle="background-color:#a0a;";
		var TBX_offstyle="background-color:#0f0;";
	
		function TBX_init() {
			// browse the document and find all TBX_* tags
			TBX_browse( document.documentElement );
		}
		
		TBX_all=null;
		
		
		function TBX_handler( btn, id, tab ) {
			TBX_all[id]=this;
			this.id = id;
			this.tab=tab;
			this.btn=btn;
			this.handleClick=TBX_handleClick;
			btn.onclick=this.handleClick;
			this.show=TBX_show;
			this.hide=TBX_hide;
		}

		TBX_current=null;
		
		function TBX_show() {
			this.tab.style.display="block";
			if( TBX_current ) TBX_current.hide();
			TBX_current=this;
			var cn = this.btn.className;
			if( !cn ) cn = "";
			else cn=cn.replace( "TBX_inactive" );
			cn+=" TBX_active";
			cn=cn.replace( "  ", " " );
			this.btn.className=cn;
		}
		
		function TBX_hide() {
			this.tab.style.display="none";
			var cn = this.btn.className;
			if( !cn ) cn = "";
			else cn=cn.replace( "TBX_active" );
			cn+=" TBX_inactive";
			cn=cn.replace( "  ", " " );
			this.btn.className=cn;
		}

		function TBX_handleClick() {
			var th=TBX_all[this.id];
			if( th == TBX_current ) return;
			th.show();
		}
		
		function TBX_browse( n ) {
		
			var id = n.id;
			var idx = -1;
			if( id!=null && id.indexOf) idx=id.indexOf( "TBX_" );
			if( id != null && idx==0 && id.substring(5,id.length).indexOf( "_" )<0 ) {
				var tab = document.getElementById( id+"_tab" );
				if( tab ) {
					if( TBX_all == null ) {
						// initialize the TBX_all and keep this  tab visible
						TBX_all=new Array();
						var th = new TBX_handler( n, id, tab );
						th.show();
					}
					else {
						var th = new TBX_handler( n, id, tab );
						th.hide();						
					}
				}
			}
			for( var i = 0; i<n.childNodes.length; i++ ) {
				if( n.nodeType == 1 ) 
					TBX_browse( n.childNodes[i] );
			}
		
		}

