function controlButton(divId, state, b1Img, b1Img_hl, b1Action, b2Img, b2Img_hl, b2Action) {
  this.state = state;

  this.divId=divId;
  this.buttonId = divId + "Button";

  this.b1Img=b1Img;
  this.b1Img_hl=b1Img_hl;
  this.b1Action=b1Action;

  this.b2Img=b2Img;
  this.b2Img_hl=b2Img_hl;
  this.b2Action=b2Action;

  this.toggle = function () {
    var oldState = this.state;
    this.state = !this.state;
    document.getElementById(this.buttonId).src = this.state ? this.b1Img_hl : this.b2Img_hl;
    oldState ? eval(this.b1Action) : eval(this.b2Action);
  }

  this.hl = function () {
    document.getElementById(this.buttonId).src = this.state ? this.b1Img_hl : this.b2Img_hl;
  }

  this.deHl = function() {
    document.getElementById(this.buttonId).src = this.state ? this.b1Img : this.b2Img;
  }

  createControlButton(this);
}

function createControlButton(obj) {
  var button = document.createElement('input');
  button.type = 'image';
  button.id = obj.buttonId;
  button.src = obj.state ? obj.b1Img : obj.b2Img;
  button.onclick = function() {obj.toggle()};
  button.onmouseover = function() {obj.hl()};
  button.onmouseout = function() {obj.deHl()};
  document.getElementById(obj.divId).appendChild(button);
}
