/*
Opendots Tab Control
Copyright (c) Gareth Hadfield 2008

Usage:
Don't put anything in content since it will be overwritten.
1) Set the Tab_tab_names property to a comma-delimited list of tab names
2) A dot will be added for each tab and the id is set to the tab name
*/

function init_tab_dot(aDot){
  var TAB_PREFIX = "tab_";
  var TAB_SUFFIX = "_tab";
  
  aDot.init_tabs = bind(aDot, function(){
    // create tabs
    this.moveChildren("document.body");
    this.setContent("");
  
    this.tabs = new TTabControl(this.name + TAB_SUFFIX);
    this.appendChild(this.tabs.mainDiv);
    send_to_back(this.tabs.mainDiv);
  
    var aTabNamesString = this.getAttributeText(TAB_PREFIX+"tab_names");
    if(aTabNamesString != undefined){
      var aTabNames = aTabNamesString.split(",");
      var iTabs = aTabNames.length;
  
      for(var iTab=0; iTab<iTabs; iTab++){
        var aTabId = aTabNames[iTab];
        this.tabs.add(aTabId);

        var aDot = geid(aTabId);
        if(aDot == undefined){
          // create new child dot
          aDot = new_dot(aTabId, aTabId, 0, 0);
        }
        aDot.setAttributeText("parent_id", this.getAttributeText("id"));
        aDot.setCSSAttribute("left", "0px");
        aDot.setCSSAttribute("top", "0px");
        aDot.setCSSAttribute("position", "relative");

      }
  
      this.tabs.activate(0);
    }
  });
  
  
  aDot.init_tabs();
  
  // custom set attribute function
  aDot.setTabsAttribute = bind(aDot, function(aName, aValue){
    this.init_tabs();
  });
  
  // add custom attributes
  aDot.addCustomAttribute(TAB_PREFIX+"tab_names", aDot.setTabsAttribute);

  aDot.addCustomMenuItem("Previous", aDot.tabs.previousTab, "Activate Next Tab");
  aDot.addCustomMenuItem("Next", aDot.tabs.nextTab, "Activate Previous Tab");
}