define("wolfRunBackground", ["viewBuilderApi", "componentmodelComponentApi", "clientkernelLoaderApi", "displayEngineApi", "clientkernelEventbusApi", "wolfRunComponentsBackgroundPort", "clientkernelModulesApi"],
    function(viewBuilderApi, componentmodelComponentApi, clientkernelLoaderApi, displayEngineApi, clientkernelEventbusApi, wolfRunComponentsBackgroundPort, clientkernelModulesApi) {
        "use strict";

        function $iterator(o) {
            if (o instanceof Array) return function() {
                return {
                    cur: 0,
                    arr: o,
                    hasNext: function() {
                        return this.cur < this.arr.length;
                    },
                    next: function() {
                        return this.arr[this.cur++];
                    }
                };
            };
            return typeof(o.iterator) == 'function' ? $bind(o, o.iterator) : o.iterator;
        };;
        var $fid = 0;

        function $bind(o, m) {
            if (m == null) return null;
            if (m.__id__ == null) m.__id__ = $fid++;
            var f;
            if (o.hx__closures__ == null) o.hx__closures__ = {};
            else f = o.hx__closures__[m.__id__];
            if (f == null) {
                f = function() {
                    return f.method.apply(f.scope, arguments);
                };
                f.scope = o;
                f.method = m;
                o.hx__closures__[m.__id__] = f;
            }
            return f;
        };
        var $_;
        var $estr = function() {
            return _hcmn_.js_Boot.__string_rec(this, '');
        };
        if (typeof haxe == 'undefined') {
            var haxe = {};
        };

        haxe.IMap = function() {}
        haxe.IMap.prototype = {

        };
        if (typeof wolfRunBackground == 'undefined') {
            var wolfRunBackground = {};
        };
        wolfRunBackground.Activator = function(context) {};
        wolfRunBackground.Activator = ck_implements(wolfRunBackground.Activator, clientkernelModulesApi.IModuleActivator);
        wolfRunBackground.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        wolfRunBackground.Activator.__name__ = ["wolfRunBackground", "Activator"];
        wolfRunBackground.Activator.prototype.start = function(context) {
            context.getServiceTracker([clientkernelLoaderApi.IAssetRegistry]).then(function(context1) {
                wolfRunBackground.ExternalService.initialize(context1);
                context1.registerService(new wolfRunBackground.BackgroundFactory(context1), wolfRunComponentsBackgroundPort.BackgroundDeclaration, null);
            });
        };
        wolfRunBackground.Activator.prototype.stop = function(context) {};
        wolfRunBackground.Activator.main = function() {};
        wolfRunBackground.Activator.prototype.__class__ = wolfRunBackground.Activator;
        wolfRunBackground.Background = function(context) {
            this.image_url = null;
            var _g = this;
            this.context = context;
            this.port = context.getImplementedPort(wolfRunComponentsBackgroundPort.IBackgroundImplementationPort);
            wolfRunBackground.ExternalService.assetRegistry.getAsset("wolf-run-backgrounds-configuration").getContent().then(function(cfg) {
                _g.config = cfg;
                _g.port.getChange().subscribe($bind(_g, _g.handleChange));
                _g.port.prepareBackground().subscribe($bind(_g, _g.loadBackground));
                if (window.document.getElementById("backgroundContainer") == null) {
                    var _this = window.document;
                    _g.backgroundContainer = _this.createElement("div");
                    _g.backgroundContainer.id = "backgroundContainer";
                    _g.backgroundContainer.style.backgroundImage = "";
                    window.document.body.appendChild(_g.backgroundContainer);
                }
            });
        };
        wolfRunBackground.Background.__name__ = ["wolfRunBackground", "Background"];
        wolfRunBackground.Background.prototype.context = null;
        wolfRunBackground.Background.prototype.port = null;
        wolfRunBackground.Background.prototype.backgroundContainer = null;
        wolfRunBackground.Background.prototype.config = null;
        wolfRunBackground.Background.prototype.image_url = null;
        wolfRunBackground.Background.prototype.handleChange = function(e) {
            if (e.getPayload().fade) this.backgroundContainer.className = "fade";
            new wolfRunBackground.Crossfade(this.image_url, this.config.fadeSpeed, $bind(this, this.onImageSet));
        };
        wolfRunBackground.Background.prototype.loadBackground = function(e) {
            var _g = this;
            var image_no = e.getPayload().image_no;
            this.getImageAsset(image_no).getContent().then(function(content) {
                _g.image_url = _g.getImageAsset(image_no).getUrl();
                if (_g.backgroundContainer.style.backgroundImage == "") _g.backgroundContainer.style.backgroundImage = "url('" + _g.image_url + "')";
            });
        };
        wolfRunBackground.Background.prototype.getImageAsset = function(imageNum) {
            var imgId = this.config.backgrounds[imageNum];
            return wolfRunBackground.ExternalService.assetRegistry.getAsset(imgId);
        };
        wolfRunBackground.Background.prototype.onImageSet = function() {
            this.port.getChanged().publish(null);
        };
        wolfRunBackground.Background.prototype.__class__ = wolfRunBackground.Background;
        wolfRunBackground.BackgroundFactory = function(context) {
            this.context = context;
        };
        wolfRunBackground.BackgroundFactory = ck_implements(wolfRunBackground.BackgroundFactory, clientkernelModulesApi.IService);
        wolfRunBackground.BackgroundFactory = ck_implements(wolfRunBackground.BackgroundFactory, componentmodelComponentApi.IComponentFactory);
        wolfRunBackground.BackgroundFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        wolfRunBackground.BackgroundFactory.__name__ = ["wolfRunBackground", "BackgroundFactory"];
        wolfRunBackground.BackgroundFactory.prototype.vbf = null;
        wolfRunBackground.BackgroundFactory.prototype.context = null;
        wolfRunBackground.BackgroundFactory.prototype.getComponentDeclaration = function() {
            return wolfRunComponentsBackgroundPort.BackgroundDeclaration;
        };
        wolfRunBackground.BackgroundFactory.prototype.createComponent = function(context) {
            new wolfRunBackground.Background(context);
        };
        wolfRunBackground.BackgroundFactory.prototype.__class__ = wolfRunBackground.BackgroundFactory;
        wolfRunBackground.Crossfade = function(img_url, step, callback) {
            this.callbackDelay = 650;
            this.opacity = 0;
            if (wolfRunBackground.Crossfade.style == null) wolfRunBackground.ExternalService.assetRegistry.getAsset("wolf-run-backgrounds-css").getContent().then(function(data) {
                wolfRunBackground.Crossfade.style = data;
                window.document.head.appendChild(wolfRunBackground.Crossfade.style);
            });
            this.img_url = img_url;
            this.step = step;
            this.callback = callback;
            this.start();
        };
        wolfRunBackground.Crossfade.__name__ = ["wolfRunBackground", "Crossfade"];
        wolfRunBackground.Crossfade.prototype.img_url = null;
        wolfRunBackground.Crossfade.prototype.step = null;
        wolfRunBackground.Crossfade.prototype.tempDiv = null;
        wolfRunBackground.Crossfade.prototype.opacity = null;
        wolfRunBackground.Crossfade.prototype.callback = null;
        wolfRunBackground.Crossfade.prototype.callbackDelay = null;
        wolfRunBackground.Crossfade.prototype.start = function() {
            this.tempDiv = window.document.getElementById("backgroundContainer");
            if (_hcmn_.Std.parseInt(this.tempDiv.style.opacity) == 1) this.tempDiv.style.opacity = "0";
            else this.tempDiv.style.opacity = "1";
            this.end();
        };
        wolfRunBackground.Crossfade.prototype.end = function() {
            if (this.callback != null) _hcmn_.haxe_Timer.delay(this.callback, this.callbackDelay);
        };
        wolfRunBackground.Crossfade.style = null;
        wolfRunBackground.Crossfade.prototype.__class__ = wolfRunBackground.Crossfade;
        wolfRunBackground.ExternalService = function() {};
        wolfRunBackground.ExternalService.__name__ = ["wolfRunBackground", "ExternalService"];
        wolfRunBackground.ExternalService.assetRegistry = null;
        wolfRunBackground.ExternalService.variableRegistry = null;
        wolfRunBackground.ExternalService.initialize = function(context) {
            wolfRunBackground.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
            wolfRunBackground.ExternalService.variableRegistry = context.getAnyService(clientkernelLoaderApi.IVariableRegistry, null);
        };
        wolfRunBackground.ExternalService.prototype.__class__ = wolfRunBackground.ExternalService;
        wolfRunBackground.Background.CFG_ID = "wolf-run-backgrounds-configuration";;
        return {
            exports: wolfRunBackground,
            activator: wolfRunBackground.Activator
        };
    });
//# sourceURL=wolfRunBackground.js