﻿if (!window.Silverlight)
    Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
    return function() {
        return method.apply(instance, arguments);
    }
}

function createArrow() {
    if (!Silverlight.isInstalled('1.0')) {
        return;
    }
    if (navigator.userAgent != null && navigator.userAgent.indexOf('Chrome') > 0) {
        return;
    }
	
    var scene = new Arrow();
	Silverlight.createObjectEx({
	source: "/Content/Core/Xaml/ArrowPreloader.xaml",
		parentElement: document.getElementById("Arrow"),
		id: "SilverlightControl2",
		properties: {
			width: "100%",
			height: "100%",
			version: "1.0",
			isWindowless: "true",
			background: "transparent"
		},
		events: {
			onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
			onError: function() {}
		}
	});
}

Arrow = function() 
{
}

Arrow.prototype =
{
    handleLoad: function(control, userContext, rootElement) {
        this._control = control;
        this._downloader = this._control.createObject("downloader");
		this._downloader.addEventListener("completed", Silverlight.createDelegate(this, this._downloadCompleted));
		this._downloader.open("GET", "/Content/Core/Xaml/Arrow.zip");
		this._downloader.send();        
    },
    
    _downloadCompleted: function(sender) 
    {
        var xamlFragment = this._control.content.createFromXamlDownloader(sender, "Arrow.xaml");
        var page = sender.findName("Preloader");
        page.children.add(xamlFragment);

        this._control.content.findName('Page').addEventListener("MouseLeftButtonUp", function() { document.location = 'https://mts2009.pl/rejestracja/'; });
        this._storyboard = this._control.content.findName('arrowTeaser');
        this._storyboard.addEventListener("Completed", Silverlight.createDelegate(this, this._loop));
        this._play();
    },
    
    _loop: function() {
        window.setTimeout(Silverlight.createDelegate(this, this._play), 10000);
    },
    
    _play: function() {
        this._storyboard.Stop();
        this._storyboard.Begin();
    }
}

