// -----------------------------------------------------------------------------------
// 
// Recycled from http://jon.hedley.net/html-tabbed-dialog-widget
// on 2005-09-14
// which at the bottom of the page reads:
// Please feel free to use this script on your websites — let me know if you do, or if you have any suggestions for extending the widget.
// It has changed a lot since I snagged it
//
// ----------------------------------------------------------------------------------- 

var panes = new Array();

function setupPanes(containerId) {
  // go through the DOM, find each tab-container
  // set up the panes array with named panes
  // find the max height, set tab-panes to that height
  panes[containerId] = new Array();
  var paneContainer = document.getElementById(containerId);
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    panes[containerId][pane.id] = pane;
  }
}

function showPane(paneId, activeTab) {
  // make tab active class
  // hide other panes (siblings)
  // make pane visible
	if(document.all) { // ie bugs out pretty weirdly, just follow the link
		return true;
	}
	else {
    for (var con in panes) {
			activeTab.blur();
			activeTab.className = "tab-active";
			if (panes[con][paneId] != null) { // tab and pane are members of this container
				var pane = document.getElementById(paneId);
				pane.className = "pane-active";
				var tabs = document.getElementById(con + '-tabs');
				var tabList = tabs.getElementsByTagName("a")
				for (var i=0; i<tabList.length; i++ ) {
					var tab = tabList[i];
					if (tab != activeTab) tab.className = "tab-disabled";
				}
				for (var i in panes[con]) {
					var pane = panes[con][i];
					if (pane == 'undefined') continue;
					if (pane.id == paneId) continue;
					if (i == 'flatten') continue; // No idea how i = 'flatten' creeps into panes
					pane.className = "pane-inactive"
				}
			}
		}
	}
  return false;
}

