/// <reference path="SilverlightAnalytics.js" />

var m_xaml;

function createSilverlight()
{
    ///<summary>Create a Silverlight control</summary>
    
    // For 75% of the traffic, try a SceneA or SceneB
    m_xaml = SilverlightAnalytics.SelectXaml(0.75, "Scene.Xaml", new Array("SceneA.xaml", "SceneB.xaml"));
    
	var scene = new Analytics.Scene();
	Silverlight.createObjectEx({
		source: m_xaml,
		parentElement: document.getElementById("SilverlightControlHost"),
		id: "SilverlightControl",
		properties: {
			width: "100%",
			height: "100%",
			version: "1.0"
		},
		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.Sys)
	window.Sys = {};
	
if (!window.Silverlight) 
	window.Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
	return function() {
        return method.apply(instance, arguments);
    }
}