﻿function createSilverlight()
{
	var scene = new Zgadywanka.Page();
	// Ustawienie szerokosci/wysokości pól
	// Setings of width/height fields
	var szerokosc = 60;
	
	var wysokosc = ((szerokosc * pol) + (pol * 2));
	
	Silverlight.createObjectEx({
	    // Pobranie źródła (XAML) z pliku Zgadywanka.ashx na podstawie ilości pól i szerokości (pobrane z JS ustawianego w Default.aspx.cs)
	    // Get the source (XAML) from file Zgadywanka.ashx and give him number and width fields (from file Default.aspx.cs)
		source: "Zgadywanka.ashx?wrzedzie="+pol+"&szerokosc="+szerokosc,
		parentElement: document.getElementById("silverlightControlHost"),
		id: "SilverlightControl",
		properties: {
			width: "100%",
			height: wysokosc+"px",
			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.Silverlight) 
	window.Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
	return function() {
		return method.apply(instance, arguments);
	}
}

if (!window.Zgadywanka)
	window.Zgadywanka = {};

Zgadywanka.Page = function() 
{
}

Zgadywanka.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
	}
}