/* Copyright (C) MOR YAZILIM. http://www.moryazilim.com
 * All rights reserved. This software is published under the terms of the
 * GNU Lesser General Public License. http://www.gnu.org/licenses/lgpl.txt
 */
function AnimatedButton(node) {
  this.props = null;
  this.img = node;
  this.base.constructor.call(this,node);
}
InheritsFrom(AnimatedButton,MoreMotionObject);
OMgr.types["AnimatedButton"] = {
  init: function(node) {
    var ab = new AnimatedButton(node);
    ab.init();
  }
}
AnimatedButton.prototype.setDisabled = function(value) {
  if (value == true) {
    this.props.isDisabled = true;
    this.img.src = this.props.disabledSource;
    this.img.style.cursor = "default";
    if (this.img.onclick) {
      this.props.savedOnclick = this.img.onclick + "";
      this.img.onclick = "";
    }
  } else {
    this.props.isDisabled = false;
    this.img.src = this.props.normalSource;
    this.img.style.cursor = "pointer";
    if (this.props.savedOnclick) {
      eval("this.img.onclick = " + this.props.savedOnclick);
    }
  }
  this.saveProps();
};
AnimatedButton.prototype.setEvent = function(eventName, jsCode) {
  var s = "";
  eval("var event = this.node." + eventName);
  if (event) {
    s = event + "";
    s = s.after("{",s);
    s = s.beforeLast("}",s);
    if (s.indexOf(jsCode) > -1) return;
  }
  eval ("this.node." + eventName + " = function() { " + jsCode + s + " }");
};
AnimatedButton.prototype.setEvents = function() {
  this.setEvent("onmouseover","ABMgr.mouseOver(this);");
  this.setEvent("onmouseout","ABMgr.mouseOut(this);");
  this.setEvent("onmousedown","ABMgr.mouseDown(this);");
  this.setEvent("onmouseup","ABMgr.mouseUp(this);");
};
AnimatedButton.prototype.setSources = function() {
  this.mouseOverImage = new Image();
  this.mouseOverImage.src = this.props.mouseOverSource;
  this.mouseDownImage = new Image();
  this.mouseDownImage.src = this.props.mouseDownSource;
  this.disabledImage = new Image();
  this.disabledImage.src = this.props.disabledSource;
};
AnimatedButton.prototype.select = function() {
  this.isSelected = true;
  this.img.src = this.props.selectedSource;
};
AnimatedButton.prototype.init = function() {
  this.setEvents();
  this.setSources();
  this.setDisabled(this.boolProp("isDisabled"));
};
function AnimatedButtonManager() {
  this.current = null;
  this.getButton = function(node) {
    if (!this.current || this.current != node) {
      this.current = OMgr.getObject(node);
    }
    return this.current;
  };
  this.mouseOver = function(node) {
    var b = this.getButton(node);
    if (!b.boolProp("isDisabled"))
      b.img.src = b.props.mouseOverSource;
  };
  this.mouseDown = function(node) {
    var b = this.getButton(node);
    if (!b.boolProp("isDisabled"))
      b.img.src = b.props.mouseDownSource;
  };
  this.mouseOut = function(node) {
    var b = this.getButton(node);
    if (!b.boolProp("isDisabled"))
      b.img.src = b.props.normalSource;
  };
  this.mouseUp = function(node) {
    var b = this.getButton(node);
    if (!b.boolProp("isDisabled"))
      b.img.src = b.props.normalSource;
  };
};
var ABMgr = new AnimatedButtonManager();

