// ToggleButton

function ToggleButton(label, implementation, enabled)
{
    this.label = label;
    this.implementation = implementation;
    this.enabled = implementation.getToggleState();
}

ToggleButton.prototype = new GControl();

ToggleButton.prototype.setButtonStyle = function()
{
    if (this.enabled) {
      this.button.style.color = "#ff0000";
    } else {
      this.button.style.color = "#00ff00";
    }
    this.button.style.backgroundColor = "white";
}

ToggleButton.prototype.initialize = function(map) { // Reimplemented from GControl
  var container = document.createElement("div");

  this.button = document.createElement("div");
  this.setButtonStyle();
  container.appendChild(this.button);
  this.button.appendChild(document.createTextNode(this.label));

  var self = this;
  GEvent.addDomListener(this.button, "click", function() {
        self.implementation.toggle();
        self.enabled = self.implementation.getToggleState();
        self.setButtonStyle();
  });

  map.getContainer().appendChild(container);
  return container;
}

ToggleButton.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 0));
}

