// © 2004-2007, Applied Geographics, Inc.  All rights reserved.

function RollOverOption(groupName, id, postBack, imageUrl, overImageUrl, 
    selectedImageUrl, clientScript) {
  this.groupName = groupName;
  this.id = id;
  this.button = document.getElementById(id + "_button");
  
  this.postBack = postBack;
  this.clientScript = clientScript;
  
  var image = new Image();
  image.src = imageUrl;
  image.src = overImageUrl;
  image.src = selectedImageUrl;
  
  this.imageUrl = imageUrl;
  this.overImageUrl = overImageUrl;
  this.selectedImageUrl = selectedImageUrl;
  
  if (this.isSelected())
    RollOverOption.selected[this.groupName] = this;
  else {
    if (RollOverOption.selected[this.groupName] == undefined)
      RollOverOption.selected[this.groupName] = null;
  }
};

RollOverOption.selected = [];

RollOverOption.execute = function(clientScript, postBack) {
  if (clientScript != "")
    eval(clientScript);
  if (postBack != "")
    eval(postBack);
};

RollOverOption.prototype.isSelected = function() {
  return this.getHiddenField().value == this.id;
};

RollOverOption.prototype.getHiddenField = function() {
  var name = "__RollOverOption";
  if (this.groupName != "")
    name += "_" + this.groupName;
  return document.getElementById(name);
};

RollOverOption.prototype.mouseDown = function() {
  if (!this.isSelected()) {
    if (RollOverOption.selected[this.groupName] != null)
      RollOverOption.selected[this.groupName].unselect();
    this.select();
  }
};

RollOverOption.prototype.mouseOut = function() {
  if (!this.isSelected())
    this.button.src = this.imageUrl;
};

RollOverOption.prototype.mouseOver = function() {
  if (!this.isSelected())
    this.button.src = this.overImageUrl;
};

RollOverOption.prototype.select = function() {
  this.getHiddenField().value = this.id;
  RollOverOption.selected[this.groupName] = this;
  this.button.src = this.selectedImageUrl;
  
  setTimeout("RollOverOption.execute(\"" + this.clientScript + "\", \"" + this.postBack + "\")", 50);
};

RollOverOption.prototype.unselect = function() {
  this.getHiddenField().value = "";
  RollOverOption.selected[this.groupName] = null;
  this.button.src = this.imageUrl;
};

