// JavaScript Document

function Tab( tab_id, header_id ) {
	this.tab_id = tab_id;
	this.header_id = header_id;
	this.onVisible = null

	this.toggleDisplay = function() {
		if ( this.isVisible() )
			$( tab_id ).style.display = 'none';
		else
			$( tab_id ).style.display = 'block';
	}

	this.isVisible = function () {
		return $( this.tab_id ).style.display != 'none' ? true : false;
	}
}

function Tabber() {
	this.tabs = null;
	this.currentTab = null;
	this.prevTab = null;
	this.onComplete = null;
	this.onToggle = null;
	
	this.setTabs = function( tabs ) {
		this.tabs = tabs;
	}

	this.toggle = function( theTab ) {
		this.currentTab = theTab;
		
		if ( ! theTab.isVisible() ) {
			for ( tab in tabs ) {
				if ( tab == 'attachEvent' || tab == 'detachEvent' ) //this quick is a hack for Safari
					continue;

				if ( ! $( tabs[tab].header_id ) )
					$( 'tabHeaderActive' ).id = tabs[tab].header_id;

				if( tabs[tab].isVisible() ) {
					Effect.toggle( tabs[tab].tab_id, 'blind', { duration: 0.0, delay: 0.0, queue: { scope: 'menus', limit: 3 } } );

					tabs[tab].toggleDisplay();
				}
			}

			$( theTab.header_id ).blur();

			if ( $( theTab.header_id ) )
				$( theTab.header_id ).id = 'tabHeaderActive';

			$( theTab.tab_id ).style.marginTop = '2px';

			Effect.toggle( theTab.tab_id, 'blind',{ afterFinish: this.onComplete, duration: 0.0, delay: 0.0, queue: { scope: 'menus', position: 'end', limit: 3  } } );

			theTab.toggleDisplay();

			if ( theTab.onVisible )
				theTab.onVisible();
		}
		
		if ( this.onToggle )
			this.onToggle( theTab );
	}

	this.show = function( theTab ) {
		if ( ! tabs[tab].visible )
			this.toggle( tabs[tab] );
	}

	this.hide = function( theTab ) {
		if ( tabs[tab].visible  );
	}

	this.reset = function() {
		for ( tab in tabs )
			tabs[tab].visible = false;
	}
}
