/***************************************************************************
 * tabs.js
 *     :
 ***************************************************************************/

/***************************************************************************
 * class ModuleTabs
 ***************************************************************************/
// Inherit from class Object.
ModuleTabs = new Object();

// Static members:
ModuleTabs.tabGroups = Array();
ModuleTabs.tabs      = Array();

/***************************************************************************
 * Constructor
 ***************************************************************************/
function ModuleTabs()
{
// Ensure this function is only called as a constructor.
	if (!(this instanceof ModuleTabs))
	{	return new ModuleTabs();	}
	return this;
}

/***************************************************************************
 * ModuleTabs::AddTab
 ***************************************************************************/
ModuleTabs.AddTab =
function(tabGroupId,tabId)
{
// Object validation:
	if (typeof(ModuleTabs.tabGroups[tabGroupId]) == 'undefined')
	{	ModuleTabs.tabGroups[tabGroupId] = Array();	}

// Add the tab.
	var len = ModuleTabs.tabGroups[tabGroupId].length;
	ModuleTabs.tabGroups[tabGroupId][len] = tabId;
	ModuleTabs.tabs     [tabId     ]      = tabGroupId;
}

/***************************************************************************
 * ModuleTabs::OnClick
 ***************************************************************************/
ModuleTabs.OnClick =
function(eventObj,currentTarget,tabId)
{
// IE -> W3C:
	if (typeof(event) != 'undefined')
	{	eventObj = event;	}
	if (eventObj.target == null)
	{	eventObj.target         = eventObj.srcElement;	}
	if (eventObj.currentTarget == null)
	{	eventObj.currentTarget  = currentTarget;	}

// TODO: Error checking?

// Gather information.
	var tabNode        = document.getElementById(tabId);
	var tabContentNode = document.getElementById(tabId+'_content');
	var tabGroupId     = ModuleTabs.tabs[tabId];
	var tabGroupTabs   = ModuleTabs.tabGroups[tabGroupId];

// Deselect the tabs and hide the contents.
	var len = tabGroupTabs.length;
	var i;
	for (i = 0; i < len; ++i)
	{
	// Gather (more) information.
		var workTabId          = tabGroupTabs[i];
		var workTabNode        = document.getElementById(workTabId);
		var workTabContentNode = document.getElementById(workTabId+'_content');

	// Unhighlight the tabs and hide their content blocks.
		workTabNode.className            = 'tab';
		workTabContentNode.style.display = 'none';
	}

// Select the tab and show its contents.
	tabNode.className            = 'tab tab_selected';
	tabContentNode.style.display = '';

// Stop the event propagation.
/* TODO: IE does not support this.
	eventObj.stopPropagation();
*/
}
