/// @param container ID of the container
/// @param panels list of panels IDs
function notebook_init(container, tab_titles, panels)
{
  if (tab_titles.length != panels.length)
  {
    logError("lengths not equal");
    return;
  }

  ntb = {
      "container": container,
      "panels": panels,
      "selected_tab": null,
      "tabs": []
    };

  body = [];

  for (i = 0; i < tab_titles.length; i++) 
  {
    tab = DIV({"class":"notebook_tab"}, tab_titles[i]);
    tab.onclick = partial(notebook_click_tab, ntb, i);
    ntb.tabs.push(tab);
    body.push(tab);
  }
  body.push(DIV({"style":"clear: both; font-size: 0"}));
  for (i = 0; i < panels.length; i++) 
  {
    body.push(getElement(panels[i]));
    hideElement(panels[i]);
  }

  appendChildNodes(container, body);
  notebook_click_tab(ntb, 0);

  return ntb;
}

//*************************************************************************

function notebook_click_tab(ntb, n)
{
  if (!isNull(ntb.selected_tab))
  {
    hideElement(ntb.panels[ntb.selected_tab]);
    ntb.tabs[ntb.selected_tab].className = "notebook_tab";
  }

  ntb.selected_tab = n;
  showElement(ntb.panels[n]);
  ntb.tabs[n].className = "notebook_tab notebook_tab_sel";
}

