// Javascript class that handles events to simulate a button
function button(target, backgroundElement, hoverFill, mouseDownFill, clickHandler) {
    this.target = target;
    this.backgroundElement = backgroundElement;
    this.hoverFill = hoverFill;
    this.mouseDownFill = mouseDownFill;
    this.clickHandler = clickHandler;
    
    // Register eventhandlers
    target.addEventListener("mouseEnter", Silverlight.createDelegate(this, this.handleMouseEnter));
    target.addEventListener("mouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave));
    target.addEventListener("mouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
    target.addEventListener("mouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
}

button.prototype.handleMouseEnter = function(sender, eventArgs) {
    this.oldFill = this.backgroundElement.fill;
    this.backgroundElement.fill = this.hoverFill;
}

button.prototype.handleMouseLeave = function(sender, eventArgs) {
    this.backgroundElement.fill = this.oldFill;
}

button.prototype.handleMouseUp = function(sender, eventArgs) {
    this.backgroundElement.fill = this.hoverFill;
    
    if (this.clickHandler) {
        this.clickHandler(sender, eventArgs);
    }
}

button.prototype.handleMouseDown = function(sender, eventArgs) {
    this.backgroundElement.fill = this.mouseDownFill;
}
