/*
function _OS3TabsGlobals ()
{
	this.reference = new Array ();
}

// PUBLIC: _tabs
if ( ( _tabs ) && ( _tabs.reference ) )
{
} else 
	var _tabs = new _OS3TabsGlobals ();
*/

var _tabs = { reference: new Array () };

function _tab_show ( tab, id )
{
	id = this._prefix + "_" + id;

	var i = document.getElementById ( id );

	if ( ! i ) return;

	if ( ! tab ) tab = document.getElementById ( "tabs:" + id );

	// Do nothing if the user is clicking on the same tab
	if ( this._prev_el == i ) return;

	if ( this._prev_el )  this._prev_el.style.display = 'none';
	if ( this._prev_tab ) 
	{
		this._prev_tab.className = 'tab_unsel';
		if ( this.tab_unsel_img )
		{
			this._prev_tab.style.backgroundImage = "url(" + this.tab_unsel_img + ")";
		}
	}

	tab.className = 'tab_sel';
	if ( this.tab_sel_img )
	{
		tab.style.backgroundImage = "url(" + this.tab_sel_img + ")";
	}

	if ( this.onclick ) this.onclick ( id, tab );

	// This used to be "inherit" but IE does not support it...
	i.style.display = 'block';

	this._prev_el = i;
	this._prev_tab = tab;
}

function _tab_add ( id, descr )
{
	var s;

	s  = '<div id="tabs:' + this._prefix + '_' + id + '" class="tab_unsel" onclick="_tabs.reference [ \'';
	s += this._prefix + "' ].show ( this, '" + id + "')\"";
	if ( this.tab_unsel_img )
	{
		s += " style=\"background-image: url(" + this.tab_unsel_img + ")\" ";
	}
	s += ">" + descr + "</div>\n";

	this._tabs += s;
	
}

function _tab_render ()
{
	var e = document.getElementById ( this._prefix + "_tabs_buttons" );
	
	e.innerHTML = this._tabs;
}

// PUBLIC: OS3Tabs show add render
function OS3Tabs ( prefix, debug )
{
	this._prev_el  = 0;
	this._prev_tab = 0;

	// Tabs
	this._tabs = '';

	this.tab_sel_img = 0;
	this.tab_unsel_img = 0;

	// Error messages are shown as alert() if debug = 1
	this._debug = debug;

	// This is the Tabs prefix to be used in ID names (eg. "main")
	this._prefix = prefix;	

	this.show 	= _tab_show;
	this.add  	= _tab_add;
	this.render	= _tab_render;

	this.onclick	= false;
	
	// Add a reference to this OS3Tabs
	_tabs.reference [ prefix ] = this;
}
