///////////////////////////////////////////////////////////////////////////////
//
//  scrollbar.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 scrollbar(target, backgroundElement, hoverFill, mouseDownFill, dragHandler) {
	this.target = target;
	this.backgroundElement = backgroundElement;
	this.hoverFill = hoverFill;
	this.mouseDownFill = mouseDownFill;
	this.dragHandler = dragHandler;
	this.mouseDown = false;
	
	// 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));
    target.addEventListener("mouseMove", Silverlight.createDelegate(this, this.handleMouseMove));
}

scrollbar.prototype.handleMouseEnter = function(sender, eventArgs) {
    this.oldFill = this.backgroundElement.fill;
    this.backgroundElement.fill = this.hoverFill;
}

scrollbar.prototype.handleMouseLeave = function(sender, eventArgs) {
    this.backgroundElement.fill = this.oldFill;
}

scrollbar.prototype.handleMouseUp = function(sender, eventArgs) {
	this.backgroundElement.fill = this.hoverFill;
	this.mouseDown = false;
	this.target.releaseMouseCapture();
}

scrollbar.prototype.handleMouseDown = function(sender, eventArgs) {
    this.backgroundElement.fill = this.mouseDownFill;
    this.mouseDownPosition = eventArgs.getPosition(this.target).Y;
    this.mouseDown = true;
    this.canvasTop = this.target["Canvas.Top"];
    this.target.captureMouse();
}

scrollbar.prototype.handleMouseMove = function(sender, eventArgs) {
    if (this.mouseDown) {
        if (this.dragHandler) {
	        this.dragHandler(sender, this.target["Canvas.Top"] + (eventArgs.getPosition(this.target).Y - this.mouseDownPosition));
	    }
	}
}



