//RadioButton.js
//a clickable button which is a member of a group of "Radio Buttons".
//The button may have two states - 'on' and 'off'.
//  Only one button out of a group may be 'on' at any given time.  This requires 
//  that the radio button be associated with a group at initialization time.
//  The default state for all radio buttons is off, represented by the "normal" 
//  graphic and the radioButtonOff style in the theme stylesheet.  After the 
//  necessary buttons have been created in the document, then a particular button 
//  can be set active either directly through code, through a call to the radio 
//  button group object specifying the index of the button to set active, or with 
//  a mouse click on the radio button itself.
//The user-specified functions are 'clickOn', called when the button's state
//  changes to true (on); and 'clickOff', which is called when the button's 
//  state changes to false (off)
//------------------------------------------
//Dependancies:
//  RadioButton.js-> |->ImageButton.js|->Button.js->GuiWidget.js-><CBE libraries>
//                   |                |->overlib.js
//                   |->RadioButtonGroup.js



RadioButton = function(newID, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newImageRoot, newTooltip, newGroup, newGroupId)
{
  if (arguments.length > 0)
    this.init(newID, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newImageRoot, newTooltip,newGroup, newGroupId);
};
RadioButton.prototype = new ImageButton();
RadioButton.prototype.constructor = RadioButton;
RadioButton.superclass = ImageButton.prototype;

RadioButton.prototype.init = function(newID, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newImageRoot, newTooltip,newGroup, newGroupId)
{
  RadioButton.superclass.init.call(this, newID, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newImageRoot, newTooltip);
  
  if (newGroupId)
    this.group = OBJECT_MANAGER.getControl(newGroupId);
  else
    this.group = newGroup;
  this.groupIndex = this.group.addButton(this);
  this.active = false;
};

RadioButton.prototype.setGroup = function(newGroup)
{
  this.group = newGroup;
  this.groupIndex = newGroup.addButton(this);
};

RadioButton.prototype.isActive = function()
{
  return this.active; 
};

RadioButton.prototype.setActive = function()
{
  //should only be called from RadioButtonGroup!
  this.active = true;
  xLeft(this.imageNode,0 - this.width()*2);
};

RadioButton.prototype.setInactive = function()
{
  //should only be called from RadioButtonGroup!
  this.active = false;
  xLeft(this.imageNode,0);
  if (this.setInactiveEvent)
    this.setInactiveEvent();
};

RadioButton.prototype.click = function(e)
{
  this.group.setActiveButton(this.groupIndex);
  this.active = true;
  xLeft(this.imageNode,0-this.width());
  this.setClass('GuiImageButtonHover');
  GuiWidget.hideTooltip();
};

RadioButton.prototype.mouseOver = function(e)
{
  xLeft(this.imageNode,0-this.width());
  this.setClass('GuiImageButtonHover');
  if (this.tooltip != '')
    GuiWidget.showTooltip(e,this.tooltip);
};

RadioButton.prototype.mouseOut = function(e)
{
  xLeft(this.imageNode,this.active?(0-this.width()*2):0);
  this.setClass('GuiImageButton');
  GuiWidget.hideTooltip();
};

RadioButton.prototype.mouseUp = function(e)
{
  xLeft(this.imageNode,0-this.width());
  this.setClass('GuiImageButtonHover');
  GuiWidget.hideTooltip();
};

RadioButton.prototype.mouseDown = function(e)
{
  xLeft(this.imageNode,0-this.width()*2);
  this.setClass('GuiImageButtonDown');
  GuiWidget.hideTooltip();
};

