// © 2007, Applied Geographics, Inc.  All rights reserved.

function PanelButton(id, normalClass, overClass, disabledClass) {
  this.id = id;
  this.element = document.getElementById(id);
  this.normalClass = normalClass;
  this.overClass = overClass;
  this.disabledClass = disabledClass;
  
  implementEventHandler(this);
  
  this.getEnabled = function() {
    return eval(document.getElementById(this.id + ".Enabled").value);
  };
  
  this.mouseDown = function(e) {
    if (this.getEnabled()) {
      this.dispatchEvent("click", e);
    }
  };
  
  this.mouseOver = function() {
    if (this.getEnabled()) {
      this.element.className = this.overClass;
    }
  };
  
  this.mouseOut = function() {
    if (this.getEnabled()) {
      this.element.className = this.normalClass;
    }
  };
  
  this.setEnabled = function(enabled) {
    this.element.className = enabled ? this.normalClass : this.disabledClass;
    document.getElementById(this.id + ".Enabled").value = enabled + "";
  };
  
  var controller = this;
  this.attachEventToElement(this.element, "mousedown", function (e) { controller.mouseDown(e); });
  this.attachEventToElement(this.element, "mouseover", function (e) { controller.mouseOver(e); });
  this.attachEventToElement(this.element, "mouseout", function (e) { controller.mouseOut(e); });
  
  this.element.controller = controller;
  this.element.attachEvent = function(eventName, handler) { this.controller.attachEvent(eventName, handler); };
  this.element.getEnabled = function() { return this.controller.getEnabled(); };
  this.element.setEnabled = function(enabled) { return this.controller.setEnabled(enabled); };

  return this.element;
}


