///////////////////////////////////////////////////////////////////////////////
//
//  listboxitem.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 to handle the events on each listbox item
function listBoxItem(target, index, clickHandler) {
	this.target = target;
	this.index = index;
	this.clickHandler = clickHandler;
	this.target.addEventListener("mouseEnter", Silverlight.createDelegate(this, this.handleMouseEnter));
	this.target.addEventListener("mouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave));
	this.target.findName("play" + index.toString()).addEventListener("mouseLeftButtonUp", Silverlight.createDelegate(this, this.handlePlayClick));
    this.target.findName("play" + index.toString()).addEventListener("mouseLeftButtonDown", Silverlight.createDelegate(this, this.handlePlayMouseDown));
	this.target.findName("play" + index.toString()).addEventListener("mouseEnter", Silverlight.createDelegate(this, this.handlePlayEnter));
	this.target.findName("play" + index.toString()).addEventListener("mouseLeave", Silverlight.createDelegate(this, this.handlePlayLeave));
}

listBoxItem.prototype.handleMouseEnter = function(sender, eventArgs) {
	var itemBackground = this.target.findName("itemBackground" + this.index.toString());
	itemBackground.fill = "#FF222222";
	
	var pathBackground = this.target.findName("pathBackground" + this.index.toString());
	this.oldFill = pathBackground.fill;
	pathBackground.fill = "#FF222222";
}

listBoxItem.prototype.handleMouseLeave = function(sender, eventArgs) {
    var itemBackground = this.target.findName("itemBackground" + this.index.toString());
	itemBackground.fill = "black";
	
    var pathBackground = this.target.findName("pathBackground" + this.index.toString());
	pathBackground.fill = this.oldFill;
}

listBoxItem.prototype.handlePlayClick = function(sender, eventArgs) {
	if (this.clickHandler) {
	    this.clickHandler(sender, this.index);
	}
    var scale = this.target.findName("scale" + this.index.toString())
    scale.scaleX = 1.2;
    scale.scaleY = 1.2;
}

listBoxItem.prototype.handlePlayMouseDown = function(sender, eventArgs) {
	var scale = this.target.findName("scale" + this.index.toString())
    scale.scaleX = .9;
    scale.scaleY = .9;
}

listBoxItem.prototype.handlePlayEnter = function(sender, eventArgs) {
    var scale = this.target.findName("scale" + this.index.toString())
    scale.scaleX = 1.2;
    scale.scaleY = 1.2;
}

listBoxItem.prototype.handlePlayLeave = function(sender, eventArgs) {
    var scale = this.target.findName("scale" + this.index.toString())
    scale.scaleX = 1;
    scale.scaleY = 1;
}