﻿if (!window.uc)
	uc = {};

uc.Page = function() 
{
}

uc.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		
		// Sample event hookup:	
		rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
	},
	
	// Sample event handler
	handleMouseDown: function(sender, eventArgs) 
	{
		// The following line of code shows how to find an element by name and call a method on it.
		// this.control.content.findName("Storyboard1").Begin();
	}
}

		function createSilverlight()
		{
			var scene = new uc.Page();
			Silverlight.createObjectEx({
				source: "sl/Page.xaml",
				parentElement: document.getElementById("silverlightControlHost"),
				id: "SilverlightControl",
				properties: {
					width: "100%",
					height: "100%",
					version: "1.0",
					background: 'transparent',    
				    isWindowless: 'true'
				},
				events: {
					onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
					onError: function(sender, args) {
						var errorDiv = document.getElementById("errorLocation");
						if (errorDiv != null) {
							var errorText = args.errorType + "- " + args.errorMessage;
									
							if (args.ErrorType == "ParserError") {
								errorText += "<br>File: " + args.xamlFile;
								errorText += ", line " + args.lineNumber;
								errorText += " character " + args.charPosition;
							}
							else if (args.ErrorType == "RuntimeError") {
								errorText += "<br>line " + args.lineNumber;
								errorText += " character " +  args.charPosition;
							}
							errorDiv.innerHTML = errorText;
						}	
					}
				}
			});
		}


		if (!window.Silverlight) 
			Silverlight = {};

		Silverlight.createDelegate = function(instance, method) {
			return function() {
				return method.apply(instance, arguments);
			}
		}
