forked from craftyjs/Crafty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
crafty-min.js
executable file
·8 lines (8 loc) · 46 KB
/
crafty-min.js
1
2
3
4
5
6
7
8
/*
* Crafty v0.3.1
* http://craftyjs.com
*
* Copyright 2010, Louis Stowasser
* Dual licensed under the MIT or GPL licenses.
*/
(function(j,d){var n=function(s){return new n.fn.init(s);},i=1,o=50,b=1,g={},h={},c={},q=[],e,f,p=Array.prototype.slice,m=/\s*,\s*/,r=/\s+/;n.fn=n.prototype={init:function(w){if(typeof w==="string"){var u=0,A,B,z=false,y=false,C;if(w==="*"){for(A in h){this[+A]=h[A];u++;}this.length=u;return this;}if(w.indexOf(",")!==-1){y=true;C=m;}else{if(w.indexOf(" ")!==-1){z=true;C=r;}}for(A in h){if(!h.hasOwnProperty(A)){continue;}B=h[A];if(z||y){var s=w.split(C),x=0,v=s.length,t=0;for(;x<v;x++){if(B.__c[s[x]]){t++;}}if(z&&t===v||y&&t>0){this[u++]=+A;}}else{if(B.__c[w]){this[u++]=+A;}}}if(u>0&&!z&&!y){this.extend(g[w]);}if(s&&z){for(x=0;x<v;x++){this.extend(g[s[x]]);}}this.length=u;}else{if(!w){w=0;if(!(w in h)){h[w]=this;}}if(!(w in h)){this.length=0;return this;}this[0]=w;this.length=1;if(!this.__c){this.__c={};}if(!h[w]){h[w]=this;}return h[w];}return this;},addComponent:function(y){var v=[],x=0,u;if(arguments.length>1){var t=0,s=arguments.length;for(;t<s;t++){this.__c[arguments[t]]=true;v.push(arguments[t]);}}else{if(y.indexOf(",")!==-1){var w=y.split(m),t=0,s=w.length;for(;t<s;t++){this.__c[w[t]]=true;v.push(w[t]);}}else{this.__c[y]=true;v.push(y);}}u=v.length;for(;x<u;x++){comp=g[v[x]];this.extend(comp);if(comp&&"init" in comp){comp.init.call(this);}}this.trigger("component");return this;},requires:function(v){var w=v.split(m),u=0,s=w.length,t;for(;u<s;++u){t=w[u];if(!this.has(t)){this.addComponent(t);}}},removeComponent:function(s){delete this.__c[s];return this;},has:function(s){return !!this.__c[s];},attr:function(s,t){if(arguments.length===1){if(typeof s==="string"){return this[s];}this.extend(s);this.trigger("change");return this;}this[s]=t;this.trigger("change");return this;},toArray:function(){return p.call(this,0);},delay:function(s,t){this.each(function(){var u=this;setTimeout(function(){s.call(u);},t);});},bind:function(u,t){if(this.length===1){if(!c[u]){c[u]={};}var s=c[u];if(!s[this[0]]){s[this[0]]=[];}s[this[0]].push(t);return this;}this.each(function(){if(!c[u]){c[u]={};}var v=c[u];if(!v[this[0]]){v[this[0]]=[];}v[this[0]].push(t);});return this;},unbind:function(t,s){this.each(function(){var w=c[t],v=0,u,x;if(w&&w[this[0]]){u=w[this[0]].length;}else{return this;}if(u===1||!s){delete w[this[0]];return this;}for(;v<u;v++){x=w[this[0]];if(x[v]==s){x.splice(v,1);v--;}}});return this;},trigger:function(v,w){if(this.length===1){if(c[v]&&c[v][this[0]]){var u=c[v][this[0]],t=0,s=u.length;for(;t<s;t++){u[t].call(this,w);}}return this;}this.each(function(){if(c[v]&&c[v][this[0]]){var z=c[v][this[0]],y=0,x=z.length;for(;y<x;y++){z[y].call(this,w);}}});return this;},each:function(u){var t=0,s=this.length;for(;t<s;t++){u.call(h[this[t]],t);}return this;},clone:function(){var v=this.__c,s,u,t=n.e();for(s in v){t.addComponent(s);}for(u in this){t[u]=this[u];}return t;},destroy:function(){this.each(function(){this.trigger("remove");for(var s in c){this.unbind(s);}delete h[this[0]];});}};n.fn.init.prototype=n.fn;n.clone2=function(u){if(u==null||typeof(u)!="object"){return u;}if(u.constructor){var s=u.constructor();}else{var s=u;}for(var t in u){s[t]=n.clone2(u[t]);}return s;};n.extend=n.fn.extend=function(t){var s=this;if(!t){return s;}for(key in t){if(s===t[key]){continue;}if(typeof t[key]=="object"&&key=="_Particles"){s[key]=n.clone2(t[key]);}else{s[key]=t[key];}}return s;};n.extend({init:function(u,s,t){if(arguments.length===2){t=s;s=u;u=60;}o=u||60;n.viewport.init(s,t);this.onload();this.timer.init();return this;},stop:function(){if(typeof e==="number"){clearInterval(e);}var s=j.cancelRequestAnimationFrame||j.webkitCancelRequestAnimationFrame||j.mozCancelRequestAnimationFrame||j.oCancelRequestAnimationFrame||j.msCancelRequestAnimationFrame||null;if(s){s(f);}e=null;return this;},pause:function(){if(!this._paused){this._paused=true;n._pausedEvents={};for(handler in c.enterframe){n._pausedEvents[handler]=c.enterframe[handler];delete c.enterframe[handler];}n.keydown={};}else{this._paused=false;for(handler in n._pausedEvents){c.enterframe[handler]=n._pausedEvents[handler];}}return this;},timer:{prev:(+new Date),current:(+new Date),fps:0,init:function(){var s=j.requestAnimationFrame||j.webkitRequestAnimationFrame||j.mozRequestAnimationFrame||j.oRequestAnimationFrame||j.msRequestAnimationFrame||null,t=function(u){if(s){e=function(){u();f=s(e);};e();}else{e=setInterval(u,1000/o);}};t(n.timer.step);},step:(function(){var s=0,t=1000/o,u=(new Date).getTime();return function(){s=0;this.prev=this.current;this.current=(+new Date);while((new Date).getTime()>u){n.trigger("enterframe",{frame:b++});u+=t;s++;this.fps=s/this.fpsUpdateFrequency;}if(s){n.DrawManager.draw();}};})(),getFPS:function(){return this.fps;}},e:function(){var t=a(),s;h[t]=null;h[t]=s=n(t);if(arguments.length>0){s.addComponent.apply(s,arguments);}s.addComponent("obj");return s;},c:function(t,s){g[t]=s;},trigger:function(w,x){var v=c[w],u,t,s;for(u in v){if(!v.hasOwnProperty(u)){continue;}s=v[u].length;for(t=0;t<s;t++){if(v[u]&&v[u][t]){v[u][t].call(n(+u),x);}}}},frame:function(){return b;},onload:function(t,v){if(!arguments.length){var u=0,s=q.length,w;for(;u<s;++u){w=q[u];if(w){w.fn.call(w.ctx);}}return this;}q.push({ctx:t,fn:v});return this;},components:function(){return g;},clone:function k(u){if(u==null||typeof(u)!="object"){return u;}var s=u.constructor();for(var t in u){s[t]=k(u[t]);}return s;}});function a(){var s=i++;if(s in h){return a();}return s;}j.Crafty=n;})(window);(function(h,d,g){(function(p){var o,r=function(t){o=t||64;this.map={};},s=Math,e=s.floor,n=s.ceil,q=" ";r.prototype={insert:function(y){var w=r.key(y),v=new m(w,y,this),u=0,t,x;for(u=w.x1;u<=w.x2;u++){for(t=w.y1;t<=w.y2;t++){x=u+q+t;if(!this.map[x]){this.map[x]=[];}this.map[x].push(y);}}return v;},search:function(B,u){var C=r.key(B),A,w,y,z,t,x=[],v=[],D={};if(u===undefined){u=true;}for(A=C.x1;A<=C.x2;A++){for(w=C.y1;w<=C.y2;w++){y=A+q+w;if(this.map[y]){x=x.concat(this.map[y]);}}}if(u){for(A=0,l=x.length;A<l;A++){z=x[A];if(!z){continue;}t=z[0];if(!D[t]&&z.x<B._x+B._w&&z._x+z._w>B._x&&z.y<B._y+B._h&&z._h+z._y>B._y){D[t]=x[A];}}for(z in D){v.push(D[z]);}return v;}else{return x;}},remove:function(x,z){var w=0,v,y;if(arguments.length==1){z=x;x=r.key(z);}for(w=x.x1;w<=x.x2;w++){for(v=x.y1;v<=x.y2;v++){y=w+q+v;if(this.map[y]){var u=this.map[y],t=0,A=u.length;for(;t<A;t++){if(u[t]&&u[t][0]===z[0]){u.splice(t,1);}}}}}}};r.key=function(x){var u=e(x._x/o),w=e(x._y/o),t=e((x._w+x._x)/o),v=e((x._h+x._y)/o);return{x1:u,y1:w,x2:t,y2:v};};r.hash=function(t){return t.x1+q+t.y1+q+t.x2+q+t.y2;};function m(t,v,u){this.keys=t;this.map=u;this.obj=v;}m.prototype={update:function(t){if(r.hash(r.key(t))!=r.hash(this.keys)){this.map.remove(this.keys,this.obj);var u=this.map.insert(this.obj);this.keys=u.keys;}}};p.HashMap=r;})(h);h.map=new h.HashMap();var f=Math,j=f.cos,a=f.sin,k=f.PI,i=k/180;h.c("2D",{_x:0,_y:0,_w:0,_h:0,_z:0,_rotation:0,_alpha:1,_visible:true,_global:null,_origin:null,_mbr:null,_entry:null,_attachy:[],_changed:false,init:function(){this._global=this[0];this._origin={x:0,y:0};if(h.support.setter){this.__defineSetter__("x",function(e){this._attr("_x",e);});this.__defineSetter__("y",function(e){this._attr("_y",e);});this.__defineSetter__("w",function(e){this._attr("_w",e);});this.__defineSetter__("h",function(e){this._attr("_h",e);});this.__defineSetter__("z",function(e){this._attr("_z",e);});this.__defineSetter__("rotation",function(e){this._attr("_rotation",e);});this.__defineSetter__("alpha",function(e){this._attr("_alpha",e);});this.__defineSetter__("visible",function(e){this._attr("_visible",e);});this.__defineGetter__("x",function(){return this._x;});this.__defineGetter__("y",function(){return this._y;});this.__defineGetter__("w",function(){return this._w;});this.__defineGetter__("h",function(){return this._h;});this.__defineGetter__("z",function(){return this._z;});this.__defineGetter__("rotation",function(){return this._rotation;});this.__defineGetter__("alpha",function(){return this._alpha;});this.__defineGetter__("visible",function(){return this._visible;});}else{if(h.support.defineProperty){Object.defineProperty(this,"x",{set:function(e){this._attr("_x",e);},get:function(){return this._x;}});Object.defineProperty(this,"y",{set:function(e){this._attr("_y",e);},get:function(){return this._y;}});Object.defineProperty(this,"w",{set:function(e){this._attr("_w",e);},get:function(){return this._w;}});Object.defineProperty(this,"h",{set:function(e){this._attr("_h",e);},get:function(){return this._h;}});Object.defineProperty(this,"z",{set:function(e){this._attr("_z",e);},get:function(){return this._z;}});Object.defineProperty(this,"rotation",{set:function(e){this._attr("_rotation",e);},get:function(){return this._rotation;}});Object.defineProperty(this,"alpha",{set:function(e){this._attr("_alpha",e);},get:function(){return this._alpha;}});Object.defineProperty(this,"visible",{set:function(e){this._attr("_visible",e);},get:function(){return this._visible;}});}else{this.x=this._x;this.y=this._y;this.w=this._w;this.h=this._h;this.z=this._z;this.rotation=this._rotation;this.alpha=this._alpha;this.visible=this._visible;this.bind("enterframe",function(){if(this.x!==this._x||this.y!==this._y||this.w!==this._w||this.h!==this._h||this.z!==this._z||this.rotation!==this._rotation||this.alpha!==this._alpha||this.visible!==this._visible){var e=this.mbr()||this.pos();if(this.rotation!==this._rotation){this._rotate(this.rotation);}else{var n=this._mbr,m=false;if(n){if(this.x!==this._x){n._x-=this.x-this._x;m=true;}else{if(this.y!==this._y){n._y-=this.y-this._y;m=true;}else{if(this.w!==this._w){n._w-=this.w-this._w;m=true;}else{if(this.h!==this._h){n._h-=this.h-this._h;m=true;}else{if(this.z!==this._z){n._z-=this.z-this._z;m=true;}}}}}}if(m){this.trigger("move",e);}}this._x=this.x;this._y=this.y;this._w=this.w;this._h=this.h;this._z=this.z;this._rotation=this.rotation;this._alpha=this.alpha;this._visible=this.visible;this.trigger("change",e);}});}}this._entry=h.map.insert(this);this.bind("move",function(){var e=this._mbr||this;this._entry.update(e);});this.bind("rotate",function(n){var m=this._mbr||this;this._entry.update(m);});this.bind("remove",function(){h.map.remove(this);this.detach();});},_rotate:function(x){var w=-1*(x%360),G=w*i,u=Math.cos(G),z=Math.sin(G),y={x:this._origin.x+this._x,y:this._origin.y+this._y};if(!w){this._mbr=null;if(!this._rotation%360){return;}}var D=y.x+(this._x-y.x)*u+(this._y-y.y)*z,q=y.y-(this._x-y.x)*z+(this._y-y.y)*u,C=y.x+(this._x+this._w-y.x)*u+(this._y-y.y)*z,n=y.y-(this._x+this._w-y.x)*z+(this._y-y.y)*u,B=y.x+(this._x+this._w-y.x)*u+(this._y+this._h-y.y)*z,m=y.y-(this._x+this._w-y.x)*z+(this._y+this._h-y.y)*u,A=y.x+(this._x-y.x)*u+(this._y+this._h-y.y)*z,e=y.y-(this._x-y.x)*z+(this._y+this._h-y.y)*u,t=Math.floor(Math.min(D,C,B,A)),r=Math.floor(Math.min(q,n,m,e)),s=Math.ceil(Math.max(D,C,B,A)),p=Math.ceil(Math.max(q,n,m,e));this._mbr={_x:t,_y:r,_w:s-t,_h:p-r};var F=this._rotation-x,E=F*i;this.trigger("rotate",{cos:Math.cos(E),sin:Math.sin(E),deg:F,rad:E,o:{x:y.x,y:y.y},matrix:{M11:u,M12:z,M21:-z,M22:u}});},area:function(){return this._w*this._h;},intersect:function(e,q,m,n){var o,p=this._mbr||this;if(typeof e==="object"){o=e;}else{o={x:e,y:q,w:m,h:n};}return p._x<o.x+o.w&&p._x+p._w>o.x&&p._y<o.y+o.h&&p._h+p._y>o.y;},within:function(e,p,m,n){var o;if(typeof e==="object"){o=e;}else{o={x:e,y:p,w:m,h:n};}return o.x>=this.x&&o.x+o.w<=this.x+this.w&&o.y>=this.y&&o.y+o.h<=this.y+this.h;},pos:function(){return{_x:(this._x),_y:(this._y),_w:(this._w),_h:(this._h)};},mbr:function(){if(!this._mbr){return this.pos();}return{_x:(this._mbr._x),_y:(this._mbr._y),_w:(this._mbr._w),_h:(this._mbr._h)};},isAt:function(e,m){return this.x<=e&&this.x+this.w>=e&&this.y<=m&&this.y+this.h>=m;},move:function(e,m){if(e.charAt(0)==="n"){this.y-=m;}if(e.charAt(0)==="s"){this.y+=m;}if(e==="e"||e.charAt(1)==="e"){this.x+=m;}if(e==="w"||e.charAt(1)==="w"){this.x-=m;}return this;},shift:function(e,o,m,n){if(e){this.x+=e;}if(o){this.y+=o;}if(m){this.w+=m;}if(n){this.h+=n;}return this;},attach:function(e){function m(o){if(!o){return;}if(o.cos){if("rotate" in e){e.rotate(o);}}else{var n=this._mbr||this;dx=n._x-o._x,dy=n._y-o._y,dw=n._w-o._w,dh=n._h-o._h;e.shift(dx,dy,dw,dh);}}this.bind("move",m);this.bind("rotate",m);this._attachy[e[0]]=m;return this;},detach:function(o){if(!o){var m,e=this._attachy;for(m in e){if(!e.hasOwnProperty(m)){continue;}this.unbind("move",e[m]);this._attachy[m]=null;delete this._attachy[m];}return this;}var n=this._attachy[o[0]];this.unbind("move",n);this._attachy[o[0]]=null;delete this._attachy[o[0]];return this;},origin:function(e,n){if(typeof e==="string"){if(e==="centre"||e==="center"||e.indexOf(" ")===-1){e=this._w/2;n=this._h/2;}else{var m=e.split(" ");if(m[0]==="top"){n=0;}else{if(m[0]==="bottom"){n=this._h;}else{if(m[0]==="middle"||m[1]==="center"||m[1]==="centre"){n=this._h/2;}}}if(m[1]==="center"||m[1]==="centre"||m[1]==="middle"){e=this._w/2;}else{if(m[1]==="left"){e=0;}else{if(m[1]==="right"){e=this._w;}}}}}else{if(e>this._w||n>this._h||e<0||n<0){return this;}}this._origin.x=e;this._origin.y=n;return this;},rotate:function(m){this._origin.x=m.o.x-this._x;this._origin.y=m.o.y-this._y;this._attr("_rotation",m.theta);},_attr:function(m,n){var p=this.pos(),e=this.mbr()||p;if(m==="_rotation"){this._rotate(n);}else{if(m==="_z"){this._global=parseInt(n+h.zeroFill(this[0],5),10);this.trigger("reorder");}else{if(m=="_x"||m==="_y"||m==="_w"||m==="_h"){var o=this._mbr;if(o){o[m]-=this[m]-n;}this[m]=n;this.trigger("move",e);}}}this[m]=n;this.trigger("change",e);}});h.c("gravity",{_gravity:0.2,_gy:0,_falling:true,_anti:null,init:function(){if(!this.has("2D")){this.addComponent("2D");}},gravity:function(e){if(e){this._anti=e;}this.bind("enterframe",this._enterframe);return this;},_enterframe:function(){if(this._falling){this._gy+=this._gravity*2;this.y+=this._gy;}else{this._gy=0;}var p,o=false,r=this.pos(),n,m=0,e;r._y++;r.x=r._x;r.y=r._y;r.w=r._w;r.h=r._h;n=h.map.search(r);e=n.length;for(;m<e;++m){p=n[m];if(p!==this&&p.has(this._anti)&&p.intersect(r)){o=p;break;}}if(o){if(this._falling){this.stopFalling(o);}}else{this._falling=true;}},stopFalling:function(m){if(m){this.y=m._y-this._h;}this._falling=false;if(this._up){this._up=false;}this.trigger("hit");},antigravity:function(){this.unbind("enterframe",this._enterframe);}});h.polygon=function(e){if(arguments.length>1){e=Array.prototype.slice.call(arguments,0);}this.points=e;};h.polygon.prototype={containsPoint:function(e,r){var o=this.points,n,m,q=false;for(n=0,m=o.length-1;n<o.length;m=n++){if(((o[n][1]>r)!=(o[m][1]>r))&&(e<(o[m][0]-o[n][0])*(r-o[n][1])/(o[m][1]-o[n][1])+o[n][0])){q=!q;}}return q;},shift:function(e,p){var n=0,m=this.points.length,o;for(;n<m;n++){o=this.points[n];o[0]+=e;o[1]+=p;}},rotate:function(q){var o=0,n=this.points.length,p,m,r;for(;o<n;o++){p=this.points[o];m=q.o.x+(p[0]-q.o.x)*q.cos+(p[1]-q.o.y)*q.sin;r=q.o.y-(p[0]-q.o.x)*q.sin+(p[1]-q.o.y)*q.cos;p[0]=Math.floor(m);p[1]=Math.floor(r);}},draw:function(q){var o=0,n=this.points.length,p,m,r;for(;o<n;o++){p=this.points[o];h.e("2D, DOM, color").attr({x:p[0],y:p[1],w:5,h:5}).color("red");}}};h.c("collision",{collision:function(m){var e=this._mbr||this;if(!m){m=new h.polygon([0,0],[e._w,0],[e._w,e._h],[0,e._h]);}this.map=m;this.attach(this.map);this.map.shift(e._x,e._y);return this;},hit:function(t){var m=this._mbr||this,q=h.map.search(m,false),r=0,o=q.length,x={},e,p,s,w,u=("map" in this&&"containsPoint" in this.map),n=[];if(!o){return false;}for(;r<o;++r){p=q[r];s=p._mbr||p;if(!p){continue;}e=p[0];if(!x[e]&&this[0]!==e&&p.__c[t]&&s._x<m._x+m._w&&s._x+s._w>m._x&&s._y<m._y+m._h&&s._h+s._y>m._y){x[e]=p;}}for(w in x){p=x[w];if(u&&"map" in p){var v=this.SAT(this.map,p.map);v.obj=p;v.type="SAT";if(v){n.push(v);}}else{n.push({obj:p,type:"MBR"});}}if(!n.length){return false;}return n;},onhit:function(n,o,e){var m=false;this.bind("enterframe",function(){var p=this.hit(n);if(p){m=true;o.call(this,p);}else{if(m){if(typeof e=="function"){e.call(this);}m=false;}}});return this;},SAT:function(p,o){var B=p.points,A=o.points,y=0,u=B.length,x,w=A.length,D={x:0,y:0},e,v,s,t,r,C,m=null,q,z,n;for(;y<u;y++){z=B[(y==u-1?0:y+1)];n=B[y];D.x=-(z[1]-n[1]);D.y=(z[0]-n[0]);e=Math.sqrt(D.x*D.x+D.y*D.y);D.x/=e;D.y/=e;v=s=-1;t=r=-1;for(x=0;x<u;++x){q=B[x][0]*D.x+B[x][1]*D.y;if(q>t||t===-1){t=q;}if(q<v||v===-1){v=q;}}for(x=0;x<w;++x){q=A[x][0]*D.x+A[x][1]*D.y;if(q>r||r===-1){r=q;}if(q<s||s===-1){s=q;}}C=(v<s)?s-t:v-r;if(C>0){return false;}if(C>m||m===null){m=C;}}for(y=0;y<w;y++){z=A[(y==w-1?0:y+1)];n=A[y];D.x=-(z[1]-n[1]);D.y=(z[0]-n[0]);e=Math.sqrt(D.x*D.x+D.y*D.y);D.x/=e;D.y/=e;v=s=-1;t=r=-1;for(x=0;x<u;++x){q=B[x][0]*D.x+B[x][1]*D.y;if(q>t||t===-1){t=q;}if(q<v||v===-1){v=q;}}for(x=0;x<w;++x){q=A[x][0]*D.x+A[x][1]*D.y;if(q>r||r===-1){r=q;}if(q<s||s===-1){s=q;}}C=(v<s)?s-t:v-r;if(C>0){return false;}if(C>m||m===null){m=C;}}return{overlap:m};}});h.c("DOM",{_element:null,_filters:{},init:function(){this._element=g.createElement("div");h.stage.inner.appendChild(this._element);this._element.style.position="absolute";this._element.id="ent"+this[0];this.bind("change",function(){if(!this._changed){this._changed=true;h.DrawManager.add(this);}});if(h.support.prefix==="ms"&&h.support.version<9){this.bind("rotate",function(t){var n=t.matrix,s=this._element.style,p=n.M11.toFixed(8),o=n.M12.toFixed(8),r=n.M21.toFixed(8),q=n.M22.toFixed(8);this._filters.rotation="progid:DXImageTransform.Microsoft.Matrix(M11="+p+", M12="+o+", M21="+r+", M22="+q+", sizingMethod='auto expand')";});}this.bind("remove",this.undraw);},DOM:function(e){if(!this.has("2D")){this.addComponent("2D");}this._element=e;this._element.style.position="absolute";return this;},draw:function(){var m=this._element.style,q=this.__coord||[0,0,0,0],p={x:q[0],y:q[1]},o=h.support.prefix;m.top=~~(this._y)+"px";m.left=~~(this._x)+"px";m.width=~~(this._w)+"px";m.height=~~(this._h)+"px";m.zIndex=this._z;m.opacity=this._alpha;m[o+"Opacity"]=this._alpha;if(h.support.prefix==="ms"&&h.support.version<9){if(h.support.version===8){this._filters.alpha="progid:DXImageTransform.Microsoft.Alpha(Opacity="+(this._alpha*100)+")";}else{this._filters.alpha="alpha(opacity="+(this._alpha*100)+")";}}this.applyFilters();if(this._mbr){var n="rotate("+this._rotation+"deg)",e=this._origin.x+"px "+this._origin.y+"px";m.transformOrigin=e;m[o+"TransformOrigin"]=e;m.transform=n;m[o+"Transform"]=n;}this.trigger("draw",{style:m,type:"DOM",co:p});return this;},applyFilters:function(){this._element.style.filter="";for(var e in this._filters){if(!this._filters.hasOwnProperty(e)){continue;}this._element.style.filter+=this._filters[e]+" ";}},undraw:function(){h.stage.inner.removeChild(this._element);return this;},css:function(p,o){var e,n=this._element,q,m=n.style;if(typeof p==="object"){for(e in p){if(!p.hasOwnProperty(e)){continue;}q=p[e];if(typeof q==="number"){q+="px";}m[h.camelize(e)]=q;}}else{if(o){if(typeof o==="number"){o+="px";}m[h.camelize(p)]=o;}else{return h.getStyle(n,p);}}this.trigger("change");return this;}});try{g.execCommand("BackgroundImageCache",false,true);}catch(c){}h.extend({window:{init:function(){this.width=d.innerWidth||(d.document.documentElement.clientWidth||d.document.body.clientWidth);this.height=d.innerHeight||(d.document.documentElement.clientHeight||d.document.body.clientHeight);},width:0,height:0},inner:function(p){var o=p.getBoundingClientRect(),e=o.left,q=o.top,n,m;n=parseInt(this.getStyle(p,"border-left-width")||0,10);m=parseInt(this.getStyle(p,"border-top-width")||0,10);if(!n||!m){n=parseInt(this.getStyle(p,"borderLeftWidth")||0,10);m=parseInt(this.getStyle(p,"borderTopWidth")||0,10);}e+=n;q+=m;return{x:e,y:q};},getStyle:function(m,n){var e;if(m.currentStyle){e=m.currentStyle[h.camelize(n)];}else{if(d.getComputedStyle){e=g.defaultView.getComputedStyle(m,null).getPropertyValue(h.csselize(n));}}return e;},camelize:function(e){return e.replace(/-+(.)?/g,function(m,n){return n?n.toUpperCase():"";});},csselize:function(e){return e.replace(/[A-Z]/g,function(m){return m?"-"+m.toLowerCase():"";});}});h.extend({randRange:function(m,e){return Math.round(Math.random()*(e-m)+m);},zeroFill:function(m,e){e-=m.toString().length;if(e>0){return new Array(e+(/\./.test(m)?2:1)).join("0")+m;}return m.toString();},sprite:function(r,m,e,o,n){var t,z,u,s,v,q,p;if(typeof r==="string"){e=m;m=r;r=1;}if(!n&&o){n=o;}o=parseInt(o||0,10);n=parseInt(n||0,10);p=h.assets[m];if(!p){p=new Image();p.src=m;h.assets[m]=p;p.onload=function(){for(var w in e){h(w).each(function(){this.ready=true;this.trigger("change");});}};}for(t in e){if(!e.hasOwnProperty(t)){continue;}z=e[t];u=z[0]*r+o;s=z[1]*r+n;v=z[2]*r||r;q=z[3]*r||r;h.c(t,{__image:m,__coord:[u,s,v,q],__tile:r,__padding:[o,n],__trim:null,img:p,ready:false,init:function(){this.addComponent("sprite");this.__trim=[0,0,0,0];if(this.img.complete&&this.img.width>0){this.ready=true;this.trigger("change");}this.w=this.__coord[2];this.h=this.__coord[3];this.bind("draw",function(x){var y=x.co,A=x.pos,w=x.ctx;if(x.type==="canvas"){w.drawImage(this.img,y.x,y.y,y.w,y.h,A._x,A._y,A._w,A._h);}else{if(x.type==="DOM"){this._element.style.background="url('"+this.__image+"') no-repeat -"+y.x+"px -"+y.y+"px";}}});},sprite:function(A,D,B,C){this.__coord=[A*this.__tile+this.__padding[0]+this.__trim[0],D*this.__tile+this.__padding[1]+this.__trim[1],this.__trim[2]||B*this.__tile||this.__tile,this.__trim[3]||C*this.__tile||this.__tile];this.trigger("change");},crop:function(A,E,C,D){var B=this._mbr||this.pos();this.__trim=[];this.__trim[0]=A;this.__trim[1]=E;this.__trim[2]=C;this.__trim[3]=D;this.__coord[0]+=A;this.__coord[1]+=E;this.__coord[2]=C;this.__coord[3]=D;this._w=C;this._h=D;this.trigger("change",B);return this;}});}return this;},_events:{},addEvent:function(e,p,o,n){if(arguments.length===3){n=o;o=p;p=d.document;}var m=function(r){var r=r||d.event;n.call(e,r);},q=e[0]||"";if(!this._events[q+p+o+n]){this._events[q+p+o+n]=m;}else{return;}if(p.attachEvent){p.attachEvent("on"+o,m);}else{p.addEventListener(o,m,false);}},removeEvent:function(e,p,o,n){if(arguments.length===3){n=o;o=p;p=d.document;}var q=e[0]||"",m=this._events[q+p+o+n];if(m){if(p.detachEvent){p.detachEvent("on"+o,m);}else{p.removeEventListener(o,m,false);}delete this._events[q+p+o+n];}},background:function(e){h.stage.elem.style.background=e;},viewport:{width:0,height:0,_x:0,_y:0,scroll:function(p,e){var q=(e-this[p]),n=h.context,o=h.stage.inner.style,m;this[p]=e;if(p=="_x"){if(n){n.translate(q,0);}}else{if(n){n.translate(0,q);}}if(n){h.DrawManager.drawAll();}o[p=="_x"?"left":"top"]=~~e+"px";},rect:function(){return{_x:-this._x,_y:-this._y,_w:this.width,_h:this.height};},init:function(e,m){h.window.init();this.width=e||h.window.width;this.height=m||h.window.height;var o=g.getElementById("cr-stage");h.stage={x:0,y:0,fullscreen:false,elem:(o?o:g.createElement("div")),inner:g.createElement("div")};if(!e&&!m){g.body.style.overflow="hidden";h.stage.fullscreen=true;}h.addEvent(this,d,"resize",function(){h.window.init();var q=h.window.width;m=h.window.height,p;if(h.stage.fullscreen){this.width=q;this.height=m;h.stage.elem.style.width=q;h.stage.elem.style.width=m;if(h._canvas){h._canvas.width=q;h._canvas.height=m;h.DrawManager.drawAll();}}p=h.inner(h.stage.elem);h.stage.x=p.x;h.stage.y=p.y;});h.addEvent(this,d,"blur",function(){if(!h.dontPauseOnBlur){h.pause();}});h.addEvent(this,d,"focus",function(){if(h._paused){h.pause();}});if(!o){g.body.appendChild(h.stage.elem);h.stage.elem.id="cr-stage";}var n=h.stage.elem.style,p;h.stage.elem.appendChild(h.stage.inner);h.stage.inner.style.position="absolute";n.width=this.width+"px";n.height=this.height+"px";n.overflow="hidden";n.position="relative";p=h.inner(h.stage.elem);h.stage.x=p.x;h.stage.y=p.y;if(h.support.setter){this.__defineSetter__("x",function(q){this.scroll("_x",q);});this.__defineSetter__("y",function(q){this.scroll("_y",q);});this.__defineGetter__("x",function(){return this._x;});this.__defineGetter__("y",function(){return this._y;});}else{if(h.support.defineProperty){Object.defineProperty(this,"x",{set:function(q){this.scroll("_x",q);},get:function(){return this._x;}});Object.defineProperty(this,"y",{set:function(q){this.scroll("_y",q);},get:function(){return this._y;}});}else{this.x=this._x;this.y=this._y;h.e("viewport");}}}},support:{},keys:{BACKSPACE:8,TAB:9,ENTER:13,PAUSE:19,CAPS:20,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT_ARROW:37,UP_ARROW:38,RIGHT_ARROW:39,DOWN_ARROW:40,INSERT:45,DELETE:46,"0":48,"1":49,"2":50,"3":51,"4":52,"5":53,"6":54,"7":55,"8":56,"9":57,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,NUMPAD_0:96,NUMPAD_1:97,NUMPAD_2:98,NUMPAD_3:99,NUMPAD_4:100,NUMPAD_5:101,NUMPAD_6:102,NUMPAD_7:103,NUMPAD_8:104,NUMPAD_9:105,MULTIPLY:106,ADD:107,SUBSTRACT:109,DECIMAL:110,DIVIDE:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,SHIFT:16,CTRL:17,ALT:18,PLUS:187,COMMA:188,MINUS:189,PERIOD:190}});(function b(){var n=h.support,m=navigator.userAgent.toLowerCase(),e=/(webkit)[ \/]([\w.]+)/.exec(m)||/(o)pera(?:.*version)?[ \/]([\w.]+)/.exec(m)||/(ms)ie ([\w.]+)/.exec(m)||/(moz)illa(?:.*? rv:([\w.]+))?/.exec(m)||[];n.setter=("__defineSetter__" in this&&"__defineGetter__" in this);n.defineProperty=(function(){if(!"defineProperty" in Object){return false;}try{Object.defineProperty({},"x",{});}catch(o){return false;}return true;})();n.audio=("Audio" in d);n.prefix=(e[1]||e[0]);if(n.prefix==="moz"){n.prefix="Moz";}if(e[2]){n.versionName=e[2];n.version=+(e[2].split("."))[0];}n.canvas=("getContext" in g.createElement("canvas"));})();h.c("viewport",{init:function(){this.bind("enterframe",function(){if(h.viewport._x!==h.viewport.x){h.viewport.scroll("_x",h.viewport.x);}if(h.viewport._y!==h.viewport.y){h.viewport.scroll("_y",h.viewport.y);}});}});h.c("canvas",{buffer:50,init:function(){h.DrawManager.total2D++;this.bind("change",function(m){if(this._changed===false){this._changed=h.DrawManager.add(m||this,this);}else{if(m){this._changed=h.DrawManager.add(m,this);}}});this.bind("remove",function(){h.DrawManager.total2D--;h.DrawManager.add(this,this);});},draw:function(u,r,p,s,m){if(!this.ready){return;}if(arguments.length===4){m=s;s=p;p=r;r=u;u=h.context;}var q={_x:(this._x+(r||0)),_y:(this._y+(p||0)),_w:(s||this._w),_h:(m||this._h)},e=u||h.context,n=this.__coord||[0,0,0,0],o={x:n[0]+(r||0),y:n[1]+(p||0),w:s||n[2],h:m||n[3]};if(this._mbr){e.save();e.translate(this._origin.x+this._x,this._origin.y+this._y);q._x=-this._origin.x;q._y=-this._origin.y;e.rotate((this._rotation%360)*(Math.PI/180));}if(this._alpha<1){var t=e.globalAlpha;e.globalAlpha=this._alpha;}this.trigger("draw",{type:"canvas",pos:q,co:o,ctx:e});if(this._mbr){e.restore();}if(this._alpha<1){e.globalAlpha=t;}return this;}});h.extend({context:null,_canvas:null,canvas:function(){if(!h.support.canvas){h.trigger("nocanvas");h.stop();return;}var e;e=g.createElement("canvas");e.width=h.viewport.width;e.height=h.viewport.height;e.style.position="absolute";e.style.left="0px";e.style.top="0px";h.stage.elem.appendChild(e);h.context=e.getContext("2d");h._canvas=e;}});h.extend({down:null,over:null,mouseObjs:0,keydown:{},mouseDispatch:function(r){if(!h.mouseObjs){return;}if(r.type==="touchstart"){r.type="mousedown";}else{if(r.type==="touchmove"){r.type="mousemove";}else{if(r.type==="touchend"){r.type="mouseup";}}}var t=-1,n,m,p=0,o;m=h.map.search(h.viewport.rect());for(o=m.length;p<o;++p){if(!m[p].has("mouse")){continue;}var s=m[p],u=false,w=r.clientX-h.stage.x+g.body.scrollLeft+g.documentElement.scrollLeft,v=r.clientY-h.stage.y+g.body.scrollTop+g.documentElement.scrollTop;if(s.map){if(s.map.containsPoint(w,v)){u=true;}}else{if(s.isAt(w,v)){u=true;}}if(u&&(s._z>=t||t===-1)){if(s._z===t&&s[0]<n[0]){continue;}t=s._z;n=s;}}if(n){if(r.type==="mousedown"){this.down=n;}if(r.type==="mouseup"){if(this.down&&n===this.down){this.down.trigger("click",r);this.down=null;return;}this.down=null;}if(r.type==="mousemove"){if(this.over!==n){if(this.over){this.over.trigger("mouseout",r);this.over=null;}this.over=n;n.trigger("mouseover",r);return;}}n.trigger(r.type,r);}else{if(r.type==="mousemove"&&this.over){this.over.trigger("mouseout",r);this.over=null;}}}});h.onload(this,function(){h.addEvent(this,h.stage.elem,"mousedown",h.mouseDispatch);h.addEvent(this,h.stage.elem,"mouseup",h.mouseDispatch);h.addEvent(this,h.stage.elem,"mousemove",h.mouseDispatch);h.addEvent(this,h.stage.elem,"touchstart",h.mouseDispatch);h.addEvent(this,h.stage.elem,"touchmove",h.mouseDispatch);h.addEvent(this,h.stage.elem,"touchend",h.mouseDispatch);});h.c("mouse",{init:function(){h.mouseObjs++;this.bind("remove",function(){h.mouseObjs--;});},areaMap:function(m){if(arguments.length>1){var e=Array.prototype.slice.call(arguments,0);m=new h.polygon(e);}m.shift(this._x,this._y);this.map=m;this.attach(this.map);return this;}});h.c("draggable",{_startX:0,_startY:0,init:function(){if(!this.has("mouse")){this.addComponent("mouse");}function e(m){this.x=m.clientX-this._startX;this.y=m.clientY-this._startY;}this.bind("mousedown",function(m){this._startX=(m.clientX-h.stage.x)-this._x;this._startY=(m.clientY-h.stage.y)-this._y;h.addEvent(this,h.stage.elem,"mousemove",e);});h.addEvent(this,h.stage.elem,"mouseup",function(){h.removeEvent(this,h.stage.elem,"mousemove",e);});},disable:function(){this.unbind("mousedown");}});h.c("controls",{init:function(){function e(m){m.key=m.keyCode||m.which;if(m.type==="keydown"){h.keydown[m.key]=true;}else{if(m.type==="keyup"){delete h.keydown[m.key];}}if(this.disableControls){return;}this.trigger(m.type,m);if(!(m.metaKey||m.altKey||m.ctrlKey)&&!(m.key==8||m.key>=112&&m.key<=135)){if(m.preventDefault){m.preventDefault();}else{m.returnValue=false;}return false;}}h.addEvent(this,"keydown",e);h.addEvent(this,"keyup",e);this.bind("remove",function(){h.removeEvent(this,"keydown",e);h.removeEvent(this,"keyup",e);});},isDown:function(e){if(typeof e==="string"){e=h.keys[e];}return !!h.keydown[e];}});h.c("fourway",{_speed:3,init:function(){this.requires("controls");},fourway:function(e){if(e){this._speed=e;}this.bind("enterframe",function(){if(this.isDown("RIGHT_ARROW")||this.isDown("D")){this.x+=this._speed;}if(this.isDown("LEFT_ARROW")||this.isDown("A")){this.x-=this._speed;}if(this.isDown("UP_ARROW")||this.isDown("W")){this.y-=this._speed;}if(this.isDown("DOWN_ARROW")||this.isDown("S")){this.y+=this._speed;}});return this;}});h.c("twoway",{_speed:3,_up:false,init:function(){this.requires("controls");},twoway:function(m,e){if(m){this._speed=m;}e=e||this._speed*2;this.bind("enterframe",function(){if(this.isDown("RIGHT_ARROW")||this.isDown("D")){this.x+=this._speed;}if(this.isDown("LEFT_ARROW")||this.isDown("A")){this.x-=this._speed;}if(this._up){this.y-=e;this._falling=true;}}).bind("keydown",function(){if(this.isDown("UP_ARROW")||this.isDown("W")){this._up=true;}});return this;}});h.c("animate",{_reels:null,_frame:null,_current:null,init:function(){this._reels={};},animate:function(s,m,r,e){if(arguments.length<4&&typeof m==="number"){this._current=s;var p=this._reels[s],q=m;this._frame={reel:p,frameTime:Math.ceil(q/p.length),frame:0,current:0,repeat:0};if(arguments.length===3&&typeof r==="number"){if(r===-1){this._frame.repeatInfinitly=true;}else{this._frame.repeat=r;}}this.bind("enterframe",this.drawFrame);return this;}if(typeof m==="number"){var n=m,p=[],o=this.__tile;if(e>m){for(;n<=e;n++){p.push([n*o,r*o]);}}else{for(;n>=e;n--){p.push([n*o,r*o]);}}this._reels[s]=p;}else{if(typeof m==="object"){this._reels[s]=m;}}return this;},drawFrame:function(n){var m=this._frame;if(this._frame.current++===m.frameTime){var o=m.reel[m.frame++];this.__coord[0]=o[0];this.__coord[1]=o[1];this._frame.current=0;}if(m.frame===m.reel.length&&this._frame.current===m.frameTime){m.frame=0;if(this._frame.repeatInfinitly===true||this._frame.repeat>0){if(this._frame.repeat){this._frame.repeat--;}this._frame.current=0;this._frame.frame=0;}else{this.trigger("animationend",{reel:m.reel});this.stop();return;}}this.trigger("change");},stop:function(){this.unbind("enterframe",this.drawFrame);this.unbind("animationend");this._current=null;this._frame=null;return this;},reset:function(){if(!this._frame){return this;}var e=this._frame.reel[0];this.__coord[0]=e[0];this.__coord[1]=e[1];this.stop();return this;},isPlaying:function(e){if(!e){return !!this._interval;}return this._current===e;}});h.c("tween",{tween:function(o,q){var s,e={},p={},n=h.frame(),m=n+q;for(s in o){e[s]=this["_"+s];p[s]=(o[s]-e[s])/q;}console.log(p);this.bind("enterframe",function r(t){if(t.frame>=m){this.unbind("enterframe",r);return;}for(s in o){this[s]+=p[s];}});}});h.c("color",{_color:"",ready:true,init:function(){this.bind("draw",function(m){if(m.type==="DOM"){m.style.background=this._color;m.style.lineHeight=0;}else{if(m.type==="canvas"){if(this._color){m.ctx.fillStyle=this._color;}m.ctx.fillRect(m.pos._x,m.pos._y,m.pos._w,m.pos._h);}}});},color:function(e){this._color=e;this.trigger("change");return this;}});h.c("tint",{_color:null,_strength:1,init:function(){this.bind("draw",function e(n){var m=n.ctx||h.context;m.fillStyle=this._color||"rgb(0,0,0)";m.fillRect(n.pos._x,n.pos._y,n.pos._w,n.pos._h);});},tint:function(e,m){this._strength=m;this._color=h.toRGB(e,this._strength);this.trigger("change");}});h.c("image",{_repeat:"repeat",ready:false,init:function(){this.bind("draw",function(m){if(m.type==="canvas"){this.canvasDraw(m);}else{if(m.type==="DOM"){if(this.__image){m.style.background="url("+this.__image+") "+this._repeat;}}}});},image:function(m,n){this.__image=m;this._repeat=n||"no-repeat";this.img=h.assets[m];if(!this.img){this.img=new Image();h.assets[m]=this.img;this.img.src=m;var e=this;this.img.onload=function(){if(e.has("canvas")){e._pattern=h.context.createPattern(e.img,e._repeat);}e.ready=true;if(e._repeat==="no-repeat"){e.w=e.img.width;e.h=e.img.height;}e.trigger("change");};return this;}else{this.ready=true;if(this.has("canvas")){this._pattern=h.context.createPattern(this.img,this._repeat);}if(this._repeat==="no-repeat"){this.w=this.img.width;this.h=this.img.height;}}this.trigger("change");return this;},canvasDraw:function(n){if(!this.ready||!this._pattern){return;}var m=n.ctx;m.fillStyle=this._pattern;m.save();m.translate(n.pos._x,n.pos._y);m.fillRect(0,0,n.pos._w,n.pos._h);m.restore();}});h.extend({_scenes:[],_current:null,scene:function(e,m){if(arguments.length===1){h("2D").each(function(){if(!this.has("persist")){this.destroy();}});this._scenes[e].call(this);this._current=e;return;}this._scenes[e]=m;return;},rgbLookup:{},toRGB:function(m,o){var n=this.rgbLookup[m];if(n){return n;}var m=(m.charAt(0)==="#")?m.substr(1):m,p=[],e;p[0]=parseInt(m.substr(0,2),16);p[1]=parseInt(m.substr(2,2),16);p[2]=parseInt(m.substr(4,2),16);e=o===undefined?"rgb("+p.join(",")+")":"rgba("+p.join(",")+","+o+")";n=e;return e;}});h.DrawManager=(function(){var n=[],p=[],q,m;q=g.createElement("canvas");if("getContext" in q){m=q.getContext("2d");}return{total2D:h("2D").length,onScreen:function(r){return h.viewport._x+r._x+r._w>0&&h.viewport._y+r._y+r._h>0&&h.viewport._x+r._x<h.viewport.width&&h.viewport._y+r._y<h.viewport.height;},merge:function(y){do{var x=[],r=false,t=0,s=y.length,w,u,v;while(t<s){w=y[t];u=y[t+1];if(t<s-1&&w._x<u._x+u._w&&w._x+w._w>u._x&&w._y<u._y+u._h&&w._h+w._y>u._y){v={_x:~~Math.min(w._x,u._x),_y:~~Math.min(w._y,u._y),_w:Math.max(w._x,u._x)+Math.max(w._w,u._w),_h:Math.max(w._y,u._y)+Math.max(w._h,u._h)};v._w=v._w-v._x;v._h=v._h-v._y;v._w=(v._w==~~v._w)?v._w:v._w+1|0;v._h=(v._h==~~v._h)?v._h:v._h+1|0;x.push(v);t++;r=true;}else{x.push(w);}t++;}y=x.length?h.clone(x):y;if(r){t=0;}}while(r);return y;},add:function o(r,u){if(!u){p.push(r);return;}var s,t=r._mbr||r,v=u._mbr||u;if(r===u){s=r.mbr()||r.pos();}else{s={_x:~~Math.min(t._x,v._x),_y:~~Math.min(t._y,v._y),_w:Math.max(t._w,v._w)+Math.max(t._x,v._x),_h:Math.max(t._h,v._h)+Math.max(t._y,v._y)};s._w=(s._w-s._x);s._h=(s._h-s._y);}if(s._w===0||s._h===0||!this.onScreen(s)){return false;}s._x=~~s._x;s._y=~~s._y;s._w=(s._w===~~s._w)?s._w:s._w+1|0;s._h=(s._h===~~s._h)?s._h:s._h+1|0;n.push(s);return true;},debug:function(){console.log(n,p);},drawAll:function(u){var u=u||h.viewport.rect(),v,t=0,s,r=h.context,w;v=h.map.search(u);s=v.length;r.clearRect(u._x,u._y,u._w,u._h);v.sort(function(y,x){return y._global-x._global;});for(;t<s;t++){w=v[t];if(w._visible&&w.__c.canvas){w.draw();w._changed=false;}}},boundingRect:function(x){if(!x||!x.length){return;}var w=[],t=1,r=x.length,v,u=x[0],s;u=[u._x,u._y,u._x+u._w,u._y+u._h];while(t<r){v=x[t];s=[v._x,v._y,v._x+v._w,v._y+v._h];if(s[0]<u[0]){u[0]=s[0];}if(s[1]<u[1]){u[1]=s[1];}if(s[2]>u[2]){u[2]=s[2];}if(s[3]>u[3]){u[3]=s[3];}t++;}s=u;u={_x:s[0],_y:s[1],_w:s[2]-s[0],_h:s[3]-s[1]};return u;},draw:function e(){if(!n.length&&!p.length){return;}var A=0,t=n.length,u=p.length,G,r,v,D,J,z,E,C=[];for(;A<u;++A){p[A].draw()._changed=false;}p.length=A=0;if(!t){return;}if(t/this.total2D>0.6){console.log("DRAW ALL");this.drawAll();n.length=0;return;}n=this.merge(n);for(;A<t;++A){G=n[A];if(!G){continue;}r=h.map.search(G);J={};for(v=0,D=r.length;v<D;++v){z=r[v];if(J[z[0]]||!z._visible||!z.has("canvas")){continue;}J[z[0]]=true;C.push({obj:z,rect:G});}h.context.clearRect(G._x,G._y,G._w,G._h);}C.sort(function(x,w){return x.obj._global-w.obj._global;});if(!C.length){return;}for(A=0,t=C.length;A<t;++A){z=C[A];G=z.rect;E=z.obj;var s=E._mbr||E,H=(G._x-s._x<=0)?0:~~(G._x-s._x),F=(G._y-s._y<0)?0:~~(G._y-s._y),I=~~Math.min(s._w-H,G._w-(s._x-G._x),G._w,s._w),B=~~Math.min(s._h-F,G._h-(s._y-G._y),G._h,s._h);if(B===0||I===0){continue;}if(E.has("image")||E._mbr){q.width=s._w;q.height=s._h;m.save();m.translate(-s._x,-s._y);E.draw(m);h.context.drawImage(q,H,F,I,B,s._x+H,s._y+F,I,B);m.restore();m.clearRect(0,0,q.width,q.height);}else{E.draw(H,F,I,B);}E._changed=false;}n.length=0;merged={};}};})();h.c("group",{_children:[],group:function(e){this._children=e;this.bind("move",function(t){var o=t._x-this.x,n=t._y-this.y,p=t._w-this.w,r=t._h-this.h,q=0,m=this._children.length,s;for(;q<m;q++){s=this._children[q];if(o){s.x-=o;}if(n){s.y-=n;}if(p){s.w-=p;}if(r){s.h-=r;}}});this.bind("remove",function(){var n=0,m=this._children.length,o;for(;n<m;n++){o.destroy();}});return this;}});h.extend({group:function(){var t=h.e("2D, group"),r=Array.prototype.slice.call(arguments),p=0,n=r.length,o,e,m,s,q;for(;p<n;p++){q=r[p];q.removeComponent("obj");if(q.x<o||!o){o=q.x;}if(q.x+q.w>o+e||!e){e=q.x+q.w-o;}if(q.y<m||!m){m=q.y;}if(q.y+q.h<m+s||!s){s=q.y+q.h-m;}}t.attr({x:o,y:m,w:e,h:s}).group(r);return t;}});h.extend({isometric:{_tile:0,_z:0,init:function(e){this._tile=e;return this;},place:function(o,s,q,p){var e=o*this._tile+(s&1)*(this._tile/2),r=s*this._tile/4,r=r-q*(this._tile/2);p.attr({x:e+h.viewport._x,y:r+h.viewport._y}).z+=q;return this;},zoom:function(e){this._tile=e;h.trigger("zoom",{tile:e});return this;}}});h.c("particles",{init:function(){},particles:function(m){if(!h.support.canvas){return this;}var r,e,p,n,q;r=g.createElement("canvas");r.width=h.viewport.width;r.height=h.viewport.height;r.style.position="absolute";h.stage.elem.appendChild(r);e=r.getContext("2d");this._Particles.init(m);p=this.x+h.viewport.x;n=this.y+h.viewport.y;this._Particles.position=this._Particles.vectorHelpers.create(p,n);var o={x:h.viewport.x,y:h.viewport.y};this.bind("enterframe",function(){p=this.x+h.viewport.x;n=this.y+h.viewport.y;this._Particles.viewportDelta={x:h.viewport.x-o.x,y:h.viewport.y-o.y};o={x:h.viewport.x,y:h.viewport.y};this._Particles.position=this._Particles.vectorHelpers.create(p,n);if(typeof h.DrawManager.boundingRect=="function"){q=h.DrawManager.boundingRect(this._Particles.register);if(q){e.clearRect(q._x,q._y,q._w,q._h);}}else{e.clearRect(0,0,h.viewport.width,h.viewport.height);}this._Particles.update();this._Particles.render(e);});return this;},_Particles:{presets:{maxParticles:150,particles:[],active:true,size:18,sizeRandom:4,speed:1,speedRandom:1.2,lifeSpan:29,lifeSpanRandom:7,angle:65,angleRandom:34,startColour:[255,131,0,1],startColourRandom:[48,50,45,0],endColour:[245,35,0,0],endColourRandom:[60,60,60,0],sharpness:20,sharpnessRandom:10,spread:10,particleCount:0,elapsedFrames:0,duration:-1,emissionRate:0,emitCounter:0,particleIndex:0,fastMode:false,gravity:{x:0,y:0.1}},init:function(e){this.position=this.vectorHelpers.create(0,0);if(typeof e=="undefined"){var e={};}for(key in this.presets){this[key]=e[key]||this.presets[key];}this.emissionRate=this.maxParticles/this.lifeSpan;this.positionRandom=this.vectorHelpers.create(this.spread,this.spread);},addParticle:function(){if(this.particleCount==this.maxParticles){return false;}var e=new this.particle(this.vectorHelpers);this.initParticle(e);this.particles[this.particleCount]=e;this.particleCount++;return true;},initParticle:function(r){var n=function(){return Math.random()*2-1;};r.position.x=this.position.x+this.positionRandom.x*n();r.position.y=this.position.y+this.positionRandom.y*n();var q=(this.angle+this.angleRandom*n())*(Math.PI/180);var m=this.vectorHelpers.create(Math.cos(q),Math.sin(q));var o=this.speed+this.speedRandom*n();r.direction=this.vectorHelpers.multiply(m,o);r.size=this.size+this.sizeRandom*n();r.size=r.size<0?0:~~r.size;r.timeToLive=this.lifeSpan+this.lifeSpanRandom*n();r.sharpness=this.sharpness+this.sharpnessRandom*n();r.sharpness=r.sharpness>100?100:r.sharpness<0?0:r.sharpness;r.sizeSmall=~~((r.size/200)*r.sharpness);var p=[this.startColour[0]+this.startColourRandom[0]*n(),this.startColour[1]+this.startColourRandom[1]*n(),this.startColour[2]+this.startColourRandom[2]*n(),this.startColour[3]+this.startColourRandom[3]*n()];var e=[this.endColour[0]+this.endColourRandom[0]*n(),this.endColour[1]+this.endColourRandom[1]*n(),this.endColour[2]+this.endColourRandom[2]*n(),this.endColour[3]+this.endColourRandom[3]*n()];r.colour=p;r.deltaColour[0]=(e[0]-p[0])/r.timeToLive;r.deltaColour[1]=(e[1]-p[1])/r.timeToLive;r.deltaColour[2]=(e[2]-p[2])/r.timeToLive;r.deltaColour[3]=(e[3]-p[3])/r.timeToLive;},update:function(){if(this.active&&this.emissionRate>0){var o=1/this.emissionRate;this.emitCounter++;while(this.particleCount<this.maxParticles&&this.emitCounter>o){this.addParticle();this.emitCounter-=o;}this.elapsedFrames++;if(this.duration!=-1&&this.duration<this.elapsedFrames){this.stop();}}this.particleIndex=0;this.register=[];while(this.particleIndex<this.particleCount){var t=this.particles[this.particleIndex];if(t.timeToLive>0){t.direction=this.vectorHelpers.add(t.direction,this.gravity);t.position=this.vectorHelpers.add(t.position,t.direction);t.position=this.vectorHelpers.add(t.position,this.viewportDelta);t.timeToLive--;var s=t.colour[0]+=t.deltaColour[0];var q=t.colour[1]+=t.deltaColour[1];var m=t.colour[2]+=t.deltaColour[2];var n=t.colour[3]+=t.deltaColour[3];var e=[];e.push("rgba("+(s>255?255:s<0?0:~~s));e.push(q>255?255:q<0?0:~~q);e.push(m>255?255:m<0?0:~~m);e.push((n>1?1:n<0?0:n.toFixed(2))+")");t.drawColour=e.join(",");e[3]="0)";t.drawColourEnd=e.join(",");this.particleIndex++;}else{if(this.particleIndex!=this.particleCount-1){this.particles[this.particleIndex]=this.particles[this.particleCount-1];}this.particleCount--;}var p={};p._x=~~t.position.x;p._y=~~t.position.y;p._w=t.size;p._h=t.size;this.register.push(p);}},stop:function(){this.active=false;this.elapsedFrames=0;this.emitCounter=0;},render:function(e){for(var n=0,m=this.particleCount;n<m;n++){var p=this.particles[n];var t=p.size;var o=t>>1;if(p.position.x+t<0||p.position.y+t<0||p.position.x-t>h.viewport.width||p.position.y-t>h.viewport.height){continue;}var s=~~p.position.x;var r=~~p.position.y;if(this.fastMode){e.fillStyle=p.drawColour;}else{var q=e.createRadialGradient(s+o,r+o,p.sizeSmall,s+o,r+o,o);q.addColorStop(0,p.drawColour);q.addColorStop(0.9,p.drawColourEnd);e.fillStyle=q;}e.fillRect(s,r,t,t);}},particle:function(e){this.position=e.create(0,0);this.direction=e.create(0,0);this.size=0;this.sizeSmall=0;this.timeToLive=0;this.colour=[];this.drawColour="";this.deltaColour=[];this.sharpness=0;},vectorHelpers:{create:function(e,m){return{x:e,y:m};},multiply:function(e,m){e.x*=m;e.y*=m;return e;},add:function(m,e){m.x+=e.x;m.y+=e.y;return m;}}}});h.extend({audio:{_elems:{},MAX_CHANNELS:5,type:{mp3:"audio/mpeg;",ogg:'audio/ogg; codecs="vorbis"',wav:'audio/wav; codecs="1"',mp4:'audio/mp4; codecs="mp4a.40.2"'},add:function(o,n){if(!h.support.audio){return this;}var r,v,t=new Audio(),p,u=0,q=[];if(arguments.length===1&&typeof o==="object"){for(v in o){if(!o.hasOwnProperty(v)){continue;}if(typeof o[v]!=="string"){var m=o[v],u=0,s=m.length,e;for(;u<s;++u){e=m[u];ext=e.substr(e.lastIndexOf(".")+1).toLowerCase();p=t.canPlayType(this.type[ext]);if(p!==""&&p!=="no"){n=e;break;}}}else{n=o[v];}for(;u<this.MAX_CHANNELS;u++){t=new Audio(n);t.preload="auto";t.load();q.push(t);}this._elems[v]=q;if(!h.assets[n]){h.assets[n]=this._elems[v][0];}}return this;}if(typeof n!=="string"){var u=0,s=n.length,e;for(;u<s;++u){e=n[u];ext=e.substr(e.lastIndexOf(".")+1);p=t.canPlayType(this.type[ext]);if(p!==""&&p!=="no"){n=e;break;}}}for(;u<this.MAX_CHANNELS;u++){t=new Audio(n);t.preload="auto";t.load();q.push(t);}this._elems[o]=q;if(!h.assets[n]){h.assets[n]=this._elems[o][0];}return this;},play:function(p){if(!h.support.audio){return;}var e=this._elems[p],o,n=0,m=e.length;for(;n<m;n++){o=e[n];if(o.ended||!o.currentTime){o.play();break;}else{if(n===m-1){o.currentTime=0;o.play();}}}return this;},settings:function(s,q){if(!q){for(var o in this._elems){this.settings(o,s);}return this;}var e=this._elems[s],r,p,n=0,m=e.length;for(var p in q){for(;n<m;n++){r=e[n];r[p]=q[p];}}return this;}}});h.c("text",{_text:"",_font:"",init:function(){this.bind("draw",function(o){if(o.type==="DOM"){var n=this._element,m=n.style;n.innerHTML=this._text;m.font=this._font;}else{}});},text:function(e){if(!e){return this._text;}this._text=e;this.trigger("change");return this;},font:function(e){this._font=e;this.trigger("change");return this;}});h.c("health",{_mana:100,health:function(e){this._mana=e;return this;},hurt:function(e){this._mana-=e;this.trigger("hurt",{by:e,mana:this._mana});if(this._mana<=0){this.trigger("die");}return this;},heal:function(e){this._mana+=e;this.trigger("heal");return this;}});h.c("score",{_score:0,incrementScore:function(e){this._score+=e;return this;},decrementScore:function(e){this._score-=e;return this;}});h.extend({assets:{},load:function(q,m,e,t){var r=0,n=q.length,s,p,u=n,o=0;for(;r<n;++r){s=q[r];ext=s.substr(s.lastIndexOf(".")+1).toLowerCase();if(h.support.audio&&(ext==="mp3"||ext==="wav"||ext==="ogg"||ext==="mp4")){p=new Audio(s);if(navigator.userAgent.indexOf("Chrome")!=-1){o++;}}else{if(ext==="jpg"||ext==="jpeg"||ext==="gif"||ext==="png"){p=new Image();p.src=s;}else{u--;continue;}}this.assets[s]=p;p.onload=function(){++o;if(e){e.call(this,{loaded:o,total:u,percent:(o/u*100)});}if(o===u){if(m){m();}}};p.onerror=function(){if(t){t.call(this,{loaded:o,total:u,percent:(o/u*100)});}};}}});})(Crafty,window,window.document);