// XamlButton.js
var clickEvents = new Array();

function setupButton(button, clickHandler) {
//  button.mouseEnter = "handleMouseEnter";
//  button.mouseLeave = "handleMouseLeave";
//  button.mouseLeftButtonUp = "handleMouseUp";
//  button.mouseLeftButtonDown = "handleMouseDown";
  if (clickHandler != null) {
    clickEvents.push(new Array(button.Name, clickHandler));
  }
}

function handleMouseEnter(sender, eventArgs) {
  var gradientStop1 = sender.findName(sender.Name + 
                                      "_gradientStop1");
  var gradientStop2 = sender.findName(sender.Name + 
                                      "_gradientStop2");
  gradientStop1.offset = 1;
  gradientStop2.offset = .203;
}

function handleMouseLeave(sender, eventArgs) {
  var gradientStop1 = sender.findName(sender.Name + 
                                      "_gradientStop1");
  var gradientStop2 = sender.findName(sender.Name + 
                                      "_gradientStop2");
  gradientStop1.offset = 0;
  gradientStop2.offset = 1;
}

function handleMouseUp(sender, eventArgs) {
  var gradientStop1 = sender.findName(sender.Name + 
                                      "_gradientStop1");
  var gradientStop2 = sender.findName(sender.Name + 
                                      "_gradientStop2");
  gradientStop1.offset = 1;
  gradientStop2.offset = .203;

  // Look for click event and fire it if necessary
  for (var x = 0; x < clickEvents.length; ++x) {
    var clickEvent = clickEvents[x];
    var buttonName = clickEvent[0];
    if (buttonName == sender.Name) { // This is our button
      var handler = clickEvent[1];
      handler.call(sender, eventArgs);
    }
  }
}

function handleMouseDown(sender, eventArgs) {
  var gradientStop1 = sender.findName(sender.Name + 
                                      "_gradientStop1");
  var gradientStop2 = sender.findName(sender.Name + 
                                      "_gradientStop2");
  gradientStop1.offset = 1;
  gradientStop2.offset = 1;
}

