///////////////////////////////////////////////////////////////////////////////
//
//  button.js
//
// 
// © 2007 Microsoft Corporation. All Rights Reserved.
//
// This file is licensed as part of the Silverlight 1.0 SDK, for details look 
// here: http://go.microsoft.com/fwlink/?LinkID=89144&clcid=0x409
//
///////////////////////////////////////////////////////////////////////////////
// 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;
}
