function xamlItem(target, index) {
	this.target = target;
	this.index = index;
	this.xaml = null;
	this.clickHandler = null;
	this.xamlUrl = this.target.findName("itemXaml" + this.index.toString()).text;
	this.setCallback(this.target, "mouseEnter", this.handleMouseEnter);
	this.setCallback(this.target, "mouseLeave", this.handleMouseLeave);
	this.setCallback(this.target, "mouseLeftButtonUp", this.handleClick);
    this.setCallback(this.target, "mouseLeftButtonDown", this.handleMouseDown);
}

xamlItem.prototype.handleMouseEnter = function(sender, eventArgs) {
	var itemBackground = this.target.findName("itemBackground" + this.index.toString());
	itemBackground.fill = "#FF626262";
}

xamlItem.prototype.handleMouseLeave = function(sender, eventArgs) {
	var itemBackground = this.target.findName("itemBackground" + this.index.toString());
	itemBackground.fill = "#FF424242";
}

xamlItem.prototype.handleClick = function(sender, eventArgs) {
	var itemBackground = this.target.findName("itemBackground" + this.index.toString());
	itemBackground.fill = "#FF626262";
	
	if (this.clickHandler != null) {
	    this.clickHandler(this);
	}
}

xamlItem.prototype.handleMouseDown = function(sender, eventArgs) {
	var itemBackground = this.target.findName("itemBackground" + this.index.toString());
	itemBackground.fill = "#FF222222";
}

xamlItem.prototype.setCallback = function(target, eventName, callback) {
	if (!window.methodIndex)
		window.methodIndex = 0;
	
	var callbackName = "uniqueCallback" + (window.methodIndex++);
	var controller = this;
	var func = function() {
		callback.apply(controller, arguments);
	}
	
	eval(callbackName + " = func;");
	target[eventName] = "javascript:" + callbackName;
}
