var currentTab = new Array();

function showTab( tablist, tab ) {
	// if there is no current tab, set current tab to 0
	if ( "undefined" == typeof currentTab[ tablist ] ) {
		currentTab[ tablist ] = 0;
	}
	
	// enable link in old tab
	getTabListNode( tablist, currentTab[ tablist ] ).className = "";
	// disable link in new tab
	getTabListNode( tablist, tab ).className = "current";
	
	// hide old tab
	getTabNode( tablist, currentTab[ tablist ] ).className = "invisible tab";
	// show new tab
	getTabNode( tablist, tab ).className = "visible tab";
	
	// set new tab
	currentTab[ tablist ] = tab;
}

function getTabListNode( tablist, tab ) {
	var node = document.getElementById( "tablist" + tablist );
	var count = 0;
	for ( var i = 0; i < node.childNodes.length; i++ ) {
		if ( "li" == node.childNodes[ i ].nodeName.toLowerCase() ) {
			if ( count == tab ) {
				return node.childNodes[ i ];
			}
			count++;
		}
	}
	return null;
}

function getTabNode( tablist, tab ) {
	var node = document.getElementById( "tabs" + tablist );
	var count = 0;
	for ( var i = 0; i < node.childNodes.length; i++ ) {
		if ( "div" == node.childNodes[ i ].nodeName.toLowerCase() ) {
			if ( count == tab ) {
				return node.childNodes[ i ];
			}
			count++;
		}
	}
	return null;
}
