text: !function(){"use strict";function t(){document.removeEventListener("touchstart",t),createjs.WebAudioPlugin.playEmptySound()}var n=cloudkid.OS,i=cloudkid.MediaLoader,s=cloudkid.LoadTask,e=cloudkid.Task,a=cloudkid.TaskManager,o=function(){this._sounds={},this._fades=[],this._contexts={},this._pool=[],this._update=this._update.bind(this),this._markLoaded=this._markLoaded.bind(this),this._playAfterLoadBound=this._playAfterLoad.bind(this)},l=o.prototype={},u=null;l._sounds=null,l._fades=null,l._pool=null,l.supportedSound=null,l._contexts=null;var d=0,r=1,h=2,c="CKSOUND";o.UNHANDLED="unhandled",o.init=function(n,i,s){return createjs.Sound.registerPlugins(n),createjs.Sound.BrowserDetect.isIOS&&document.addEventListener("touchstart",t),u=new o,createjs.Sound.getCapabilities()?u._initComplete(i,s):createjs.Sound.activePlugin?cloudkid.OS.instance.addUpdateCallback("SoundInit",function(){createjs.Sound.getCapabilities()&&(cloudkid.OS.instance.removeUpdateCallback("SoundInit"),u._initComplete(i,s))}):Debug.error("Unable to initialize SoundJS with a plugin!"),u},l._initComplete=function(t,n){if(createjs.FlashPlugin&&createjs.Sound.activePlugin instanceof createjs.FlashPlugin)u.supportedSound=".mp3";else for(var i=0;i<t.length;++i){var s=t[i];if(createjs.Sound.getCapability(s)){u.supportedSound="."+s;break}}n&&n()},Object.defineProperty(o,"instance",{get:function(){return u}}),l.loadConfig=function(t,n){if(!t)return void Debug.warn("Warning - cloudkid.Sound was told to load a null config");var i=t.soundManifest,s=t.path;n=n||t.context;for(var e=0,a=i.length;a>e;++e){var o=i[e],l=this._sounds[o.id]={id:o.id,src:s+o.src+this.supportedSound,volume:o.volume?o.volume:1,state:d,playing:[],waitingToPlay:[],context:o.context||n,playAfterLoad:!1,preloadCallback:null,data:o};l.context&&(this._contexts[l.context]||(this._contexts[l.context]=new f(l.context)),this._contexts[l.context].sounds.push(l))}},l.exists=function(t){return!!this._sounds[t]},l.isUnloaded=function(t){return this._sounds[t]?this._sounds[t].state==d:!1},l.isLoaded=function(t){return this._sounds[t]?this._sounds[t].state==h:!1},l.isLoading=function(t){return this._sounds[t]?this._sounds[t].state==r:!1},l.isPlaying=function(t){var n=this._sounds[t];return n?n.playing.length+n.waitingToPlay.length>0:!1},l.fadeIn=function(t,i,s,e){var a,o;if("string"==typeof t){if(a=this._sounds[t],!a)return;a.playing.length&&(o=a.playing[a.playing.length-1])}else o=t,a=this._sounds[o.alias];if(o&&o._channel){o._fTime=0,o._fDur=i>0?i:500;var l=e>0?e:0;o._channel.setVolume(l),o.curVol=o._fStart=l,o._fEnd=s||a.volume,-1==this._fades.indexOf(o)&&(this._fades.push(o),1==this._fades.length&&n.instance.addUpdateCallback(c,this._update))}},l.fadeOut=function(t,i,s,e){var a,o;if("string"==typeof t){if(a=this._sounds[t],!a)return;a.playing.length&&(o=a.playing[a.playing.length-1])}else o=t;o&&o._channel&&(o._fTime=0,o._fDur=i>0?i:500,e>0?(o._channel.setVolume(e),o._fStart=e):o._fStart=o._channel.getVolume(),o.curVol=o._fStart,o._fEnd=s||0,-1==this._fades.indexOf(o)&&(this._fades.push(o),1==this._fades.length&&n.instance.addUpdateCallback(c,this._update)))},l._update=function(t){for(var i=this._fades,s=0,e=i.length-1;e>=0;--e){var a=i[e];if(!a.paused){var o=a._fTime+=t;if(o>=a._fDur){if(0===a._fEnd){var l=this._sounds[a.alias];l.playing=l.playing.splice(l.playing.indexOf(a),1),this._stopInst(a)}else a.curVol=a._fEnd,a.updateVolume();++s;var u=i.length-s;e!=u&&(i[e]=i[u])}else{var d,r=o/a._fDur;d=a._fEnd>a._fStart?a._fStart+(a._fEnd-a._fStart)*r:a._fEnd+(a._fStart-a._fEnd)*r,a.curVol=d,a.updateVolume()}}}i.length=i.length-s,0===i.length&&n.instance.removeUpdateCallback(c)},l.play=function(t,n,s,e,a,l,u,c,p){if(u===!0&&(u=-1),n==o.UNHANDLED)return createjs.Sound.play(t,e,a,l,u,c,p);var _=this._sounds[t];if(!_)return Debug.error("cloudkid.Sound: sound "+t+" not found!"),void(n&&n());var f,g,y=_.state;if(c="number"==typeof c&&c>0?c:_.volume,y==h){var v=createjs.Sound.play(t,e,a,l,u,c,p);return v&&v.playState!=createjs.Sound.PLAY_FAILED?(f=this._getSoundInst(v,_.id),v.handleExtraData&&v.handleExtraData(_.data),f.curVol=c,_.playing.push(f),f._endCallback=n,f.updateVolume(),f.length=v.getDuration(),f._channel.addEventListener("complete",f._endFunc),s&&setTimeout(s,0),f):(n&&n(),null)}return y==d?(_.state=r,_.playAfterLoad=!0,f=this._getSoundInst(null,_.id),f.curVol=c,_.waitingToPlay.push(f),f._endCallback=n,f._startFunc=s,f._startParams?(g=f._startParams,g[0]=e,g[1]=a,g[2]=l,g[3]=u,g[4]=p):f._startParams=[e,a,l,u,p],i.instance.load(_.src,this._playAfterLoadBound,null,0,_),f):y==r?(_.playAfterLoad=!0,f=this._getSoundInst(null,_.id),f.curVol=c,_.waitingToPlay.push(f),f._endCallback=n,f._startFunc=s,f._startParams?(g=f._startParams,g[0]=e,g[1]=a,g[2]=l,g[3]=u,g[4]=p):f._startParams=[e,a,l,u,p],f):void 0},l._getSoundInst=function(t,n){var i;return this._pool.length?i=this._pool.pop():(i=new p,i._endFunc=this._onSoundComplete.bind(this,i)),i._channel=t,i.alias=n,i.length=t?t.getDuration():0,i.isValid=!0,i},l._playAfterLoad=function(t){var n="string"==typeof t?t:t.id,i=this._sounds[n];if(i.state=h,i.playAfterLoad){for(var s=i.waitingToPlay,e=0;e<s.length;++e){var a=s[e],o=a._startParams,l=a.curVol,u=createjs.Sound.play(n,o[0],o[1],o[2],o[3],l,o[4]);u&&u.playState!=createjs.Sound.PLAY_FAILED?(i.playing.push(a),a._channel=u,u.handleExtraData&&u.handleExtraData(i.data),a.length=u.getDuration(),a.updateVolume(),u.addEventListener("complete",a._endFunc),a._startFunc&&a._startFunc(),a.paused&&u.pause()):(a._endCallback&&a._endCallback(),this._poolInst(a))}s.length=0}},l._onSoundComplete=function(t){t._channel.removeEventListener("complete",t._endFunc);var n=this._sounds[t.alias];n.playing.splice(n.playing.indexOf(t),1);var i=t._endCallback;this._poolInst(t),i&&i()},l.stop=function(t){var n=this._sounds[t];if(n)if(n.playing.length)this._stopSound(n);else if(n.state==r){n.playAfterLoad=!1;for(var i=n.waitingToPlay,s=0;s<i.length;++s){var e=i[s];this._poolInst(e)}i.length=0}},l._stopSound=function(t){for(var n=t.playing,i=n.length-1;i>=0;--i)this._stopInst(n[i]);n.length=0},l._stopInst=function(t){t._channel.removeEventListener("complete",t._endFunc),t._channel.stop(),this._poolInst(t)},l.stopContext=function(t){if(t=this._contexts[t])for(var n=t.sounds,i=n.length-1;i>=0;--i){var s=n[i];s.playing.length?this._stopSound(s):s.state==r&&(s.playAfterLoad=!1)}},l.pauseSound=function(t){var n;n="string"==typeof t?this._sounds[t]:t;for(var i=n.playing,s=i.length-1;s>=0;--s)i[s].pause()},l.unpauseSound=function(t){var n;n="string"==typeof t?this._sounds[t]:t;for(var i=n.playing,s=i.length-1;s>=0;--s)i[s].unpause()},l.pauseAll=function(){var t=this._sounds;for(var n in t)this.pauseSound(t[n])},l.unpauseAll=function(){var t=this._sounds;for(var n in t)this.unpauseSound(t[n])},l.setContextMute=function(t,n){if(t=this._contexts[t]){t.muted=n;for(var i=t.volume,s=t.sounds,e=s.length-1;e>=0;--e){var a=s[e];if(a.playing.length)for(var o=a.playing,l=o.length-1;l>=0;--l)o[l].updateVolume(n?0:i)}}},l.setContextVolume=function(t,n){if(t=this._contexts[t]){var i=t.muted;t.volume=n;for(var s=t.sounds,e=s.length-1;e>=0;--e){var a=s[e];if(a.playing.length)for(var o=a.playing,l=o.length-1;l>=0;--l)o[l].updateVolume(i?0:n)}}},l.preloadSound=function(t,n){var s=this._sounds[t];return s?void(s.state==d&&(s.state=r,s.preloadCallback=n||null,i.instance.load(s.src,this._markLoaded,null,0,s))):void Debug.error("Sound does not exist: "+t+" - can't preload!")},l.preload=function(t,n){if(!t||0===t.length)return void(n&&n());for(var i=[],e=0,o=t.length;o>e;++e){var l=this._sounds[t[e]];l?l.state==d&&(l.state=r,i.push(new s(l.id,l.src,this._markLoaded,null,0,l))):Debug.error("cloudkid.Sound was asked to preload "+t[e]+" but it is not a registered sound!")}i.length>0?a.process(i,function(){n&&n()}):n&&n()},l._markLoaded=function(t){var n=t.id,i=this._sounds[n];i&&(i.state=h,i.playAfterLoad&&this._playAfterLoad(n));var s=i.preloadCallback;s&&(i.preloadCallback=null,s())},l.createPreloadTask=function(t,n,i){return _?new _(t,n,i):null},l.unload=function(t){if(t)for(var n=0,i=t.length;i>n;++n){var s=this._sounds[t[n]];s&&(this._stopSound(s),s.state=d),createjs.Sound.removeSound(t[n])}},l._poolInst=function(t){t._endCallback=null,t.alias=null,t._channel=null,t._startFunc=null,t.curVol=0,t.paused=!1,t.isValid=!1,this._pool.push(t)},l.destroy=function(){u=null,this._volumes=null,this._fades=null,this._contexts=null,this._pool=null};var p=function(){this._channel=null,this._endFunc=null,this._endCallback=null,this._startFunc=null,this._startParams=null,this.alias=null,this._fTime=0,this._fDur=0,this._fStart=0,this._fEnd=0,this.curVol=0,this.length=0,this.paused=!1,this.isValid=!0};Object.defineProperty(p.prototype,"position",{get:function(){return this._channel?this._channel.getPosition():0}}),p.prototype.stop=function(){var t=o.instance,n=t._sounds[this.alias];n.playing.splice(n.playing.indexOf(this),1),o.instance._stopInst(this)},p.prototype.updateVolume=function(t){if(this._channel){if(void 0===t){var n=o.instance,i=n._sounds[this.alias];if(i.context){var s=n._contexts[i.context];t=s.muted?0:s.volume}else t=1}this._channel.setVolume(t*this.curVol)}},p.prototype.pause=function(){this.paused||(this.paused=!0,this._channel&&this._channel.pause())},p.prototype.unpause=function(){this.paused&&(this.paused=!1,this._channel&&this._channel.resume())};var _;e&&(_=function(t,n,i){this.initialize(t,i),this.list=n},_.prototype=Object.create(e.prototype),_.s=e.prototype,_.prototype.start=function(t){u.preload(this.list,t)},_.prototype.destroy=function(){_.s.destroy.apply(this),this.list=null});var f=function(t){this.id=t,this.volume=1,this.muted=!1,this.sounds=[]};f.prototype={},namespace("cloudkid").Sound=o}(),function(){"use strict";var t,n,i=cloudkid.Sound,s=function(i){t=cloudkid.Captions,n=cloudkid.OS,this._audioListener=this._onAudioFinished.bind(this),this._update=this._update.bind(this),this._updateCaptionPos=this._updateCaptionPos.bind(this),i&&(this.captions=i instanceof t?i:new t,this.captions.isSlave=!0),this._listHelper=[]},e=s.prototype={};e.trackAudio=!1,e.audioList=null,e._listCounter=0,e._currentAudio=null,e._audioInst=null,e._callback=null,e._cancelledCallback=null,e._audioListener=null,e._playedAudio=null,e._timer=0,e.captions=null,e._listHelper=null,Object.defineProperty(e,"playing",{get:function(){return null!==this._currentAudio||this._timer>0}}),e.play=function(t,n,i){this.stop(),this._listCounter=-1,this._listHelper[0]=t,this.audioList=this._listHelper,this._callback=n,this._cancelledCallback=i,this._onAudioFinished()},e.playList=function(t,n,i){this.stop(),this._listCounter=-1,this.audioList=t,this._callback=n,this._cancelledCallback=i,this._onAudioFinished()},e._onAudioFinished=function(){if(n.instance.removeUpdateCallback("VOPlayer"),this.captions&&this._audioInst&&this.captions.seek(this._audioInst.length),this._audioInst=null,this._listCounter++,this._listCounter>=this.audioList.length){this.captions&&this.captions.stop(),this._currentAudio=null,this._cancelledCallback=null;var t=this._callback;this._callback=null,t&&t()}else this._currentAudio=this.audioList[this._listCounter],"string"==typeof this._currentAudio?this._playAudio():"function"==typeof this._currentAudio?(this._currentAudio(),this._onAudioFinished()):(this._timer=this._currentAudio,this._currentAudio=null,n.instance.addUpdateCallback("VOPlayer",this._update))},e._update=function(t){this.captions&&this.captions.updateTime(t),this._timer-=t,this._timer<=0&&this._onAudioFinished()},e._updateCaptionPos=function(){this._audioInst&&this.captions.seek(this._audioInst.position)},e._playAudio=function(){this.trackAudio&&(this._playedAudio?-1==this._playedAudio.indexOf(this._currentAudio)&&this._playedAudio.push(this._currentAudio):this._playedAudio=[this._currentAudio]);var t=i.instance;!t.exists(this._currentAudio)&&this.captions&&this.captions.hasCaption(this._currentAudio)?(this.captions.play(this._currentAudio),this._timer=this.captions.currentDuration,this._currentAudio=null,n.instance.addUpdateCallback("VOPlayer",this._update)):(this._audioInst=t.play(this._currentAudio,this._audioListener),this.captions&&(this.captions.play(this._currentAudio),n.instance.addUpdateCallback("VOPlayer",this._updateCaptionPos)));for(var s=this._listCounter+1;s<this.audioList.length;++s){var e=this.audioList[s];if("string"==typeof e){t.isLoaded(e)||t.preloadSound(e);break}}},e.stop=function(){this._currentAudio&&(i.instance.stop(this._currentAudio),this._currentAudio=null),this.captions&&this.captions.stop(),n.instance.removeUpdateCallback("VOPlayer"),this.audioList=null,this._timer=0,this._callback=null;var t=this._cancelledCallback;this._cancelledCallback=null,t&&t()},e.unloadPlayedAudio=function(){i.instance.unload(this._playedAudio),this._playedAudio=null},e.destroy=function(){this.stop(),this.audioList=null,this._listHelper=null,this._currentAudio=null,this._audioInst=null,this._callback=null,this._cancelledCallback=null,this._audioListener=null,this._playedAudio=null,this.captions&&(this.captions.destroy(),this.captions=null)},namespace("cloudkid").VOPlayer=s,namespace("cloudkid").Sound.VOPlayer=s}();