﻿// 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("mouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
    target.addEventListener("mouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
}

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;
}
