//ToolBar.js
//A button panel is used to dynamically control the placement of a series of image
//buttons.  Generally speakinig, these buttons should be of equal size.  They will be
//tiled either horizontally or vertically depending on the value of the orientation property of the class.
//------------------------------------------
//Dependancies:
//  x                   radioButtonGroup
//  |--guiWidget        |
//    |--button         |
//      |--imageButto   |
//      |--radioButton--|
//      |--toggleButton


ToolBar = function(newID, parentElement, xPosition, yPosition, zIndex, width, height, visibility, styleClass, orientation)
{
  this.widgetType = 'ToolBar';
  this.init(newID,parentElement, xPosition, yPosition, zIndex, width, height, visibility, styleClass,orientation);
};
ToolBar.prototype = new GuiWidget();
ToolBar.prototype.constructor = ToolBar;
ToolBar.superclass = GuiWidget.prototype;

ToolBar.prototype.init = function(newID,parentElement, xPosition, yPosition, zIndex, width, height, visibility, styleClass,orientation)
{
  
  ToolBar.superclass.init.call(this, newID,parentElement, xPosition, yPosition, zIndex, width, height, visibility, styleClass);  //call parent's init function
  this.nextButtonOffset = 0;
  this.orientation = orientation;
  this.buttonObjects = new Object;
};

ToolBar.prototype.addButton = function (newButtonId, newButtonType, newExtensionName)
{
  //arguments list varies by button type; will be same as constructor for that particular button, however the parentElement is not set
  //Get the correct offset for the button based on the orientation of the panel
  //if the extension name is set, then we need to verify that the specified extension is active.
  var buttonXPosition = ((this.orientation == 'VERTICAL')?(1):(this.nextButtonOffset));
  var buttonYPosition = ((this.orientation == 'VERTICAL')?(this.nextButtonOffset):(1));
  dprintf(describeObject('extensions',document.getGuiValue('extensions')),true);
  if (newExtensionName != null)
    if (!document.getGuiValue('extensions')[newExtensionName].enabled)
      return null;
  
  //Declare the button
  switch (newButtonType)
  {
    case 'imageButton':
      //function parameters:  id,type,width,height,visibility,imageName,tooltip
      this.buttonObjects[this.id+'.'+newButtonId] = new ImageButton(this.id+'.'+newButtonId, this.element, buttonXPosition, buttonYPosition, 0, arguments[3], arguments[4], arguments[5], arguments[6], arguments[7]);    
      break;
    case 'toggleButton':
      this.buttonObjects[this.id+'.'+newButtonId] = new ToggleButton(newButtonId, this.element, buttonXPosition, buttonYPosition, 0, newButtonSizeX, newButtonSizeY, true, newButtonImageName, newButtonTooltip, newButtonOffTooltip, newSetActive, true);
      break;
    case 'radioButton':
      this.buttonObjects[this.id+'.'+newButtonId] = new RadioButton(this.id+'.'+newButtonId, this.element, buttonXPosition, buttonYPosition, 0, arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9]);
      break;
    default:
      alert(this.id+'.addButton:  unknown button type \''+newButtonType+'\'');
      break;
  }
  //determine the next button offset
  this.nextButtonOffset += ((this.orientation == 'VERTICAL')?(arguments[3]):(arguments[2]));
  return this.buttonObjects[this.id+'.'+newButtonId];
};

ToolBar.prototype.addDivider = function (newDividerId, newDividerWidth, newDividerStyle)
{
  var buttonXPosition = ((this.orientation == 'VERTICAL')?(0):(this.nextButtonOffset));
  var buttonYPosition = ((this.orientation == 'VERTICAL')?(this.nextButtonOffset):(0));
  //TODO:  ADD DIVIDER CODE
};

