define("wildFuryRules", ["componentmodelComponentApi", "slotModelApi", "wildFuryRulesDeclaration", "clientkernelEventbusApi", "clientkernelModulesApi", "moneyApi"],
    function(componentmodelComponentApi, slotModelApi, wildFuryRulesDeclaration, clientkernelEventbusApi, clientkernelModulesApi, moneyApi) {
        "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 wildFuryRules == 'undefined') {
            var wildFuryRules = {};
        };
        wildFuryRules.ModuleActivator = function() {};
        wildFuryRules.ModuleActivator = ck_implements(wildFuryRules.ModuleActivator, clientkernelModulesApi.IModuleActivator);
        wildFuryRules.ModuleActivator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        wildFuryRules.ModuleActivator.__name__ = ["wildFuryRules", "ModuleActivator"];
        wildFuryRules.ModuleActivator.prototype.factory = null;
        wildFuryRules.ModuleActivator.prototype.registration = null;
        wildFuryRules.ModuleActivator.prototype.start = function(context) {
            var _g = this;
            context.getServiceTracker([clientkernelEventbusApi.IEventBus]).then(function(mContext) {
                _g.factory = new wildFuryRules.RulesFactory(context);
                _g.registration = context.registerService(_g.factory, wildFuryRulesDeclaration.RulesDeclaration, null);
            });
        };
        wildFuryRules.ModuleActivator.prototype.stop = function(context) {
            if (this.factory.rules != null) {
                this.registration.unregister();
                this.factory.rules.stop();
            }
        };
        wildFuryRules.ModuleActivator.main = function() {};
        wildFuryRules.ModuleActivator.prototype.__class__ = wildFuryRules.ModuleActivator;
        wildFuryRules.Rules = function(smPort) {
            this.smPort = smPort;
            this.helpInstance = null;
            this.paytableInstance = null;
            this.subscribe();
        };
        wildFuryRules.Rules.__name__ = ["wildFuryRules", "Rules"];
        wildFuryRules.Rules.prototype.smPort = null;
        wildFuryRules.Rules.prototype.helpInstance = null;
        wildFuryRules.Rules.prototype.paytableInstance = null;
        wildFuryRules.Rules.prototype.subscriptions = null;
        wildFuryRules.Rules.prototype.subscribe = function() {
            this.subscriptions = [];
            this.subscriptions.push(this.smPort.getStages().getIdleStage().getOpenHelp().subscribe($bind(this, this.onOpenHelp)));
            this.subscriptions.push(this.smPort.getStages().getIdleStage().getOpenPaytable().subscribe($bind(this, this.onOpenPaytable)));
        };
        wildFuryRules.Rules.prototype.onOpenHelp = function(event) {
            var url = event.getPayload();
            if (url == null || url == "") return;
            if (window.document.getElementById("rulesInstance") != null) {
                this.closeHelp();
                return;
            }
            this.helpInstance = new wildFuryRules.RulesInstance(url, "Help", $bind(this, this.helpClosed));
        };
        wildFuryRules.Rules.prototype.closeHelp = function() {
            if (this.helpInstance == null) return;
            this.helpInstance.close();
            this.helpClosed();
        };
        wildFuryRules.Rules.prototype.helpClosed = function() {
            this.helpInstance = null;
        };
        wildFuryRules.Rules.prototype.onOpenPaytable = function(event) {
            this.closeHelp();
        };
        wildFuryRules.Rules.prototype.stop = function() {
            this.unsubscribe();
        };
        wildFuryRules.Rules.prototype.unsubscribe = function() {
            if (this.subscriptions == null) return;
            while (this.subscriptions.length > 0) this.subscriptions.pop().unsubscribe();
            this.subscriptions = null;
        };
        wildFuryRules.Rules.prototype.__class__ = wildFuryRules.Rules;
        wildFuryRules.RulesFactory = function(moduleContext) {
            this.moduleContext = moduleContext;
        };
        wildFuryRules.RulesFactory = ck_implements(wildFuryRules.RulesFactory, clientkernelModulesApi.IService);
        wildFuryRules.RulesFactory = ck_implements(wildFuryRules.RulesFactory, componentmodelComponentApi.IComponentFactory);
        wildFuryRules.RulesFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        wildFuryRules.RulesFactory.__name__ = ["wildFuryRules", "RulesFactory"];
        wildFuryRules.RulesFactory.prototype.rules = null;
        wildFuryRules.RulesFactory.prototype.moduleContext = null;
        wildFuryRules.RulesFactory.prototype.getComponentDeclaration = function() {
            return wildFuryRulesDeclaration.RulesDeclaration;
        };
        wildFuryRules.RulesFactory.prototype.createComponent = function(componentContext) {
            this.rules = new wildFuryRules.Rules(componentContext.getUsedPort(slotModelApi.ISlotModelPort));
        };
        wildFuryRules.RulesFactory.prototype.__class__ = wildFuryRules.RulesFactory;
        wildFuryRules.RulesInstance = function(url, id, closeCallback) {
            this.id = id;
            this.closeCallback = closeCallback;
            this.createIFrame(url);
            this.createContentWrapper();
            this.addListeners();
        };
        wildFuryRules.RulesInstance.__name__ = ["wildFuryRules", "RulesInstance"];
        wildFuryRules.RulesInstance.prototype.iframe = null;
        wildFuryRules.RulesInstance.prototype.node = null;
        wildFuryRules.RulesInstance.prototype.id = null;
        wildFuryRules.RulesInstance.prototype.closeCallback = null;
        wildFuryRules.RulesInstance.prototype.divWrapper = null;
        wildFuryRules.RulesInstance.prototype.createIFrame = function(url) {
            var _this = window.document;
            this.iframe = _this.createElement("iframe");
            this.iframe.marginHeight = "0";
            this.iframe.marginWidth = "0";
            this.iframe.src = url;
            this.iframe.frameBorder = "0";
            this.iframe.setAttribute("style", "width:100%; height:100%; min-height:101%; background:white; position:absolute;");
            this.iframe.height = window.document.body.scrollHeight + "px";
        };
        wildFuryRules.RulesInstance.prototype.createContentWrapper = function() {
            var _this = window.document;
            this.divWrapper = _this.createElement("div");
            this.setDivWrapperStyle();
            this.divWrapper.appendChild(this.iframe);
            this.divWrapper.id = "rulesInstance";
            this.node = window.document.body.appendChild(this.divWrapper);
        };
        wildFuryRules.RulesInstance.prototype.addListeners = function() {
            window.addEventListener("resize", $bind(this, this.onResize));
            this.iframe.addEventListener("load", $bind(this, this.onLoad));
        };
        wildFuryRules.RulesInstance.prototype.onLoad = function(e) {
            this.iframe.height = this.iframe.contentWindow.document.body.scrollHeight + "px";
            this.setDivWrapperStyle();
        };
        wildFuryRules.RulesInstance.prototype.setDivWrapperStyle = function() {
            if (this.isAppleDevice()) this.divWrapper.setAttribute("style", "overflow-x: hidden; overflow-y: auto; width:100%; height:100%; position: absolute; z-index: 99999; background:white; top:0px");
            else this.divWrapper.setAttribute("style", "width:100%; height:100%; position: absolute; z-index: 99999; background:white; top:0px");
            this.divWrapper.style.setProperty("-webkit-overflow-scrolling", "touch");
            this.divWrapper.style.setProperty("-webkit-user-select", "none");
            this.divWrapper.style.setProperty("-webkit-text-size-adjust", "none");
        };
        wildFuryRules.RulesInstance.prototype.isAppleDevice = function() {
            return new _hcmn_.EReg("iP(hone|od|ad)", "").match(window.navigator.platform);
        };
        wildFuryRules.RulesInstance.prototype.onResize = function() {
            this.setDivWrapperStyle();
            _hcmn_.haxe_Timer.delay($bind(this, this.updateIFrame), 0);
        };
        wildFuryRules.RulesInstance.prototype.updateIFrame = function() {
            if (this.iframe == null || this.iframe.contentWindow == null || this.iframe.contentWindow.document == null) {
                window.removeEventListener("resize", $bind(this, this.onResize));
                this.iframe.removeEventListener("load", $bind(this, this.onLoad));
                this.divWrapper = null;
                this.iframe = null;
                return;
            }
            this.iframe.height = this.iframe.contentWindow.document.body.scrollHeight + "px";
        };
        wildFuryRules.RulesInstance.prototype.closeListener = function(event) {
            if ("rules:close" + this.id == event.data) {
                window.document.removeEventListener("message", $bind(this, this.closeListener));
                this.close();
            }
        };
        wildFuryRules.RulesInstance.prototype.close = function() {
            if (this.node == null) return;
            if (this.node.parentNode != null) this.node.parentNode.removeChild(this.node);
            this.node = null;
            if (this.closeCallback != null) this.closeCallback();
        };
        wildFuryRules.RulesInstance.prototype.__class__ = wildFuryRules.RulesInstance;
        if (typeof haxe == 'undefined') {
            var haxe = {};
        };

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

        };
        return {
            exports: wildFuryRules,
            activator: wildFuryRules.ModuleActivator
        };
    });
//# sourceURL=wildFuryRules.js