define("soundmanager", ["componentmodelComponentApi", "clientkernelLoaderApi", "soundManagerApi", "clientkernelEventbusApi", "clientkernelModulesApi"],
    function(componentmodelComponentApi, clientkernelLoaderApi, soundManagerApi, 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 haxe == 'undefined') {
            var haxe = {};
        };

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

        };
        if (typeof js == 'undefined') {
            var js = {};
        };
        if (!js._Boot) {
            js._Boot = {};
        };
        js._Boot.HaxeError = function(val) {
            Error.call(this);
            this.val = val;
            this.message = String(val);
            if (Error.captureStackTrace) Error.captureStackTrace(this, js._Boot.HaxeError);
        };
        js._Boot.HaxeError.__name__ = ["js", "_Boot", "HaxeError"];
        js._Boot.HaxeError.__super__ = Error;
        for (var k in Error.prototype) js._Boot.HaxeError.prototype[k] = Error.prototype[k];
        js._Boot.HaxeError.prototype.val = null;
        js._Boot.HaxeError.prototype.__class__ = js._Boot.HaxeError;
        if (typeof soundmanager == 'undefined') {
            var soundmanager = {};
        };
        soundmanager.Activator = function(context) {};
        soundmanager.Activator = ck_implements(soundmanager.Activator, clientkernelModulesApi.IModuleActivator);
        soundmanager.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        soundmanager.Activator.__name__ = ["soundmanager", "Activator"];
        soundmanager.Activator.prototype.start = function(context) {
            context.getServiceTracker([clientkernelLoaderApi.IAssetRegistry]).then(function(context1) {
                soundmanager.ExternalService.initialize(context1);
                if (!soundmanager.ExternalService.checkIsIE()) soundmanager.ExternalService.assetRegistry.getAsset("soundplayer-assets/sounds").getContent().then(function(sound) {
                    context1.registerService(new soundmanager.SoundManagerFactory(context1, sound), soundManagerApi.SoundManagerDeclaration, null);
                });
                else soundmanager.ExternalService.assetRegistry.getAsset("soundplayer-assets/soundsIE").getContent().then(function(sound1) {
                    soundmanager.ExternalService.assetRegistry.getAsset("soundplayer-assets/soundMapIE").getContent().then(function(map) {
                        soundmanager.ExternalService.soundMapIE = map;
                        context1.registerService(new soundmanager.SoundManagerFactory(context1, sound1), soundManagerApi.SoundManagerDeclaration, null);
                    });
                });
            });
        };
        soundmanager.Activator.prototype.stop = function(context) {};
        soundmanager.Activator.main = function() {};
        soundmanager.Activator.prototype.__class__ = soundmanager.Activator;
        soundmanager.ExternalService = function() {};
        soundmanager.ExternalService.__name__ = ["soundmanager", "ExternalService"];
        soundmanager.ExternalService.assetRegistry = null;
        soundmanager.ExternalService.variableRegistry = null;
        soundmanager.ExternalService.soundMapIE = null;
        soundmanager.ExternalService.initialize = function(context) {
            soundmanager.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
            soundmanager.ExternalService.variableRegistry = context.getAnyService(clientkernelLoaderApi.IVariableRegistry, null);
        };
        soundmanager.ExternalService.isMobileGame = function() {
            if (soundmanager.ExternalService.variableRegistry.get("skin") == "mobile" || soundmanager.ExternalService.variableRegistry.get("assetPack") == "mobile") return true;
            return false;
        };
        soundmanager.ExternalService.checkIsIE = function() {
            var ua = window.navigator.userAgent;
            var trident = ua.indexOf("Trident/");
            if (trident > -1) return true;
            else return false;
        };
        soundmanager.ExternalService.prototype.__class__ = soundmanager.ExternalService;
        soundmanager.SoundComponent = function(sound) {
            this.muted = false;
            this.map = new _hcmn_.haxe_ds_StringMap();
            this.sound = sound;
            this.events = new soundmanager.SoundEvents();
            Visibility.change($bind(this, this.handleVisibilityChange));
        };
        soundmanager.SoundComponent.__name__ = ["soundmanager", "SoundComponent"];
        soundmanager.SoundComponent.prototype.sound = null;
        soundmanager.SoundComponent.prototype.map = null;
        soundmanager.SoundComponent.prototype.events = null;
        soundmanager.SoundComponent.prototype.muted = null;
        soundmanager.SoundComponent.prototype.getEvents = function() {
            return this.events;
        };
        soundmanager.SoundComponent.prototype.play = function(id) {
            if (!this.map.exists(id)) {
                var value = this.sound.play(id);
                this.map.set(id, value);
                this.attachToEvents(id);
            } else {
                this.stop(id);
                this.play(id);
            }
        };
        soundmanager.SoundComponent.prototype.stop = function(id) {
            if (id == null) this.sound.stop();
            if (this.map.exists(id)) {
                this.sound.stop(this.map.get(id));
                this.map.remove(id);
            }
        };
        soundmanager.SoundComponent.prototype.muteAll = function() {
            Howler.mute(true);
            this.muted = true;
        };
        soundmanager.SoundComponent.prototype.unmuteAll = function() {
            Howler.mute(false);
            this.muted = false;
        };
        soundmanager.SoundComponent.prototype.mute = function(id) {};
        soundmanager.SoundComponent.prototype.unmute = function(id) {};
        soundmanager.SoundComponent.prototype.pause = function(id) {
            if (this.map.exists(id)) this.sound.pause(this.map.get(id));
        };
        soundmanager.SoundComponent.prototype.setRate = function(data) {
            if (this.map.exists(data.soundId)) this.sound.rate(data.rate, this.map.get(data.soundId));
        };
        soundmanager.SoundComponent.prototype.setVolume = function(data) {
            if (this.map.exists(data.soundId)) this.sound.volume(data.volume, this.map.get(data.soundId));
        };
        soundmanager.SoundComponent.prototype.fadeIn = function(properties) {
            if (!this.map.exists(properties.soundId)) {
                this.attachToEvents(properties.soundId);
                var value = this.sound.play(properties.soundId);
                this.map.set(properties.soundId, value);
                this.sound.fade(0, 1, properties.length, this.map.get(properties.soundId));
            } else {
                this.sound.off("fade", null, this.map.get(properties.soundId));
                this.stop(properties.soundId);
                this.fadeIn(properties);
            }
        };
        soundmanager.SoundComponent.prototype.fadeOut = function(properties) {
            var _g = this;
            if (this.map.exists(properties.soundId)) {
                this.sound.fade(1, 0, properties.length, this.map.get(properties.soundId));
                this.sound.on("fade", function(id) {
                    _g.sound.stop(id);
                    _g.map.remove(properties.soundId);
                }, this.map.get(properties.soundId));
            }
        };
        soundmanager.SoundComponent.prototype.onPlay = function(id) {
            var _g = this;
            this.sound.once("play", function(i) {
                _g.events.ON_PLAY().dispatch(id);
            }, this.map.get(id));
        };
        soundmanager.SoundComponent.prototype.onFinish = function(id) {
            var _g = this;
            this.sound.once("end", function(i) {
                if (!_g.sound.loop(i)) _g.events.ON_FINISH().dispatch(id);
            }, this.map.get(id));
        };
        soundmanager.SoundComponent.prototype.onStop = function(id) {
            var _g = this;
            this.sound.once("stop", function(i) {
                _g.events.ON_STOP().dispatch(id);
                _g.events.ON_FINISH().dispatch(id);
            }, this.map.get(id));
        };
        soundmanager.SoundComponent.prototype.onPause = function(id) {
            var _g = this;
            this.sound.on("pause", function(i) {
                _g.events.ON_PAUSE().dispatch(id);
            }, this.map.get(id));
        };
        soundmanager.SoundComponent.prototype.onFade = function(id) {
            var _g = this;
            this.sound.on("fade", function(i) {
                if (_g.sound.volume(i) == 0 || _g.sound.volume(i) == 1) {
                    if (_g.sound.volume(i) == 0) _g.sound.off("fade", null, i);
                    _g.events.ON_FADE().dispatch(new soundManagerApi.SoundFadeData(id, _g.sound.volume(i)));
                }
            }, this.map.get(id));
        };
        soundmanager.SoundComponent.prototype.onRate = function(id) {
            this.sound.on("rate", function(i) {}, this.map.get(id));
        };
        soundmanager.SoundComponent.prototype.attachToEvents = function(id) {
            this.onStop(id);
            this.onFinish(id);
        };
        soundmanager.SoundComponent.prototype.handleVisibilityChange = function(e, state) {
            if (state == "hidden") Howler.mute(true);
            else if (state == "visible" && !this.muted) Howler.mute(false);
        };
        soundmanager.SoundComponent.prototype.__class__ = soundmanager.SoundComponent;
        soundmanager.SoundComponentIE = function(sound, loopMap) {
            this.soundMap = sound;
            this.loopMap = loopMap;
            this.events = new soundmanager.SoundEvents();
            Visibility.change($bind(this, this.handleVisibilityChange));
        };
        soundmanager.SoundComponentIE.__name__ = ["soundmanager", "SoundComponentIE"];
        soundmanager.SoundComponentIE.prototype.soundMap = null;
        soundmanager.SoundComponentIE.prototype.events = null;
        soundmanager.SoundComponentIE.prototype.loopMap = null;
        soundmanager.SoundComponentIE.prototype.getEvents = function() {
            return this.events;
        };
        soundmanager.SoundComponentIE.prototype.play = function(id) {
            if (!this.soundMap.exists(id)) return;
            if (this.soundMap.get(id).playing()) this.soundMap.get(id).stop();
            this.soundMap.get(id).play();
            this.soundMap.get(id).loop(this.loopMap.get(id));
        };
        soundmanager.SoundComponentIE.prototype.stop = function(id) {
            if (id == null) {
                var $it0 = this.soundMap.keys();
                while ($it0.hasNext()) {
                    var key = $it0.next();
                    this.soundMap.get(key).stop();
                }
            }
            if (!this.soundMap.exists(id)) return;
            this.soundMap.get(id).loop(false);
            this.soundMap.get(id).stop();
        };
        soundmanager.SoundComponentIE.prototype.muteAll = function() {
            Howler.mute(true);
        };
        soundmanager.SoundComponentIE.prototype.unmuteAll = function() {
            Howler.mute(false);
        };
        soundmanager.SoundComponentIE.prototype.mute = function(id) {};
        soundmanager.SoundComponentIE.prototype.unmute = function(id) {};
        soundmanager.SoundComponentIE.prototype.pause = function(id) {
            if (!this.soundMap.exists(id)) return;
            this.soundMap.get(id).pause();
        };
        soundmanager.SoundComponentIE.prototype.setRate = function(data) {};
        soundmanager.SoundComponentIE.prototype.setVolume = function(data) {
            if (!this.soundMap.exists(data.soundId)) return;
            this.soundMap.get(data.soundId).volume(data.volume);
        };
        soundmanager.SoundComponentIE.prototype.fadeIn = function(properties) {
            if (!this.soundMap.exists(properties.soundId)) return;
            if (this.soundMap.get(properties.soundId).playing()) this.soundMap.get(properties.soundId).stop();
            this.soundMap.get(properties.soundId).play();
            this.soundMap.get(properties.soundId).fade(0, 1, properties.length);
            this.soundMap.get(properties.soundId).loop(this.loopMap.get(properties.soundId));
        };
        soundmanager.SoundComponentIE.prototype.fadeOut = function(properties) {
            if (!this.soundMap.exists(properties.soundId)) return;
            this.soundMap.get(properties.soundId).fade(1, 0, properties.length);
            if (this.soundMap.get(properties.soundId).loop()) this.soundMap.get(properties.soundId).loop(false);
        };
        soundmanager.SoundComponentIE.prototype.onPlay = function(id) {};
        soundmanager.SoundComponentIE.prototype.onFinish = function(id) {};
        soundmanager.SoundComponentIE.prototype.onStop = function(id) {};
        soundmanager.SoundComponentIE.prototype.onPause = function(id) {};
        soundmanager.SoundComponentIE.prototype.onFade = function(id) {};
        soundmanager.SoundComponentIE.prototype.onRate = function(id) {};
        soundmanager.SoundComponentIE.prototype.attachToEvents = function(id) {
            this.onPlay(id);
            this.onStop(id);
            this.onPause(id);
            this.onFade(id);
            this.onFinish(id);
        };
        soundmanager.SoundComponentIE.prototype.handleVisibilityChange = function(e, state) {
            if (state == "hidden") Howler.mute(true);
            else if (state == "visible") Howler.mute(false);
        };
        soundmanager.SoundComponentIE.prototype.__class__ = soundmanager.SoundComponentIE;
        soundmanager.SoundManager = function(context, sound) {
            this.assetsLoaded = false;
            this.ccontext = context;
            this.port = this.ccontext.getImplementedPort(soundManagerApi.ISoundManagerImplementationPort);
            if (!soundmanager.ExternalService.checkIsIE()) {
                this.soundComponent = new soundmanager.SoundComponent(sound);
                this.initialize();
            } else {
                var loopMap = new _hcmn_.haxe_ds_StringMap();
                var map = soundmanager.ExternalService.soundMapIE;
                var _g = 0;
                var _g1 = _hcmn_.Reflect.fields(map);
                while (_g < _g1.length) {
                    var key = _g1[_g];
                    ++_g;
                    if (map[key].length == 3 && map[key][2] == 1) {
                        if (_hcmn_.__map_reserved[key] != null) loopMap.setReserved(key, true);
                        else loopMap.h[key] = true;
                    } else if (_hcmn_.__map_reserved[key] != null) loopMap.setReserved(key, false);
                    else loopMap.h[key] = false;
                }
                this.soundComponent = new soundmanager.SoundComponentIE(sound, loopMap);
                this.initialize();
            }
        };
        soundmanager.SoundManager.__name__ = ["soundmanager", "SoundManager"];
        soundmanager.SoundManager.prototype.port = null;
        soundmanager.SoundManager.prototype.ccontext = null;
        soundmanager.SoundManager.prototype.assetsLoaded = null;
        soundmanager.SoundManager.prototype.soundComponent = null;
        soundmanager.SoundManager.prototype.initialize = function() {
            this.port.play().subscribe($bind(this, this.handlePlay));
            this.port.stop().subscribe($bind(this, this.handleStop));
            this.port.fadeIn().subscribe($bind(this, this.handleFadeIn));
            this.port.fadeOut().subscribe($bind(this, this.handleFadeOut));
            this.port.mute().subscribe($bind(this, this.handleMute));
            this.port.muteAll().subscribe($bind(this, this.handleMuteAll));
            this.port.unmute().subscribe($bind(this, this.handleUnmute));
            this.port.unmuteAll().subscribe($bind(this, this.handleUnmuteAll));
            this.port.pause().subscribe($bind(this, this.handlePause));
            this.port.volume().subscribe($bind(this, this.handleVolume));
            this.port.rate().subscribe($bind(this, this.handleRate));
            this.soundComponent.getEvents().ON_PLAY().addListener($bind(this, this.handleOnPlay));
            this.soundComponent.getEvents().ON_STOP().addListener($bind(this, this.handleOnStop));
            this.soundComponent.getEvents().ON_FINISH().addListener($bind(this, this.handleOnFinish));
            this.soundComponent.getEvents().ON_PAUSE().addListener($bind(this, this.handleOnPause));
            this.soundComponent.getEvents().ON_FADE().addListener($bind(this, this.handleOnFade));
        };
        soundmanager.SoundManager.prototype.handlePlay = function(e) {
            this.soundComponent.play(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleStop = function(e) {
            this.soundComponent.stop(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleFadeIn = function(e) {
            this.soundComponent.fadeIn(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleFadeOut = function(e) {
            this.soundComponent.fadeOut(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleMute = function(e) {
            this.soundComponent.mute(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleMuteAll = function(e) {
            this.soundComponent.muteAll();
        };
        soundmanager.SoundManager.prototype.handleUnmute = function(e) {
            this.soundComponent.unmute(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleUnmuteAll = function(e) {
            this.soundComponent.unmuteAll();
        };
        soundmanager.SoundManager.prototype.handlePause = function(e) {
            this.soundComponent.pause(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleVolume = function(e) {
            this.soundComponent.setVolume(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleRate = function(e) {
            this.soundComponent.setRate(e.getPayload());
        };
        soundmanager.SoundManager.prototype.handleOnPlay = function(e) {
            this.port.onPlay().publish(e);
        };
        soundmanager.SoundManager.prototype.handleOnStop = function(e) {
            this.port.onStop().publish(e);
        };
        soundmanager.SoundManager.prototype.handleOnFinish = function(e) {
            this.port.onFinish().publish(e);
        };
        soundmanager.SoundManager.prototype.handleOnPause = function(e) {
            this.port.onPause().publish(e);
        };
        soundmanager.SoundManager.prototype.handleOnFade = function(e) {
            this.port.onFade().publish("");
        };
        soundmanager.SoundManager.prototype.__class__ = soundmanager.SoundManager;
        soundmanager.SoundManagerFactory = function(context, sound) {
            this.context = context;
            this.sound = sound;
        };
        soundmanager.SoundManagerFactory = ck_implements(soundmanager.SoundManagerFactory, clientkernelModulesApi.IService);
        soundmanager.SoundManagerFactory = ck_implements(soundmanager.SoundManagerFactory, componentmodelComponentApi.IComponentFactory);
        soundmanager.SoundManagerFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        soundmanager.SoundManagerFactory.__name__ = ["soundmanager", "SoundManagerFactory"];
        soundmanager.SoundManagerFactory.prototype.context = null;
        soundmanager.SoundManagerFactory.prototype.sound = null;
        soundmanager.SoundManagerFactory.prototype.getComponentDeclaration = function() {
            return soundManagerApi.SoundManagerDeclaration;
        };
        soundmanager.SoundManagerFactory.prototype.createComponent = function(context) {
            new soundmanager.SoundManager(context, this.sound);
        };
        soundmanager.SoundManagerFactory.prototype.__class__ = soundmanager.SoundManagerFactory;
        soundmanager.BaseEvent = function() {
            this._signal = new _hcmn_.msignal_Signal1();
        };
        soundmanager.BaseEvent.__name__ = ["soundmanager", "BaseEvent"];
        soundmanager.BaseEvent.prototype._signal = null;
        soundmanager.BaseEvent.prototype.addListener = function(listener) {
            this._signal.add(listener);
        };
        soundmanager.BaseEvent.prototype.removeListener = function(listener) {
            this._signal.remove(listener);
        };
        soundmanager.BaseEvent.prototype.dispatch = function(data) {
            this._signal.dispatch(data);
        };
        soundmanager.BaseEvent.prototype.__class__ = soundmanager.BaseEvent;
        soundmanager.SoundEvents = function() {
            this.onPlay = new soundmanager.BaseEvent();
            this.onFinish = new soundmanager.BaseEvent();
            this.onStop = new soundmanager.BaseEvent();
            this.onPause = new soundmanager.BaseEvent();
            this.onFade = new soundmanager.BaseEvent();
        };
        soundmanager.SoundEvents.__name__ = ["soundmanager", "SoundEvents"];
        soundmanager.SoundEvents.prototype.onPlay = null;
        soundmanager.SoundEvents.prototype.onFinish = null;
        soundmanager.SoundEvents.prototype.onStop = null;
        soundmanager.SoundEvents.prototype.onPause = null;
        soundmanager.SoundEvents.prototype.onMute = null;
        soundmanager.SoundEvents.prototype.onFade = null;
        soundmanager.SoundEvents.prototype.ON_PLAY = function() {
            return this.onPlay;
        };
        soundmanager.SoundEvents.prototype.ON_FINISH = function() {
            return this.onFinish;
        };
        soundmanager.SoundEvents.prototype.ON_STOP = function() {
            return this.onStop;
        };
        soundmanager.SoundEvents.prototype.ON_PAUSE = function() {
            return this.onPause;
        };
        soundmanager.SoundEvents.prototype.ON_FADE = function() {
            return this.onFade;
        };
        soundmanager.SoundEvents.prototype.__class__ = soundmanager.SoundEvents;
        return {
            exports: soundmanager,
            activator: soundmanager.Activator
        };
    });
//# sourceURL=soundManager.js