
window.onload = function()
{
  new engine();
}

function engine()
{
  new agHost('wpfe','wpfeControl1','400','300','black',null,"load.xaml",'false','30',null);
  this._host = document.getElementById('wpfeControl1');
  this.setCallback(this._host, "onLoad", delegate(this, this.loaded));
}

engine.prototype.loaded = function(sender, args)
{
 alert("XAML loaded.");
}

engine.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;
}

function delegate(target, callback) {
	var func = function() {
		callback.apply(target, arguments);
	}
	return func;
}