text: /*! BlocksJS 0.5.11 2014-09-16
  
  Copyright (c) 2014 William Malone (www.williammalone.com)
  
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
  
  var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.block=function(a){"use strict";var b,c=BLOCKS.eventDispatcher(),d=[],e={},f=[],g=["stack","worldX","worldY","x","y","scale","width","height","centerRegistrationPoint","mirrorX","mirrorY","angle","alpha","layer","visible","dirty","justTapped","justNotTapped","dragging","justReleased","tapPos","cropWidth","cropHeight","frameOffsetX","frameOffsetY","offsetX","offsetY","minHotspot","hotspots"],h=["update","render","show","hide","pause","unpause","reset","stop","play","isPointInside","getBounds","getBoundingBox","isRectInside","gotoLastFrame","gotoFrame"],i=function(a){var b;for(a.removeEventListener("destroyed",i),b=0;b<f.length;b+=1){f.splice(b,1);break}};return a=a||{},c.name=a.name,c.addSlice=function(b){var f,h;if(h=BLOCKS.slice(b),b.name||(h.name="unnamedSlice"+d.length),d.push(h),e[b.name]=h,h.addEventListener("complete",function(){c.dispatchEvent("complete")}),1===d.length){for(f=0;f<g.length;f+=1)void 0!==a[g[f]]&&(h[g[f]]=a[g[f]]);c.setSlice(b.name)}return h},c.getSlice=function(a){return void 0===a?b:e[a]},c.setSlice=function(a,c){var d,f;if(f=e[a],f&&f!==b){if(b)for(d=0;d<g.length;d+=1)"width"!==g[d]&&"height"!==g[d]&&"offsetX"!==g[d]&&"offsetY"!==g[d]&&(f[g[d]]=b[g[d]]);return b=f,b.reset(),b.autoPlay&&b.play(c),b.dirty=!0,!0}return!1},c.motorize=function(a){a.addEventListener("destroyed",i),f.push(a)},c.removeMotors=function(a){var b,c=[];for(b=0;b<f.length;b+=1)a?f[b].type===a?f[b].destroy():c.push(f[b]):f[b].destroy();f=c},c.destroy=function(){var a;if(c){for(c.removeMotors(),a=0;a<d.length;a+=1)d[a].destroy();d=null,e=null,b=null,c.dispatchEvent("destroyed",c),c=null}},function(){var d,e=function(a){Object.defineProperty(c,a,{get:function(){return b?b[a]:void 0},set:function(c){b&&(b[a]=c)}})},f=function(a){c[a]=function(c){return b[a](c)}};for(d=0;d<g.length;d+=1)e(g[d]);for(d=0;d<h.length;d+=1)f(h[d]);if(a.slices)for(d=0;d<a.slices.length;d+=1)c.addSlice(a.slices[d])}(),c};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.camera=function(a){"use strict";var b=BLOCKS.eventDispatcher();return b.x=a&&a.x||0,b.y=a&&a.y||0,b.width=a&&a.width||1024,b.height=a&&a.height||768,b};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.clock=function(){"use strict";var a,b=BLOCKS.eventDispatcher(),c=!0,d=function(){c||(a=window.requestAnimationFrame(d),b.dispatchEvent("tick"))};return b.stop=function(){window.cancelAnimationFrame(a),c=!0},b.start=function(){c&&(c=!1,a=window.requestAnimationFrame(d))},b.destroy=function(){b.stop(),b=null},function(){for(var a=0,b=["webkit","moz"],c=0;c<b.length&&!window.requestAnimationFrame;++c)window.requestAnimationFrame=window[b[c]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[b[c]+"CancelAnimationFrame"]||window[b[c]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(b){var c=(new Date).getTime(),d=Math.max(0,16-(c-a)),e=window.setTimeout(function(){b(c+d)},d);return a=c+d,e}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(a){window.clearTimeout(a)})}(),b};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.container=function(){"use strict";var a=BLOCKS.eventDispatcher(),b=[],c=[],d=[],e=function(a){var c;for(a.removeEventListener("destroyed",e),c=0;c<b.length;c+=1){b.splice(c,1);break}};return a.visible=!0,a.dirty=!0,a.addView=function(b){var e,f;for(b.addEventListener("destroyed",a.removeView),d.push(b),e=0;e<c.length;e+=1)if(b.layer===c[e]){f=!0;break}!f&&b.layer&&c.push(b.layer)},a.removeView=function(b){var e,f,g;for(b.removeEventListener("destroyed",a.removeView),e=0;e<d.length;e+=1)if(b===d[e]){f=d.layer,d.splice(e,1);break}for(e=0;e<d.length;e+=1)if(b.layer===f){g=!0;break}if(!g)for(e=0;e<c.length;e+=1)if(f===c[e]){c.splice(e,1);break}},a.setViewLayerIndex=function(a,b){var c,e;for(c=0;c<d.length;c+=1)if(d[c]===a){e=c;break}void 0===c?BLOCKS.warn("Cannot find view to set view's layer index."):(d.splice(e,1),d.splice(b,0,a),a.dirty=!0)},a.getViewLayerIndex=function(a){var b,c;for(b=0;b<d.length;b+=1)if(d[b]===a){c=b;break}return c},a.clear=function(){var b;for(b=0;b<c.length;b+=1)a.layers[b].clear()},a.motorize=function(a){a.addEventListener("destroyed",e),b.push(a)},a.removeMotors=function(a){var c,d=[];for(c=0;c<b.length;c+=1)a?b[c].type===a?b[c].destroy():d.push(b[c]):b[c].destroy();b=d},a.update=function(){var a;for(a=0;a<d.length;a+=1)d[a].update()},a.render=function(b){var e,f,g={};for(e=0;e<c.length;e+=1)(c[e].dirty||a.dirty)&&(g[c[e].name]=c[e]);for(e=0;e<d.length;e+=1)d[e].dirty&&(g[d[e].layer.name]=d[e].layer);for(f in g)g.hasOwnProperty(f)&&g[f].clear();for(e=0;e<d.length;e+=1)g[d[e].layer.name]&&(d[e].dirty=!0),a.visible&&d[e].render(b);a.dirty=!1},a.destroy=function(){var e;for(e=0;e<d.length;e+=1)a.removeView(d[e]),d[e].destroy(),d[e]=null;d=null,c=null,b=null},a};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.controller=function(a){"use strict";var b,c=BLOCKS.eventDispatcher(),d=function(a){var b,c={x:a.offsetLeft,y:a.offsetTop};return a.offsetParent&&(b=d(a.offsetParent),c.x+=b.x,c.y+=b.y),c},e=function(){a||(a=document.getElementById("BlocksGame")),a.addEventListener("orientationchange",f,!0),document.addEventListener("keydown",g,!0),document.addEventListener("keyup",h,!0),a.addEventListener("touchstart",j,!0),a.addEventListener("touchmove",j,!0),a.addEventListener("touchend",j,!0),a.addEventListener("touchcancel",j,!0),a.addEventListener("mousedown",k,!0),a.addEventListener("mousemove",k,!0),a.addEventListener("mouseup",k,!0),a.addEventListener("mousecancel",k,!0),a.addEventListener("mouseout",k,!0),document.addEventListener("mouseup",function(a){k(a,!0)},!1)},f=function(){if(c.listening){switch(window.orientation){case-90:c.orientation="landscape";break;case 0:c.orientation="portrait";break;case 90:c.orientation="landscape";break;case 180:c.orientation="portrait"}c.dispatchEvent("orientationChange",{orientation:c.orientation})}},g=function(a){c.listening&&c.dispatchEvent("keyDown",a)},h=function(a){c.listening&&c.dispatchEvent("keyUp",a)},i=function(a,b){switch(b){case"tap":c.drag=!0,c.dispatchEvent("tap",a);break;case"drag":c.drag=!0,c.dispatchEvent("drag",a);break;case"release":c.drag=!1,c.dispatchEvent("release",a);break;case"cancel":c.drag=!1,c.dispatchEvent("cancel",a)}},j=function(e){var f,g,h,j,k;if(c.listening){e.preventDefault&&e.preventDefault(),b=d(a),k=e.changedTouches[0],h={};for(g in k)h[g]=k[g];for(h.x=(k.pageX-b.x-c.offsetX)*c.scaleX,h.y=(k.pageY-b.y-c.offsetY)*c.scaleY,h.type=e.type,h.touches=[],f=0;f<e.touches.length;f+=1){h.touches[f]={};for(g in e.touches[f])e.touches[f].hasOwnProperty(g)&&(h.touches[f][g]=e.touches[f][g]);h.touches[f].x=(h.touches[f].clientX-b.x-c.offsetX)*c.scaleX,h.touches[f].y=(h.touches[f].clientY-b.y-c.offsetY)*c.scaleY}for(h.changedTouches=[],f=0;f<e.changedTouches.length;f+=1){h.changedTouches[f]={};for(g in e.changedTouches[f])e.changedTouches[f].hasOwnProperty(g)&&(h.changedTouches[f][g]=e.changedTouches[f][g]);h.changedTouches[f].x=(h.changedTouches[f].pageX-b.x-c.offsetX)*c.scaleX,h.changedTouches[f].y=(h.changedTouches[f].pageY-b.y-c.offsetY)*c.scaleY}switch(h.type){case"touchstart":j="tap",c.dispatchEvent("touchStart",h);break;case"touchmove":j="drag",c.dispatchEvent("touchMove",h);break;case"touchend":j="release",c.dispatchEvent("touchEnd",h);break;case"touchcancel":j="cancel",c.dispatchEvent("touchCancel",h)}i(h,j)}},k=function(e,f){var g,h,j;if(c.listening){e.stopPropagation(),j={};for(g in e)j[g]=e[g];switch(b=d(a),j.x=(j.pageX-b.x-c.offsetX)*c.scaleX,j.y=(j.pageY-b.y-c.offsetY)*c.scaleY,j.identifier="mouse",j.touches=[j],j.changedTouches=[j],f&&(j.type+="outside"),j.type){case"mousedown":h="tap",c.dispatchEvent("mouseDown",j);break;case"mousemove":h="drag",c.dispatchEvent("mouseMove",j);break;case"mouseup":h="release",c.dispatchEvent("mouseUp",j);break;case"mousecancel":h="cancel",c.dispatchEvent("mouseCancel",j);break;case"mouseout":return h="mouseout",c.dispatchEvent("mouseOut",j),void 0;case"mouseupoutside":return h="mouseupoutside",c.dispatchEvent("mouseUpOutside",j),void 0}i(j,h)}};return c.scaleX=1,c.scaleY=1,c.offsetX=0,c.offsetY=0,c.listening=!0,c.simulateKeyDownEvent=function(a){g({keyCode:a})},c.simulateKeyUpEvent=function(a){h({keyCode:a})},e(),c};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.eventDispatcher=function(){"use strict";var a={},b={};return a.dispatchEvent=function(a,c){var d,e=[],f=[];if(b[a]){for(d=0;d<b[a].length;d+=1)e.push(b[a][d].callback),b[a][d].destroyOnDispatch||f.push(b[a][d]);for(b[a]=f,d=0;d<e.length;d+=1)e[d](c)}},a.addEventListener=function(a,c,d){b[a]||(b[a]=[]),b[a].push({name:a,callback:c,destroyOnDispatch:d})},a.removeEventListener=function(a,c){var d;if(b[a])for(d=0;d<b[a].length;d+=1)c?b[a][d].callback===c&&(b[a][d]=null,b[a].splice(d,1)):(b[a][d]=null,b[a].splice(d,1))},a.clearEventListeners=function(){b={}},a};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.game=function(a,b){"use strict";var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s=BLOCKS.eventDispatcher(),t=BLOCKS.clock(),u=!1,v=[],w=[],x=0,y=function(){var a,b=[],c=[];for(a=0;a<w.length;a+=1)w[a].curTick+=1,w[a].curTick>=w[a].totalTicks?c.push(w[a]):b.push(w[a]);for(w=b,a=0;a<c.length;a+=1)c[a].callback(c[a].parameters)},z=function(){(navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i))&&(90===window.orientation||-90===window.orientation)&&(window.scrollTo(0,0),U())},A=function(){document.hidden||document.webkitHidden||document.mozHidden||document.msHidden?s.pause():s.unpause()},B=function(){o||(s.controller.removeEventListener("tap",B),s.dispatchEvent("firstTap"),o=!0,s.introScreen&&(s.introScreen.destroy(),s.introScreen=null),s.state="loading",s.speaker.load(),T())},C=function(){var b;for(c=document.createElement("article"),c.id="BlocksGameContainer",a&&a.minWidth&&(i=a.minWidth,c.style.minWidth=i+"px"),a&&a.minHeight&&(j=a.minHeight,c.style.minHeight=j+"px"),a&&a.maxWidth&&(l=a.maxWidth,c.style.maxWidth=l+"px"),a&&a.maxHeight&&(k=a.maxHeight,c.style.maxHeight=k+"px"),m=a&&void 0!==a.scaleLandscape?a.scaleLandscape:!0,n=a&&void 0!==a.scalePortrait?a.scalePortrait:!0,s.element.appendChild(c),d=document.createElement("article"),d.id="BlocksInteractionContainer",c.appendChild(d),s.controller=BLOCKS.controller(d),b=0;10>b;b+=1)s.addLayer("blocksGameLayer"+(b+1));s.debug&&(e=BLOCKS.virtualKeyboard(s.controller,{layer:s.addLayer("internalblocksjsdebuglayer",{zIndex:999999},!1),customKeys:a.customVirtualKeys})),window.addEventListener("orientationchange",z),window.addEventListener("resize",U),U(),s.controller.addEventListener("keyUp",H),s.controller.addEventListener("keyDown",G),s.controller.addEventListener("tap",I),s.controller.addEventListener("drag",J),s.controller.addEventListener("release",K),s.controller.addEventListener("cancel",K),s.controller.addEventListener("touchStart",L),s.controller.addEventListener("touchMove",M),s.controller.addEventListener("touchEnd",N),s.controller.addEventListener("touchCancel",N),s.controller.addEventListener("mouseDown",O),s.controller.addEventListener("mouseMove",P),s.controller.addEventListener("mouseUp",Q),s.controller.addEventListener("mouseCancel",Q),s.controller.addEventListener("mouseOut",R),s.controller.addEventListener("mouseUpOutside",S),s.controller.addEventListener("tap",B),"undefined"!=typeof document.hidden?document.addEventListener("visibilitychange",A):"undefined"!=typeof document.mozHidden?document.addEventListener("mozvisibilitychange",A):"undefined"!=typeof document.msHidden?document.addEventListener("msvisibilitychange",A):"undefined"!=typeof document.webkitHidden&&document.addEventListener("webkitvisibilitychange",A),window.onunload=s.destroy,s.autoLoad!==!1&&s.load()},D=function(){var a;if(!u)for(a=+new Date,h+=a-g,g=a,h>s.maxLoopDuration&&(BLOCKS.warn("Cannot keep up with game loop. Chopping "+Math.ceil((h-s.maxLoopDuration)/60)+" frames."),h=s.maxLoopDuration);h>=16.666666666666;)h-=16.666666666666,s.dispatchEvent("tick"),s.dispatchEvent("preUpdate"),s.debug&&e.update(),y(),s.update(),s.dispatchEvent("postUpdate")},E=function(){var a={camera:s.camera};u||(s.dispatchEvent("preRender",a),s.debug&&e.render(a),s.render(a),s.dispatchEvent("postRender",a))},F=function(){D(),E()},G=function(a){s.keyDown&&s.keyDown(a)},H=function(a){s.keyUp&&s.keyUp(a)},I=function(a){s.debug&&(a.x<100&&a.y<100&&(f=window.setTimeout(function(){e.visible=!e.visible,e.dirty=!0},1e3)),e.onTap(a)),s.tap&&s.tap(a)},J=function(a){s.debug&&window.clearTimeout(f),s.drag&&s.drag(a)},K=function(a){s.debug&&window.clearTimeout(f),s.release&&s.release(a)},L=function(a){s.touchStart&&s.touchStart(a)},M=function(a){s.touchMove&&s.touchMove(a)},N=function(a){s.touchEnd&&s.touchEnd(a)},O=function(a){s.mouseDown&&s.mouseDown(a)},P=function(a){s.mouseMove&&s.mouseMove(a)},Q=function(a){s.mouseUp&&s.mouseUp(a)},R=function(a){s.mouseOut&&s.mouseOut(a)},S=function(a){s.mouseUpOutside&&s.mouseUpOutside(a)},T=function(){p||(s.introScreen&&o||!s.introScreen)&&s.imageLoader.isLoaded()&&(s.speaker.isReady()||0===s.speaker.getNumFiles())&&(p=!0,s.autoStart!==!1&&s.start(),s.loadingScreen&&(s.loadingScreen.destroy(),s.loadingScreen=null),s.dispatchEvent("loaded"))},U=function(){var a,b,d,e,f,g;for(b={width:s.element.offsetWidth,height:s.element.offsetHeight},i&&b.width<i&&(b.width=i),j&&b.height<j&&(b.height=j),l&&b.width>l&&(b.width=l),k&&b.height>k&&(b.height=k),!m&&90===Math.abs(window.orientation)||!n&&90!==Math.abs(window.orientation)?(e=s.height,d=s.width):s.height/s.width>b.height/b.width?s.safeHeight/s.width>b.height/b.width?(e=b.height*s.height/s.safeHeight,d=e*s.width/s.height):(d=b.width,e=d*s.height/s.width):s.height/s.safeWidth>b.height/b.width?(e=b.height,d=e*s.width/s.height):(d=b.width*s.width/s.safeWidth,e=d*s.height/s.width),f=(b.width-d)/2,g=(b.height-e)/2,s.scale=d/s.width,s.camera.x=-Math.min(f,0)/s.scale,s.camera.y=-Math.min(g,0)/s.scale,s.camera.width=(b.width-2*Math.max(f,0))/s.scale,s.camera.height=(b.height-2*Math.max(g,0))/s.scale,c.style.width=b.width-2*Math.max(f,0)+"px",c.style.height=b.height-2*Math.max(g,0)+"px",c.style.padding=Math.max(g,0)+"px "+Math.max(f,0)+"px",s.controller.scaleX=s.width/d,s.controller.scaleY=s.height/e,s.controller.offsetX=-s.camera.x*s.scale,s.controller.offsetY=-s.camera.y*s.scale,a=0;a<s.layers.length;a+=1)s.layers[a].width=s.camera.width,s.layers[a].height=s.camera.height;!p&&s.loadingScreen&&(s.loadingScreen.dirty=!0),s.dispatchEvent("resize")};return a=a||{},s.layers=[],s.width=void 0!==a.width?a.width:1024,s.height=void 0!==a.height?a.height:768,s.safeWidth=a.safeWidth||s.width,s.safeHeight=a.safeHeight||s.height,s.debug=void 0!==a.debug?a.debug:!1,s.maxLoopDuration=void 0!==a.maxLoopDuration?a.maxLoopDuration:500,s.scale=1,s.stage=BLOCKS.container(s),s.camera=BLOCKS.camera({width:s.width,height:s.height}),s.autoLoad=void 0!==a.autoLoad?a.autoLoad:!0,s.autoStart=void 0!==a.autoStart?a.autoStart:!0,s.state="intro",s.element=void 0!==b?b:document.getElementById("BlocksGame"),s.element||(s.element=document.getElementsByClassName("BlocksGame")[0]),s.element||BLOCKS.error("Game does not have a game element"),s.imageLoader=a&&a.imagesPath?BLOCKS.preloader(a.imagesPath):BLOCKS.preloader(),a&&a.loading&&(s.loadingScreen=BLOCKS.loadingScreen(a.loading,s)),a&&a.intro&&(s.introScreen=BLOCKS.introScreen(a.intro,s)),s.speaker=BLOCKS.speaker({path:a&&void 0!==a.audioPath?a.audioPath:"",src:a&&void 0!==a.audioSpriteSrc?a.audioSpriteSrc:""}),s.speaker.addEventListener("update",function(){var a=s.imageLoader.getNumFilesLoaded()+s.speaker.getNumFilesLoaded();s.loadingScreen&&s.loadingScreen.setProgress(a,s.imageLoader.getNumFiles()+s.speaker.getNumFiles())}),s.speaker.addEventListener("ready",function(){T()},!0),Object.defineProperty(s,"paused",{get:function(){return u}}),s.pause=function(){u||(u=!0,s.speaker&&(r=s.speaker.isMuted(),s.speaker.mute(),s.speaker.pause(),s.dispatchEvent("pause")))},s.resize=function(){U()},s.unpause=function(){u&&(u=!1,g=+new Date,s.speaker&&(r||s.speaker.unmute(),s.speaker.unpause(),s.dispatchEvent("unpause")))},s.update=function(){s.stage.update()},s.render=function(a){s.stage.render(a)},s.getLayer=function(a){var b;for(b=0;b<s.layers.length;b+=1)if(s.layers[b].name===a)return s.layers[b]},s.createLayer=function(a,b){return b=b||{},b.name=a,b.parentElement=d,b.width||(b.width=s.camera.width),b.height||(b.height=s.camera.height),BLOCKS.layer(b)},s.destroyLayer=function(a){a.destroy(),a=null},s.addLayer=function(a,b){var c;return s.getLayer(a)?(BLOCKS.warn("Cannot add layer '"+a+"' because it already exists."),void 0):(c=s.createLayer(a,b),s.layers.push(c),c)},s.removeLayer=function(a){var b;for(b=0;b<s.layers.length;b+=1)if(s.layers[b].name===a)return s.destroyLayer(s.layers[b]),s.layers.splice(b,1),!0;BLOCKS.warn("Cannot remove layer '"+a+"' because it cannot be found.")},s.addMotor=function(a){var b,c=arguments[1]||{};return c.type=a,"drag"===c.type?c.controller=s.controller:c.clock=s,b=BLOCKS.motor(c),b&&(b.type=a,c.object&&c.object.motorize(b),b.addEventListener("destroyed",s.removeMotor),v.push(b)),b},s.removeMotor=function(a){var b;for(b=0;b<v.length;b+=1)if(v[b]===a)return v.splice(b,1),!0},s.addTicker=function(a,b,c){var d=(+new Date).toString()+x;return x+=1,x>99999999&&(x=0),w.push({id:d,curTick:0,totalTicks:Math.ceil(60*b/1e3),callback:a,parameters:c}),d},s.removeTicker=function(a){var b,c=[];for(b=0;b<w.length;b+=1)w[b].id===a?w[b]=null:c.push(w[b]);w=c},s.clearTickers=function(){w=[]},s.load=function(){var b;if(s.imageLoader.loadFromTree(a),a.sounds)for(b=0;b<a.sounds.length;b+=1)s.speaker.createSound(a.sounds[b]);s.imageLoader.addEventListener("update",function(){var a=s.imageLoader.getNumFilesLoaded()+s.speaker.getNumFilesLoaded();s.loadingScreen&&s.loadingScreen.setProgress(a,s.imageLoader.getNumFiles()+s.speaker.getNumFiles())}),s.imageLoader.addEventListener("complete",function(){T()}),s.imageLoader.load()},s.stop=function(){t.removeEventListener("tick",F),t.stop()},s.start=function(){g=+new Date,h=0,q||(q=!0,s.prepare&&s.prepare()),t.removeEventListener("tick",F),t.addEventListener("tick",F),t.start()},s.destroy=function(){var a;for(t.destroy(),s.loadingScreen&&s.loadingScreen.destroy(),a=0;a<s.layers;a+=1)s.removeLayer(s.layers[a])},function(){for(var a=0,b=["webkit","moz"],c=0;c<b.length&&!window.requestAnimationFrame;++c)window.requestAnimationFrame=window[b[c]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[b[c]+"CancelAnimationFrame"]||window[b[c]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(b){var c=(new Date).getTime(),d=Math.max(0,16-(c-a)),e=window.setTimeout(function(){b(c+d)},d);return a=c+d,e}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(a){window.clearTimeout(a)})}(),C(),s},BLOCKS.introScreen=function(a,b){"use strict";var c,d,e,f,g=BLOCKS.eventDispatcher(),h=function(){a.bg.image=b.imageLoader.loadNow(a.bg),a.bg.image.onload=j},i=function(){k(),l()},j=function(){f||(e=b.addLayer("intro",{zIndex:1}),c=BLOCKS.slice({layer:e,image:a.bg.image}),d=BLOCKS.clock(),d.addEventListener("tick",i),d.start())},k=function(){c.update()},l=function(){e.dirty&&(c.dirty=!0),c.render(b)};return g.destroy=function(){f=!0,d&&d.destroy(),c&&c.destroy(),e&&b.removeLayer("intro"),g=null},h(),g};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.layer=function(a){"use strict";var b,c,d={},e=a&&a.width||300,f=a&&a.height||150,g=a&&void 0!==a.zIndex?a.zIndex:0;return d.name=a&&a.name,d.x=a&&a.x,d.y=a&&a.y,d.clear=function(){d.webGLEnabled?(d.ctx.colorMask(!0,!0,!0,!0),d.ctx.clearColor(0,0,0,0),d.ctx.clear(d.ctx.COLOR_BUFFER_BIT)):b.width=b.width,d.dirty=!1},d.destroy=function(){c&&c.removeChild(b),b=null,d.ctx=null,c=null,d=null},Object.defineProperty(d,"width",{get:function(){return e},set:function(a){a!==e&&(d.dirty=!0,e=a,b.width=e)}}),Object.defineProperty(d,"height",{get:function(){return f},set:function(a){a!==f&&(d.dirty=!0,f=a,b.height=f)}}),a||(a={}),function(){var h,i,j;if(b=document.createElement("canvas"),b.width=e,b.height=f,b.className="BlocksCanvas",b.style.zIndex=g,d.name&&(b.id="BlocksCanvas_"+d.name),a.parentElement){for(c=a.parentElement,i=c.children,h=0;h<i.length;h+=1)if(i[h].style.zIndex>g){j=!0,c.insertBefore(b,i[h]);break}j||c.appendChild(b)}d.ctx?d.webGLEnabled=!0:(d.webGLEnabled=!1,d.ctx=b.getContext("2d"))}(),d},BLOCKS.loadingScreen=function(a,b){"use strict";var c,d,e,f,g,h,i,j=BLOCKS.eventDispatcher(),k=0,l="Arial,sans",m="24px",n="bold",o="#eee",p=0,q=0,r="loading... ",s=function(){g||(a.animation.layer=e.loading,g=BLOCKS.slice(a.animation),g.x=a.animation.x,g.y=a.animation.y,j.dirty=!0)},t=function(){f||(a.progressBar.layer=e.loading,f=BLOCKS.slice(a.progressBar),f.x=a.progressBar.x,f.y=a.progressBar.y,j.dirty=!0)},u=function(){a.bg.image=b.imageLoader.loadNow(a.bg),a.bg.image.onload=v,a.progressBar.image=b.imageLoader.loadNow(a.progressBar),a.progressBar.image.onload=function(){h=!0,e&&e.loading&&t()},a.animation&&(a.animation.image=b.imageLoader.loadNow(a.animation),a.animation.image.onload=function(){i=!0,e&&e.loading&&s()})},v=function(){e={loadingBg:b.addLayer("loadingBg",{enableWebGL:!1}),loading:b.addLayer("loading")},d=BLOCKS.slice({layer:e.loadingBg,image:a.bg.image}),h&&!f&&t(),a.animation&&i&&!g&&s(),c=BLOCKS.clock(),c.addEventListener("tick",function(){w(),x()}),c.start()},w=function(){d.update(),f&&f.update(),g&&g.update()},x=function(){(j.dirty||d.dirty||g&&g.dirty||f&&f.dirty)&&(e.loading.clear(),d.dirty=!0,f&&(f.cropWidth=f.width*k,f.dirty=!0),g&&(g.dirty=!0),d.render(b),e.loading.ctx.fillStyle=o,e.loading.ctx.font=n+" "+m+" "+l,e.loading.ctx.textAlign="right",e.loading.ctx.fillText(r,p,q),e.loading.ctx.textAlign="left",e.loading.ctx.fillText(Math.round(100*k,10)+"%",p,q),f&&f.render(b),g&&g.render(b)),j.dirty=!1};return j.dirty=!0,j.destroy=function(){c&&(c.destroy(),e&&(b.removeLayer("loadingBg"),b.removeLayer("loading")),d.destroy(),d=null,f&&(f.destroy(),f=null),g&&(g.destroy(),g=null)),j=null},j.setProgress=function(a,b){var c=a/b;k!==c&&(k=c,j.dirty=!0)},a.message&&(a.message.fontFamily&&(l=a.message.fontFamily),a.message.fontSize&&(m=a.message.fontSize.toString().replace("px","")+"px"),a.message.fontWeight&&(n=a.message.fontWeight),a.message.fontColor&&(o=a.message.fontColor),a.message.x&&(p=a.message.x),a.message.y&&(q=a.message.y),a.message.text&&(r=a.message.text)),u(),j};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.tween=function(a){"use strict";var b,c,d,e,f=BLOCKS.eventDispatcher(),g=a.property,h=a.clock,i=a.object,j=a.amount,k=60*(a.duration/1e3),l=a.callback,m=a.easing,n=a.dirtyTolerance||0,o=0,p=o;return f.tick=function(){e||(d+=1,f.dispatchEvent("tick"),c="easeIn"===m?Math.pow(d/k,4)*j:"easeOut"===m?-(Math.pow(d/k-1,4)-1)*j:"easeInOut"===m?1>d/(k/2)?Math.pow(d/(k/2),4)*j/2:-(Math.pow(d/(k/2)-2,4)-2)*j/2:"easeOutElastic"===m?(Math.pow(2,-10*d/k)*Math.sin((d/k-.075)*2*Math.PI/.3)+1)*j:o+b,i[g]+=c-o,d===k?(i.dirty=!0,f.dispatchEvent("complete",f),l&&l(),f&&f.destroy()):(o=c,Math.abs(p-o)>n&&(p=o,i.dirty=!0)))},f.destroy=function(){e||(e=!0,h&&h.removeEventListener("tick",f.tick),f.dispatchEvent("destroyed",f),f=null)},function(){return g?i?k?j?void 0===i[g]?(BLOCKS.error("Tween property does not exist on object: "+g),null):(h&&h.addEventListener("tick",f.tick),b=j/k,d=0,void 0):(0!==j&&BLOCKS.error("Amount is required for tween property: "+g),null):(BLOCKS.error("Duration is required for tween property: "+g),null):(BLOCKS.error("Object is required for tween property: "+g),null):(BLOCKS.error("Tween property parameter required"),null)}(),f},BLOCKS.motor=function(a){"use strict";var b;return"move"===a.type?b=function(a){var b,c,d,e,f,g=BLOCKS.eventDispatcher(),h=!1,i=a.clock,j=a.object,k=a.callback,l=a.speed,m=a.easing,n={x:a.x||0,y:a.y||0},o={x:0,y:0},p=BLOCKS.toolbox.dist(o,n),q=BLOCKS.toolbox.angle(o,n);return g.tick=function(){var a,d;h||(g.dispatchEvent("tick"),a=BLOCKS.toolbox.dist(o,n),b+=1,j.dirty=!0,b>=c?(j.x+=a*Math.cos(q),j.y+=a*Math.sin(q),g.dispatchEvent("complete",g),k&&k(),g&&g.destroy()):("easeIn"===m?(d=Math.pow(b/c,4)*p,e=d*Math.cos(q)-o.x,f=d*Math.sin(q)-o.y):"easeOut"===m?(d=-(Math.pow(b/c-1,4)-1)*p,e=d*Math.cos(q)-o.x,f=d*Math.sin(q)-o.y):"easeInOut"===m&&(d=1>b/(c/2)?Math.pow(b/(c/2),4)*p/2:-(Math.pow(b/(c/2)-2,4)-2)*p/2,e=d*Math.cos(q)-o.x,f=d*Math.sin(q)-o.y),o.x+=e,o.y+=f,j.x+=e,j.y+=f))},g.destroy=function(){h||(h=!0,i&&i.removeEventListener("tick",g.tick),g.dispatchEvent("destroyed",g),g=null)},function(){return p?(i&&i.addEventListener("tick",g.tick),a.duration?(d=a.duration,l=p/(60*(a.duration/1e3))):d=p/l*(1e3/60),e=l*Math.cos(q),f=l*Math.sin(q),b=0,c=p/l,void 0):(g.destroy(),null)}(),g}(a):"drag"===a.type?b=function(a){var b,c=BLOCKS.eventDispatcher(),d=a.object,e=a.controller,f=a.bounds,g=a.horizontalOnly,h=a.verticalOnly,i=!1,j=function(b){return a.bounds&&(b.x<f.x&&(b.x=f.x),b.x>f.x+f.width&&(b.x=f.x+f.width),b.y<f.y&&(b.y=f.y),b.y>f.y+f.height&&(b.y=f.y+f.height)),b},k=function(a){a=j(a),h||(d.x=Math.round(a.x)),g||(d.y=Math.round(a.y)),d.dirty=!0},l=function(a){d.isPointInside(a)?(d.justTapped=!0,d.dirty=!0,b=!0,k(a)):(d.justNotTapped=!0,d.dirty=!0)},m=function(a){d.tapPos=a,e.drag&&b&&(k(a),d.dragging||d.dispatchEvent("onDragStart",d),d.dragging=!0)},n=function(){d.justTapped&&(d.justTapped=!1,d.dirty=!0),d.justNotTapped&&(d.justNotTapped=!1,d.dirty=!0),b&&(d.justReleased=!0,d.dispatchEvent("onDragEnd",d)),d.dragging=!1,b=!1};return c.destroy=function(){i||(i=!0,e.removeEventListener("tap",l),e.removeEventListener("drag",m),e.removeEventListener("release",n),e.removeEventListener("cancel",n),c.dispatchEvent("destroyed",c),c=null)},function(){return e?(e.addEventListener("tap",l),e.addEventListener("drag",m),e.addEventListener("release",n),e.addEventListener("cancel",n),void 0):(BLOCKS.error("A drag motor will not work without a controller"),c.destroy(),!1)}(),c}(a):("rotate"===a.type?(a.angle&&(a.amount=a.angle),a.property="angle"):a.property=a.type,b=BLOCKS.tween(a)),b};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.preloader=function(a){"use strict";var b,c=BLOCKS.eventDispatcher(),d=[],e=function(){b+=1,c.dispatchEvent("update",{loaded:b,total:d.length}),b===d.length&&c.dispatchEvent("complete")},f=function(a,b){var c,d;for(c in a)if(a.hasOwnProperty(c)&&!(a[c]instanceof HTMLElement))if(b.apply(this,[c,a]),a[c]instanceof Object&&!(a[c]instanceof Array))f(a[c],b);else if(a[c]instanceof Array)for(d=0;d<a[c].length;d+=1)f(a[c][d],b)};return c.path=a||"",c.load=function(){var a;for(b=0,a=0;a<d.length;a+=1)d[a].loadStarted||(d[a].loadStarted=!0,d[a].image.addEventListener("load",e),d[a].image.src=c.path+d[a].src)},c.loadFromTree=function(a){f(a,function(a,b){"src"===a&&c.add(b)})},c.add=function(a){var b,c;if(a&&a.src&&(-1!==a.src.toLowerCase().indexOf("jpg")||-1!==a.src.toLowerCase().indexOf("png"))){for(b=0;b<d.length;b+=1)if(d[b].src===a.src)return a.image=d[b].image,d[b];return c={image:new Image,src:a.src,loadStarted:!1},a.image=c.image,void 0!==a.crossOrigin&&(a.image.crossOrigin=a.crossOrigin),d.push(c),c}},c.loadNow=function(a){var b;return b=new Image,b.src=c.path+a.src,b},c.getNumFiles=function(){return d.length},c.getNumFilesLoaded=function(){return b},c.isLoaded=function(){return b>=d.length},c};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.slice=function(a){"use strict";var b,c,d,e,f,g,h,i,j,k,l,m=BLOCKS.view(a),n=!1,o=0,p=0,q=0,r=function(){b&&(c=b.image.width/m.numberOfFrames,d=b.image.height,m.width=b.image.width/m.numberOfFrames,m.height=b.image.height)};return m.loop=a&&a.loop,m.frameDelay=a&&void 0!==a.frameDelay?a.frameDelay:4,m.numberOfFrames=a&&a.numberOfFrames||1,m.autoPlay=a&&void 0!==a.autoPlay?a.autoPlay:!0,m.resetOnComplete=a&&void 0!==a.resetOnComplete?a.resetOnComplete:!0,m.update=function(){e||b&&m.numberOfFrames>1&&(o+=1,q>=m.numberOfFrames-1?o>=m.frameDelay&&(o=0,p+=1,m.loop===!0||"number"==typeof m.loop&&p<m.loop?(q=0,m.dirty=!0):(m.resetOnComplete&&(q=0,m.dirty=!0),e=!0,function(){var a;m.callback&&(a=m.callback,m.callback=null),m.dispatchEvent("complete"),a&&a()}())):o>=m.frameDelay&&(q+=1,o=0,m.dirty=!0))},m.pause=function(){e=!0},m.unpause=function(){e=!1},m.reset=function(){m.callback=null,(0!==o||0!==q||0!==p)&&(m.dirty=!0),o=0,q=0,p=0},m.stop=function(){e=!0,m.reset()},m.play=function(a){q>=m.numberOfFrames-1&&m.stop(),e=!1,m.callback=a},m.render=function(a){var e,g,h,i,j,k,l;if(m.alpha<0?m.alpha=0:m.alpha>1&&(m.alpha=1),m.dirty&&m.visible&&0!==m.alpha&&0!==m.cropWidth&&0!==m.cropHeight&&(j={x:a&&a.camera&&a.camera.x||0,y:a&&a.camera&&a.camera.y||0},k=m.worldX,l=m.worldY,b&&m.layer&&(i=m.layer.ctx,m.layer.webGLEnabled||((m.angle||1!==m.alpha||m.colorize||m.mirrorX||m.mirrorY)&&(i.save(),h=!0),i.globalAlpha=m.alpha,m.angle&&(i.translate(k,l),i.rotate(m.angle*Math.PI/180),i.translate(-k,-l)),(m.mirrorX||m.mirrorY)&&(i.translate(k,l),m.mirrorX&&m.mirrorY?i.scale(-1,-1):m.mirrorX?i.scale(-1,1):i.scale(1,-1),i.translate(-k,-l)),m.colorize&&(f||(f=document.createElement("canvas").getContext("2d"),f.canvas.width=i.canvas.width,f.canvas.height=i.canvas.height),i=f,i.globalCompositeOperation="copy"),m.numberOfFrames>1?i.drawImage(b.image,q*m.width/m.scale+m.frameOffsetX,m.frameOffsetY,m.cropWidth||c,m.cropHeight||d,k+m.offsetX-j.x,l+m.offsetY-j.y,m.cropWidth||m.width,m.cropHeight||m.height):i.drawImage(b.image,m.frameOffsetX,m.frameOffsetY,m.cropWidth||c,m.cropHeight||d,k+m.offsetX-j.x,l+m.offsetY-j.y,m.cropWidth||m.width,m.cropHeight||m.height),m.colorize&&(i.fillStyle=m.colorize,i.globalCompositeOperation="source-in",i.fillRect(k,l,m.width,m.height),i=m.layer.ctx,i.drawImage(f.canvas,0,0)),h&&i.restore()),n&&i))){for(g=m.getBounds(),g.length||(g=[g]),i.lineWidth=4,e=0;e<g.length;e+=1)m.dragging?(i.beginPath(),i.fillStyle="rgba(10, 255, 50, 0.4)",i.fillRect(g[e].x-j.x,g[e].y-j.y,g[e].width,g[e].height),i.closePath()):m.justTapped?(i.beginPath(),i.fillStyle="rgba(255, 10, 50, 0.4)",i.fillRect(g[e].x-j.x,g[e].y-j.y,g[e].width,g[e].height),i.closePath()):m.justNotTapped?(i.beginPath(),i.fillStyle="rgba(255, 10, 255, 0.4)",i.fillRect(g[e].x-j.x,g[e].y-j.y,g[e].width,g[e].height),i.closePath()):m.justReleased&&(i.beginPath(),i.fillStyle="rgba(125, 10, 255, 0.4)",i.fillRect(g[e].x-j.x,g[e].y-j.y,g[e].width,g[e].height),i.closePath(),m.justReleased=!1),i.beginPath(),i.strokeStyle="rgba(96, 255, 0, 0.5)",i.strokeRect(g[e].x-j.x,g[e].y-j.y,g[e].width,g[e].height),i.closePath();i.beginPath(),i.arc(k-j.x,l-j.y,7,0,2*Math.PI,!1),i.fillStyle="rgba(96, 255, 0, 0.5)",i.fill()}m.dirty=!1},m.gotoLastFrame=function(){q!==m.numberOfFrames-1&&(q=m.numberOfFrames-1,m.dirty=!0)},m.gotoFrame=function(a){var b=Math.floor(m.frameDelay*(a-Math.floor(a))/100);a=Math.floor(a),(q!==a||o!==b)&&(q=a,o=b,m.dirty=!0)},m.destroy=function(){m&&m.dispatchEvent("destroyed",m),b=null,a=null,m=null},a=a||{},g=a.cropWidth,Object.defineProperty(m,"cropWidth",{get:function(){return g},set:function(a){g!==a&&(m.dirty=!0,g=a)}}),h=a.cropHeight,Object.defineProperty(m,"cropHeight",{get:function(){return h},set:function(a){h!==a&&(m.dirty=!0,h=a)}}),i=a.frameOffsetX||0,Object.defineProperty(m,"frameOffsetX",{get:function(){return i},set:function(a){i!==a&&(m.dirty=!0,i=a)}}),j=a.frameOffsetY||0,Object.defineProperty(m,"frameOffsetY",{get:function(){return j},set:function(a){j!==a&&(m.dirty=!0,j=a)}}),k=a.mirrorX,Object.defineProperty(m,"mirrorX",{get:function(){return k},set:function(a){k!==a&&(m.dirty=!0,k=a)}}),l=a.mirrorY,Object.defineProperty(m,"mirrorY",{get:function(){return l},set:function(a){l!==a&&(m.dirty=!0,l=a)}}),function(){var c=a.image,d=a.imageSrc||a.image&&a.src,f=c?!0:!1;a=a||{},m.autoPlay||(e=!0),c||d?(b={image:c,imageSrc:d,loaded:f},b.loaded?r():(b.image||(b.image=new Image),b.image.addEventListener("load",r),b.image.src=b.imageSrc)):r()}(),m};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.audio={},BLOCKS.audio.soundInstance=function(a){"use strict";var b={};return b.stop=a.stopSoundInstance(b),b.play=a.playSoundInstance(b),b.getSoundGain=a.getSoundInstanceGain(),b
  },BLOCKS.audio.audioElementPlayer=function(a){"use strict";var b,c,d,e,f,g,h,i,j=BLOCKS.eventDispatcher(),k=!1,l=!1,m={},n=!1,o=!1,p=function(){l||(l=!0,j.debug&&BLOCKS.debug("audio ready"),j.dispatchEvent("ready"))},q=function(){o||(o=!0,j.createSound({name:"BlocksTestSound",start:0,end:.5}),w("BlocksTestSound",p),window.setTimeout(function(){l||(w("BlocksTestSound",p),window.setTimeout(function(){l||p()},1e4))},1e4))},r=function(){q()},s=function(){j.debug&&BLOCKS.debug("load audio sprite: "+b),f&&window.clearInterval(f),f=window.setInterval(function(){var a,b;e.buffered.length&&(a=e.buffered.end(e.buffered.length-1),b=100*(a/e.duration),isNaN(b)||d===b||(d=b,j.dispatchEvent("loadUpdate"),j.debug&&BLOCKS.debug("loadUpdate: "+Math.round(b)+"%"),i||(i=!0,e.pause())),window.Math.abs(a-e.duration)<.1&&(window.clearInterval(f),q(),j.dispatchEvent("loadComplete"),j.debug&&BLOCKS.debug("loadComplete")))},100),e.play()},t=function(){window.clearInterval(g),g=null,e.pause()},u=function(){t(),c=null},v=function(){var a;c?e.currentTime>=c.end&&(c.loop===!0?e.currentTime=c.start:(t(),j.dispatchEvent("played"),a=c,c=null,a.callback&&a.callback(a.name))):window.clearInterval(g)},w=function(a,b){return j.debug&&BLOCKS.debug("Play sound: "+a+" ("+m[a].start+" - "+m[a].end+")"),m[a].start>=0&&m[a].end>0?(h>=0&&(e.volume=h,h=null),c={name:m[a].name,start:m[a].start,end:m[a].end,loop:m[a].loop,sound:m[a].sound,callback:b},e.currentTime=m[a].start,e.play(),g&&window.clearInterval(g),g=window.setInterval(v,100),!0):(BLOCKS.warn("Sound parameters not specified."),!1)},x=function(){e.pause()},y=function(){c&&e.play()},z=function(){e.volume=0},A=function(){e.volume=1};return j.setSoundGain=function(a,b){c&&c.name===a&&(h=e.volume,e.volume=b)},j.play=function(a,b){return m[a]?w(a,b):(BLOCKS.warn("Cannot play sound '"+a+"' because it was not defined"),void 0)},j.pause=function(){x()},j.unpause=function(){y()},j.stop=function(){u()},j.mute=function(){n||z(),n=!0},j.unmute=function(){n&&A(),n=!1},j.isMuted=function(){return n},j.isReady=function(){return l},j.load=function(){k||(k=!0,s())},j.createSound=function(a){m[a.name]={name:a.name,start:a.start,end:a.end,loop:a.loop}},j.getActiveSounds=function(){return[c]},j.getNumFiles=function(){return 1},j.getNumFilesLoaded=function(){return l?1:0},function(){a&&a.src?(b=a.path?a.path:"",b+=a.src,e=window.document.createElement("audio"),e.addEventListener("canplaythrough",r),e.canPlayType("audio/mpeg")?b+=".mp3":e.canPlayType("audio/ogg")&&(b+=".ogg"),e.src=b):BLOCKS.error("sprite filename not specified")}(),j},BLOCKS.audio.webAudioPlayer=function(a){"use strict";var b,c,d,e,f=BLOCKS.eventDispatcher(),g=!1,h=!1,i=!1,j=a&&a.path||"",k={},l={},m=[],n={},o=a.maxLoadTime||6e4,p=0,q=5,r=function(a){return n[a]||(n[a]={name:a,gain:d.createGain?d.createGain():d.createGainNode()},n[a].gain.connect(c)),n[a]},s=function(){var a,b;a=f.getNumFilesLoaded(),b=f.getNumFiles(),f.debug&&BLOCKS.debug("load: "+a+" of "+b),f.dispatchEvent("update",a,b),a===b&&(h||(h=!0,window.clearTimeout(e),f.debug&&BLOCKS.debug("audio ready"),f.dispatchEvent("ready")))},t=function(a){a.request=new window.XMLHttpRequest,"withCredentials"in a.request||(a.request=new window.XDomainRequest),a.request.open("get",j+a.src+b,!0),a.request.responseType="arraybuffer",a.request.onload=function(){d.decodeAudioData(a.request.response,function(b){a.buffer=b,a.loaded=!0,s(a),a.request=null},function(){BLOCKS.debug&&BLOCKS.debug("Error decoding buffer: "+j+a.src+b),a.request=null})},a.request.send()},u=function(){var a;g=!0,a=d.createOscillator(),a.start?a.start(0,0,1):a.noteGrainOn&&a.noteGrainOn(0,0,1)},v=function(a){var b,c;for(b=0;b<m.length;b+=1)if(m[b]===a){m[b]=null,c=b;break}m.splice(c,1)},w=function(a){var b,c;f.debug&&BLOCKS.debug("Sound '"+a.sound.name+"' Complete"),a.callback&&(b=a.callback,c=a.name),v(a),b&&b(c)},x=function(a){window.clearTimeout(a.timeout),a.source.stop?a.source.stop(0):a.source.noteGrainOff?a.source.noteGrainOff(0):a.source.noteOff(0),v(a)},y=function(a){return a.gain.gain.value},z=function(a,b,e){a.gain===a.track.gain&&(a.source.disconnect(0),a.gain=d.createGain?d.createGain():d.createGainNode(),a.gain.connect(c),a.source.connect(a.gain)),f.debug&&BLOCKS.debug("speaker.setSoundGain of sound '"+a.name+"' to '"+b+"'"),e?(a.gain.gain.linearRampToValueAtTime(a.gain.gain.value,d.currentTime),a.gain.gain.linearRampToValueAtTime(b,d.currentTime+e)):a.gain.gain.value=b},A=function(a){window.clearTimeout(a.timeout),a.currentTime=(+new Date-a.startTime)/1e3,a.source.stop?a.source.stop(0):a.source.noteGrainOff?a.source.noteGrainOff(0):a.source.noteOff(0)},B=function(a){var b;b=C(a.name,a.callback,a.track.name,a.currentTime),1!==a.gain.gain.value&&z(b,a.gain.gain.value),v(a)},C=function(a,c,e,g,h){var i={};return k[a].file.loaded?(m.push(i),i.sound=k[a],i.name=a,i.currentTime=g?g:0,i.startTime=+new Date-1e3*i.currentTime,h?i.delay=d.currentTime+h:(h=0,i.delay=0),e?(n[e]||r(e),i.track=n[e]):i.track=n["default"],i.source=d.createBufferSource(),i.source.buffer=k[a].file.buffer,i.source.loop=k[a].loop,i.gain=i.track.gain,i.source.connect(i.gain),k[a].loop||(i.timeout=window.setTimeout(w,1e3*(h+i.source.buffer.duration-i.currentTime),i),i.callback=c),f.debug&&(i.currentTime?BLOCKS.debug("Play sound: "+a+" ("+i.currentTime+" - "+k[a].end+"), src: "+k[a].file.src+b):BLOCKS.debug("Play sound: "+a+" ("+k[a].start+" - "+k[a].end+"), src: "+k[a].file.src+b)),i.source.start?i.currentTime?i.source.start(i.delay,i.currentTime,i.source.buffer.duration-i.currentTime):i.source.start(i.delay):i.source.noteGrainOn&&i.source.noteGrainOn(i.delay,i.currentTime,i.source.buffer.duration-i.currentTime),i):(BLOCKS.warn("Tried to play sound: "+a+", but it is not loaded yet"),void 0)},D=function(){e=window.setTimeout(function(){var a;for(a in l)l.hasOwnProperty(a)&&(l[a].loaded||(l[a].request?(BLOCKS.warn("Sound file load has timed out. Aborting request and trying again: "+l[a].src),l[a].request.abort()):BLOCKS.warn("Sound file load has timed out. Sending additional request: "+l[a].src),t(l[a])));p+=1,q>p&&D()},o)};return f.play=function(a,b,c,d,e){return k[a]?C(a,b,c,d,e):(BLOCKS.warn("Cannot play sound '"+a+"' because it was not defined"),void 0)},f.getSoundDuration=function(a){return k[a].file.buffer.duration},f.getSoundInstanceGain=function(a){return y(a)},f.getSoundGain=function(a){var b,c=m.slice(0);for(b=0;b<c.length;b+=1)if(c[b].name===a)return y(c[b])},f.setSoundInstanceGain=function(a,b,c){z(a,b,c)},f.setSoundGain=function(a,b,c){var d,e=m.slice(0);for(d=0;d<e.length;d+=1)e[d].name===a&&z(e[d],b,c)},f.stopSound=function(a){var b,c=m.slice(0);for(b=0;b<c.length;b+=1)c[b].name===a&&x(c[b])},f.pauseSound=function(a){var b,c=m.slice(0);for(b=0;b<c.length;b+=1)c[b].name===a&&A(c[b])},f.unpauseSound=function(a){var b,c=m.slice(0);for(b=0;b<c.length;b+=1)c[b].name===a&&B(c[b])},f.stopTrack=function(a){var b,c=m.slice(0);for(b=0;b<c.length;b+=1)c[b].track.name===a&&x(c[b])},f.pauseTrack=function(a){var b,c=m.slice(0);for(b=0;b<c.length;b+=1)c[b].track.name===a&&A(c[b])},f.unpauseTrack=function(a){var b,c=m.slice(0);for(b=0;b<c.length;b+=1)c[b].track.name===a&&B(c[b])},f.stop=function(){var a,b=m.slice(0);for(a=0;a<b.length;a+=1)x(b[a])},f.pause=function(){var a,b=m.slice(0);for(a=0;a<b.length;a+=1)A(b[a])},f.unpause=function(){var a,b=m.slice(0);for(a=0;a<b.length;a+=1)B(b[a])},f.mute=function(){i||(i=!0,c.gain.value=0)},f.unmute=function(){i&&(i=!1,c.gain.value=1)},f.isMuted=function(){return i},f.load=function(){g||(g=!0,D(),u())},f.isReady=function(){return h},f.createSound=function(a){k[a.name]={name:a.name,start:a.start,end:a.end,loop:a.loop},l[a.src]||(l[a.src]={src:a.src},t(l[a.src])),k[a.name].file=l[a.src]},f.getActiveSoundInstances=function(){return m},f.getNumFiles=function(){var a,b;b=0;for(a in l)l.hasOwnProperty(a)&&(b+=1);return b},f.getNumFilesLoaded=function(){var a,b;b=0;for(a in l)l.hasOwnProperty(a)&&l[a].loaded&&(b+=1);return b},f.getCurrentTime=function(){return d.currentTime},f.multipleTracksSupported=!0,function(){var a,e=document.createElement("audio");a=navigator.userAgent.toLowerCase().indexOf("firefox")>-1,b=e.canPlayType("audio/mpeg;").replace(/no/,"")&&e.canPlayType&&!a?".mp3":".ogg","undefined"!=typeof AudioContext?d=new window.AudioContext:"undefined"!=typeof webkitAudioContext&&(d=new window.webkitAudioContext),d?(c=d.createGain?d.createGain():d.createGainNode(),c.connect(d.destination)):BLOCKS.error("Cannot create audio context."),r("default")}(),f},BLOCKS.speaker=function(a){"use strict";var b;return function(){a||(a={}),b="undefined"==typeof AudioContext&&"undefined"==typeof webkitAudioContext||a.webAudioEnabled===!1?BLOCKS.audio.audioElementPlayer(a):BLOCKS.audio.webAudioPlayer(a)}(),b.debug=!1,b};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.stack=function(a){"use strict";var b,c,d,e,f,g=BLOCKS.eventDispatcher(),h=[],i=[],j=function(a){var b;for(a.removeEventListener("destroyed",j),b=0;b<i.length;b+=1){i.splice(b,1);break}},k=function(a){var b;for(b=0;b<h.length;b+=1)h[b].dirty=a};return a=a||{},g.addView=function(a){a.stack=g,h.push(a)},g.getView=function(a){var b;for(b=0;b<h.length;b+=1)if(h[b].name===a)return h[b]},g.removeView=function(a){var b;for(b=0;b<h.length;b+=1)if(h[b]===a){h[b].splice(b,1);break}},g.show=function(){var a;if(!f)for(f=!0,a=0;a<h.length;a+=1)h[a].show()},g.hide=function(){var a;if(f)for(f=!1,b=!0,a=0;a<h.length;a+=1)h[a].hide()},g.isPointInside=function(a){var b;for(b=0;b<h.length;b+=1)if(h[b].visible&&h[b].isPointInside(a))return!0;return!1},g.motorize=function(a){a.addEventListener("destroyed",j),i.push(a)},g.removeMotors=function(a){var b,c=[];for(b=0;b<i.length;b+=1)a?i[b].type===a?i[b].destroy():c.push(i[b]):i[b].destroy();i=c},g.destroy=function(){var a;for(a=0;a<h.length;a+=1)h[a].destroy();h=[],g=null},Object.defineProperty(g,"dirty",{get:function(){return b},set:function(a){k(a)}}),Object.defineProperty(g,"alpha",{get:function(){return void 0!==c?c:1},set:function(a){var b;for(c=a,b=0;b<h.length;b+=1)h[b].alpha=a}}),Object.defineProperty(g,"width",{get:function(){var a,b=0;for(a=0;a<h.length;a+=1)h[a].visible&&h[a].width>b&&(b=h[a].width);return b}}),Object.defineProperty(g,"height",{get:function(){var a,b=0;for(a=0;a<h.length;a+=1)h[a].visible&&h[a].height>b&&(b=h[a].height);return b}}),d=a.x||0,Object.defineProperty(g,"x",{get:function(){return d},set:function(a){d!==a&&(d=a,k(!0))}}),e=a.y||0,Object.defineProperty(g,"y",{get:function(){return e},set:function(a){e!==a&&(e=a,k(!0))}}),f=a.visible||!0,Object.defineProperty(g,"visible",{get:function(){return f},set:function(a){a?g.show():g.hide()}}),g};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.storage=function(){"use strict";var a=BLOCKS.eventDispatcher();return a.get=function(a){return window.localStorage?JSON.parse(window.localStorage.getItem(a)):null},a.save=function(a,b){window.localStorage.setItem(a,JSON.stringify(b))},a.destroy=function(){a=null},a};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.textField=function(a){"use strict";var b=BLOCKS.view(a),c=!1,d=[],e=function(a){var b;for(a.removeEventListener("destroyed",e),b=0;b<d.length;b+=1){d.splice(b,1);break}};return b.render=function(){var a,d,e,f,g,h,i,j;if(b.dirty&&b.visible&&b.layer){for(j=b.layer.ctx,(b.angle||1!==b.alpha)&&(j.save(),d=!0),1!==b.alpha&&(j.globalAlpha=b.alpha),b.angle&&(j.translate(b.x,b.y),j.rotate(b.angle*Math.PI/180),j.translate(-b.x,-b.y)),j.fillStyle=b.fontColor,j.font=b.fontWeight+" "+(Number(b.fontSize.toString().replace("px",""))*b.scale+"px")+" "+b.fontFamily,j.textAlign=b.textAlign,e=(b.prependText+b.text).split(" "),f="",h=b.x,i=b.y,j.textBaseline=b.textBaseline,a=0;a<e.length;a+=1)g=f+e[a]+" ",a&&b.width&&j.measureText(g).width>b.width?(j.fillText(f,h,i),f=e[a]+" ",i+=20):f=g;j.fillText(f,h,i),d&&j.restore(),c&&(j.beginPath(),j.strokeStyle="rgba(255, 80, 0, 0.5)",j.strokeRect(b.x,b.y,b.width,b.height),j.closePath())}b.dirty=!1},b.destroy=function(){b.stopMotors(),a=null,b=null},b.motorize=function(a){a.addEventListener("destroyed",e),d.push(a)},b.stopMotors=function(a){var b,c=d.slice(0);for(b=0;b<c.length;b+=1)a?c[b].type===a&&c[b].destroy():c[b].destroy()},function(){a=a||{},b.fontColor=a.fontColor||"#000000",b.fontFamily=a.fontFamily||"Arial,sans",b.fontSize=a.fontSize&&Number(a.fontSize.toString().replace("px",""))||24,b.fontWeight=a.fontWeight||"bold",b.textAlign=a.textAlign||"center",b.prependText=a.prependText||"",b.textBaseline=a.textBaseline||"top",b.text=a.text||""}(),b};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.toolbox={},BLOCKS.toolbox.angle=function(a,b){"use strict";var c,d=b.x-a.x,e=b.y-a.y;return 0===d?c=e>0?Math.PI/2:-Math.PI/2:(c=Math.atan(e/d),e>0?0>d&&(c=Math.PI+c):c=0>d?Math.PI+c:2*Math.PI+c),c},BLOCKS.toolbox.randomizeArr=function(a){var b,c,d;for(b=a.length;b;c=parseInt(Math.random()*b,10),d=a[--b],a[b]=a[c],a[c]=d);},BLOCKS.toolbox.isPointInsideRect=function(a,b){return a.x>b.x&&a.x<b.x+b.width&&a.y>b.y&&a.y<b.y+b.height},BLOCKS.toolbox.isRectInsideRect=function(a,b){return a.x+a.width>b.x&&a.x<b.x+b.width&&a.y+a.height>b.y&&a.y<b.y+b.height},BLOCKS.toolbox.dist=function(a,b){"use strict";var c=a.x-b.x,d=a.y-b.y;return Math.sqrt(c*c+d*d)},BLOCKS.toolbox.vector=function(a,b){var c={x:a,y:b};return c.scale=function(a){return c.x*=a,c.y*=a,c},c.normalize=function(){return c.scale(1/c.magnitude())},c.magnitude=function(){return Math.sqrt(c.x*c.x+c.y*c.y)},c},BLOCKS.toolbox.sum=function(a,b){return{x:a.x+b.x,y:a.y+b.y}},BLOCKS.toolbox.diff=function(a,b){return{x:a.x-b.x,y:a.y-b.y}},BLOCKS.toolbox.dot=function(a,b){return a.x*b.x+a.y*b.y};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.log=function(a){window.console&&window.console.log&&window.console.log(a)},BLOCKS.warn=function(a){window.console&&(window.console.warn?window.console.warn(a):window.console.log&&window.console.log(a))},BLOCKS.debug=function(a){window.console&&(window.console.debug?window.console.debug(a):window.console.log&&window.console.log(a))},BLOCKS.error=function(a){window.console&&(window.console.error?window.console.error(a):window.console.log&&window.console.log(a))},BLOCKS.dir=function(a){window.console&&(window.console.dir?window.console.dir(a):window.console.log&&window.console.log(a))};var BLOCKS;void 0===BLOCKS&&(BLOCKS={}),BLOCKS.view=function(a){"use strict";var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=BLOCKS.eventDispatcher(),r=[],s=function(a){var b;for(a.removeEventListener("destroyed",s),b=0;b<r.length;b+=1){r[b]===a&&r.splice(b,1);break}};return q.update=function(){},q.render=function(){q.dirty=!1},q.show=function(){q.visible||(q.dirty=!0),q.visible=!0},q.hide=function(){q.visible&&(q.dirty=!0),q.visible=!1},q.motorize=function(a){a.addEventListener("destroyed",s),r.push(a)},q.removeMotors=function(a){var b,c=[];for(b=0;b<r.length;b+=1)a?r[b].type===a?r[b].destroy():c.push(r[b]):r[b].destroy();r=c},q.isPointInside=function(a){var b,c=q.getBounds(),d=!1;if(!a)return BLOCKS.warn("view.isPointInside point is falsy: "+a),void 0;for(c.length||(c=[c]),b=0;b<c.length;b+=1)if(a.x>=c[b].x&&a.x<=c[b].x+c[b].width&&a.y>=c[b].y&&a.y<=c[b].y+c[b].height){d=!0;break}return d},q.getBounds=function(){var a,b,c,d,e,f,g,h;if(e=q.worldX,f=q.worldY,g=void 0!==q.cropWidth?q.cropWidth:q.width,h=void 0!==q.cropHeight?q.cropHeight:q.height,q.hotspots||q.minHotspot){if(b=[],q.hotspots)for(a=0;a<q.hotspots.length;a+=1)b.push({x:e+q.offsetX+q.hotspots[a].x,y:f+q.offsetY+q.hotspots[a].y,width:q.hotspots[a].width,height:q.hotspots[a].height});q.minHotspot&&(c=g<q.minHotspot?q.minHotspot-g:0,d=h<q.minHotspot?q.minHotspot-h:0,b.push({x:e+q.offsetX-c/2,y:f+q.offsetY-d/2,width:g+c,height:h+d})),1===b.length&&(b=b[0])}else b={x:e+q.offsetX,y:f+q.offsetY,width:g,height:h};return b},q.getBoundingBox=function(){return{x:q.worldX+q.offsetX,y:q.worldY+q.offsetY,width:void 0!==q.cropWidth?q.cropWidth:q.width,height:void 0!==q.cropHeight?q.cropHeight:q.height}},q.isRectInside=function(a){var b,c,d;if(!a)return BLOCKS.warn("view.isRectangleInside rect is falsy: "+a),!1;for(d=q.getBounds(),d.length||(d=[d]),b=0;b<d.length;b+=1)if(a.x+a.width>d[b].x&&a.x<d[b].x+d[b].width&&a.y+a.height>d[b].y&&a.y<d[b].y+d[b].height){c=!0;break}return c},q.destroy=function(){q&&(q.removeMotors(),q.dispatchEvent("destroyed",q),q=null)},function(){a=a||{},q.name=a.name,q.dirty=!0,o=a.stack,Object.defineProperty(q,"stack",{get:function(){return o},set:function(a){o!==a&&(q.dirty=!0,o=a)}}),Object.defineProperty(q,"worldX",{get:function(){return q.stack?q.stack.x+q.x:q.x},set:function(a){q.x!==a&&(q.dirty=!0,q.x=q.stack?a-q.stack.x:a)}}),Object.defineProperty(q,"worldY",{get:function(){return q.stack?q.stack.y+q.y:q.y},set:function(a){q.y!==a&&(q.dirty=!0,q.y=q.stack?a-q.stack.y:a)}}),i=void 0!==a.scale?a.scale:1,Object.defineProperty(q,"scale",{get:function(){return i},set:function(a){i!==a&&(q.dirty=!0,i=a)}}),d=a.width||0,Object.defineProperty(q,"width",{get:function(){return d*q.scale},set:function(a){(d!==q.scale?a/q.scale:a)&&(q.dirty=!0,d=q.scale?a/q.scale:a)}}),e=a.height||0,Object.defineProperty(q,"height",{get:function(){return e*q.scale},set:function(a){(e!==q.scale?a/q.scale:a)&&(q.dirty=!0,e=q.scale?a/q.scale:a)}}),f=a.offsetX||0,Object.defineProperty(q,"offsetX",{get:function(){return q.centerRegistrationPoint?-q.width/2:f},set:function(a){f!==a&&(q.dirty=!0,f=a)}}),g=a.offsetY||0,Object.defineProperty(q,"offsetY",{get:function(){return q.centerRegistrationPoint?-q.height/2:g},set:function(a){g!==a&&(q.dirty=!0,g=a)}}),h=a.angle||0,Object.defineProperty(q,"angle",{get:function(){return h},set:function(a){a%=360,0>a&&(a=360+a),h!==a&&(q.dirty=!0,h=a)}}),b=a.x||0,Object.defineProperty(q,"x",{get:function(){return b},set:function(a){b!==a&&(q.dirty=!0,b=a)}}),c=a.y||0,Object.defineProperty(q,"y",{get:function(){return c},set:function(a){c!==a&&(q.dirty=!0,c=a)}}),j=void 0!==a.alpha?a.alpha:1,Object.defineProperty(q,"alpha",{get:function(){return j},set:function(a){j!==a&&(1e-4>j?j=0:j>.9999&&(j=1),q.dirty=!0,j=a)}}),k=void 0!==a.visible?a.visible:!0,Object.defineProperty(q,"visible",{get:function(){return k},set:function(a){k!==a&&(q.dirty=!0,k=a)}}),l=a.layer,Object.defineProperty(q,"layer",{get:function(){return l},set:function(a){l!==a&&(q.dirty=!0,l=a)}}),m=a.hotspots,Object.defineProperty(q,"hotspots",{get:function(){return m},set:function(a){m!==a&&(q.dirty=!0,m=a)}}),n=a.minHotspot,Object.defineProperty(q,"minHotspot",{get:function(){return n},set:function(a){n!==a&&(q.dirty=!0,n=a)}}),p=a.centerRegistrationPoint||!1,Object.defineProperty(q,"centerRegistrationPoint",{get:function(){return p},set:function(a){p!==a&&(q.dirty=!0,p=a)}})}(),q},BLOCKS.key=function(a){"use strict";var b=BLOCKS.eventDispatcher();return b.name=a.name,b.keyCode=a.keyCode,b.layer=a.layer,b.x=a.x||0,b.y=a.y||0,b.width=a.width||80,b.height=a.height||80,b.scale=a.scale||1,b.visible=a.visible||!1,b.alpha=a.alpha||1,b.color=a.color||"#333",b.textColor=a.textColor||"#eee",b.dirty=!0,b.update=function(){},b.render=function(){b.dirty&&b.visible&&(b.layer.ctx.save(),b.layer.ctx.globalAlpha=b.alpha,b.layer.ctx.fillStyle=b.color,b.layer.ctx.fillRect(b.x,b.y,b.width,b.height),b.layer.ctx.fillStyle=b.textColor,b.layer.ctx.font="bold 24px sans-serif",b.layer.ctx.textAlign="center",b.layer.ctx.fillText(b.name,b.x+b.width/2,b.y+b.height/2+7),b.layer.ctx.restore())},b.destroy=function(){b=null},b},BLOCKS.virtualKeyboard=function(a,b){"use strict";var c=BLOCKS.eventDispatcher(),d=b.layer,e=[[{name:"1",keyCode:49},{name:"2",keyCode:50},{name:"3",keyCode:51},{name:"4",keyCode:52},{name:"5",keyCode:53},{name:"6",keyCode:54},{name:"7",keyCode:55},{name:"8",keyCode:56},{name:"9",keyCode:57},{name:"0",keyCode:48}]],f=[],g=function(){var a,g,h,i=20,j=20;if(b.customKeys)for(a=0;a<b.customKeys.length;a+=1)e.push(b.customKeys[a]);for(a=0;a<e.length;a+=1)for(g=0;g<e[a].length;g+=1)e[a][g].layer=d,h=BLOCKS.key(e[a][g]),h.width=h.width*h.scale,h.scale<1&&(h.width+=(h.scale-1)*j*g),h.x=c.x+i+h.width*g,g<=e[a].length-1&&(h.x+=j*g),h.y=c.y+i+h.height*a,a<=e.length-1&&(h.y+=j*a),f.push(h)};return c.x=b.x||0,c.y=b.y||0,c.width=b.width||640,c.height=b.height||480,c.dirty=!1,c.alpha=.8,c.visible=!1,c.update=function(){var a;for(a=0;a<f.length;a+=1)f[a].update()},c.render=function(){var a;if(c.dirty){for(d.clear(),a=0;a<f.length;a+=1)f[a].visible=c.visible,f[a].dirty=!0;c.visible&&(d.ctx.save(),d.ctx.globalAlpha=c.alpha,d.ctx.fillStyle="white",d.ctx.fillRect(c.x,c.y,c.width,c.height),d.ctx.restore()),c.dirty=!1}for(a=0;a<f.length;a+=1)f[a].render()},c.destroy=function(){var a;for(a=0;a<f.length;a+=1)f[a].destroy()},c.onTap=function(b){var d;if(c.visible)for(d=0;d<f.length;d+=1)if(BLOCKS.toolbox.isPointInsideRect(b,f[d])){a.simulateKeyDownEvent(f[d].keyCode);break}c.visible=!1,c.dirty=!0},g(),c};