define("ballooniesIXFBackground", ["viewBuilderApi", "componentmodelComponentApi", "clientkernelLoaderApi", "displayEngineApi", "ballooniesIXFBackgroundPort", "clientkernelEventbusApi", "clientkernelModulesApi"],
    function(viewBuilderApi, componentmodelComponentApi, clientkernelLoaderApi, displayEngineApi, ballooniesIXFBackgroundPort, clientkernelEventbusApi, 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 ballooniesIXFBackground == 'undefined') {
            var ballooniesIXFBackground = {};
        };
        ballooniesIXFBackground.Activator = function(context) {};
        ballooniesIXFBackground.Activator = ck_implements(ballooniesIXFBackground.Activator, clientkernelModulesApi.IModuleActivator);
        ballooniesIXFBackground.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        ballooniesIXFBackground.Activator.__name__ = ["ballooniesIXFBackground", "Activator"];
        ballooniesIXFBackground.Activator.prototype.start = function(context) {
            context.getServiceTracker([clientkernelLoaderApi.IAssetRegistry]).then(function(context1) {
                ballooniesIXFBackground.ExternalService.initialize(context1);
                context1.registerService(new ballooniesIXFBackground.BackgroundFactory(context1), ballooniesIXFBackgroundPort.BackgroundDeclaration, null);
            });
        };
        ballooniesIXFBackground.Activator.prototype.stop = function(context) {};
        ballooniesIXFBackground.Activator.main = function() {};
        ballooniesIXFBackground.Activator.prototype.__class__ = ballooniesIXFBackground.Activator;
        ballooniesIXFBackground.Background = function(context) {
            var _g = this;
            this.context = context;
            this.port = context.getImplementedPort(ballooniesIXFBackgroundPort.IBackgroundImplementationPort);
            ballooniesIXFBackground.ExternalService.assetRegistry.getAsset("baloonies-bkg-config").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);
                }
            });
        };
        ballooniesIXFBackground.Background.__name__ = ["ballooniesIXFBackground", "Background"];
        ballooniesIXFBackground.Background.prototype.context = null;
        ballooniesIXFBackground.Background.prototype.port = null;
        ballooniesIXFBackground.Background.prototype.backgroundContainer = null;
        ballooniesIXFBackground.Background.prototype.config = null;
        ballooniesIXFBackground.Background.prototype.imageUrl = null;
        ballooniesIXFBackground.Background.prototype.handleChange = function(e) {
            if (e.getPayload().fade) this.backgroundContainer.className = "fade";
            new ballooniesIXFBackground.Crossfade(this.imageUrl, this.config.fadeSpeed, $bind(this, this.onImageSet));
        };
        ballooniesIXFBackground.Background.prototype.loadBackground = function(e) {
            var _g = this;
            var imageNo = e.getPayload().imageNo;
            this.getImageAsset(imageNo).getContent().then(function(content) {
                _g.imageUrl = _g.getImageAsset(imageNo).getUrl();
                if (_g.backgroundContainer.style.backgroundImage == "") _g.backgroundContainer.style.backgroundImage = "url('" + _g.imageUrl + "')";
            });
        };
        ballooniesIXFBackground.Background.prototype.getImageAsset = function(imageNum) {
            var imgId = this.config.backgrounds[imageNum];
            return ballooniesIXFBackground.ExternalService.assetRegistry.getAsset(imgId);
        };
        ballooniesIXFBackground.Background.prototype.onImageSet = function() {
            this.port.getChanged().publish(null);
        };
        ballooniesIXFBackground.Background.prototype.__class__ = ballooniesIXFBackground.Background;
        ballooniesIXFBackground.BackgroundFactory = function(context) {
            this.context = context;
        };
        ballooniesIXFBackground.BackgroundFactory = ck_implements(ballooniesIXFBackground.BackgroundFactory, clientkernelModulesApi.IService);
        ballooniesIXFBackground.BackgroundFactory = ck_implements(ballooniesIXFBackground.BackgroundFactory, componentmodelComponentApi.IComponentFactory);
        ballooniesIXFBackground.BackgroundFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        ballooniesIXFBackground.BackgroundFactory.__name__ = ["ballooniesIXFBackground", "BackgroundFactory"];
        ballooniesIXFBackground.BackgroundFactory.prototype.vbf = null;
        ballooniesIXFBackground.BackgroundFactory.prototype.context = null;
        ballooniesIXFBackground.BackgroundFactory.prototype.getComponentDeclaration = function() {
            return ballooniesIXFBackgroundPort.BackgroundDeclaration;
        };
        ballooniesIXFBackground.BackgroundFactory.prototype.createComponent = function(context) {
            new ballooniesIXFBackground.Background(context);
        };
        ballooniesIXFBackground.BackgroundFactory.prototype.__class__ = ballooniesIXFBackground.BackgroundFactory;
        ballooniesIXFBackground.Crossfade = function(imageUrl, step, callback) {
            this.callbackDelay = 650;
            this.opacity = 0;
            if (ballooniesIXFBackground.Crossfade.style == null) ballooniesIXFBackground.ExternalService.assetRegistry.getAsset("baloonies-bkg-css").getContent().then(function(data) {
                ballooniesIXFBackground.Crossfade.style = data;
                window.document.head.appendChild(ballooniesIXFBackground.Crossfade.style);
            });
            this.imageUrl = imageUrl;
            this.step = step;
            this.callback = callback;
            this.start();
        };
        ballooniesIXFBackground.Crossfade.__name__ = ["ballooniesIXFBackground", "Crossfade"];
        ballooniesIXFBackground.Crossfade.prototype.imageUrl = null;
        ballooniesIXFBackground.Crossfade.prototype.step = null;
        ballooniesIXFBackground.Crossfade.prototype.tempDiv = null;
        ballooniesIXFBackground.Crossfade.prototype.opacity = null;
        ballooniesIXFBackground.Crossfade.prototype.callback = null;
        ballooniesIXFBackground.Crossfade.prototype.callbackDelay = null;
        ballooniesIXFBackground.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();
        };
        ballooniesIXFBackground.Crossfade.prototype.end = function() {
            if (this.callback != null) _hcmn_.haxe_Timer.delay(this.callback, this.callbackDelay);
        };
        ballooniesIXFBackground.Crossfade.style = null;
        ballooniesIXFBackground.Crossfade.prototype.__class__ = ballooniesIXFBackground.Crossfade;
        ballooniesIXFBackground.ExternalService = function() {};
        ballooniesIXFBackground.ExternalService.__name__ = ["ballooniesIXFBackground", "ExternalService"];
        ballooniesIXFBackground.ExternalService.assetRegistry = null;
        ballooniesIXFBackground.ExternalService.variableRegistry = null;
        ballooniesIXFBackground.ExternalService.initialize = function(context) {
            ballooniesIXFBackground.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
            ballooniesIXFBackground.ExternalService.variableRegistry = context.getAnyService(clientkernelLoaderApi.IVariableRegistry, null);
        };
        ballooniesIXFBackground.ExternalService.prototype.__class__ = ballooniesIXFBackground.ExternalService;
        if (typeof haxe == 'undefined') {
            var haxe = {};
        };

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

        };
        ballooniesIXFBackground.Background.CFG_ID = "baloonies-bkg-config";;
        return {
            exports: ballooniesIXFBackground,
            activator: ballooniesIXFBackground.Activator
        };
    });
//# sourceURL=ballooniesIxfBackground.js