var CRENDER_DEBUG=false;function ImagesPreloader()
{var self=this;this.curItem=-1;this.loadedImages={};this.data=null;this.endCallback=null;this.processCallback=null;this.load=function(data,endCallback,processCallback)
{this.data=data;this.endCallback=endCallback;this.processCallback=processCallback;for(var i=0;i<this.data.length;i++)
{var item=this.data[i];var img=new Image();img.src=item.src;this.loadedImages[item.name]=img;}
wait();};function wait()
{var itemsLoaded=0;var itemsTotal=0;for(var key in self.loadedImages)
{if(self.loadedImages[key].complete)itemsLoaded++;itemsTotal++;}
if(itemsLoaded>=itemsTotal)
{if(self.endCallback)self.endCallback(self.loadedImages);return;}
else
{if(self.processCallback)self.processCallback(Math.floor(itemsLoaded/itemsTotal*100));setTimeout(wait,50);}}}
var Utils={touchScreen:("ontouchstart"in window),globalScale:1,setCookie:function(name,value)
{window.localStorage.setItem(name,value);},getCookie:function(name)
{return window.localStorage.getItem(name);},bindEvent:function(el,eventName,eventHandler)
{if(el.addEventListener)
{el.addEventListener(eventName,eventHandler,false);}
else if(el.attachEvent)
{el.attachEvent('on'+eventName,eventHandler);}},getObjectLeft:function(element)
{result=element.offsetLeft;if(element.offsetParent)result+=Utils.getObjectLeft(element.offsetParent);return result;},getObjectTop:function(element)
{result=element.offsetTop;if(element.offsetParent)result+=Utils.getObjectTop(element.offsetParent);return result;},parseGet:function()
{var get={};var s=new String(window.location);var p=s.indexOf("?");var tmp,params;if(p!=-1)
{s=s.substr(p+1,s.length);params=s.split("&");for(var i=0;i<params.length;i++)
{tmp=params[i].split("=");get[tmp[0]]=tmp[1];}}
return get;},globalPixelScale:1,getMouseCoord:function(event,object)
{var e=event||window.event;if(e.touches)e=e.touches[0];if(!e)return{x:0,y:0};var x=0;var y=0;var mouseX=0;var mouseY=0;if(object)
{x=Utils.getObjectLeft(object);y=Utils.getObjectTop(object);}
if(e.pageX||e.pageY)
{mouseX=e.pageX;mouseY=e.pageY;}
else if(e.clientX||e.clientY)
{mouseX=e.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft)-document.documentElement.clientLeft;mouseY=e.clientY+(document.documentElement.scrollTop||document.body.scrollTop)-document.documentElement.clientTop;}
var retX=(mouseX-x);var retY=(mouseY-y);return{x:retX,y:retY};},extend:function(Child,Parent)
{var F=function(){};F.prototype=Parent.prototype;Child.prototype=new F();Child.prototype.constructor=Child;Child.superclass=Parent.prototype;},removeFromArray:function(arr,item)
{var tmp=[];for(var i=0;i<arr.length;i++)
{if(arr[i]!=item)tmp.push(arr[i]);}
return tmp;},showLoadProgress:function(val)
{var scl=Utils.globalScale;var s='Loading: '+val+'%';s+='<br><br>';s+='<div style="display: block; background: #000; width: '+(val*scl*2)+'px; height: '+(10*scl)+'px;">&nbsp;</div>';document.getElementById('progress').innerHTML=s;},mobileHideAddressBar:function()
{window.scrollTo(0,1);},mobileCheckIphone4:function()
{if(window.devicePixelRatio)
{if(navigator.userAgent.indexOf('iPhone')!=-1&&window.devicePixelRatio==2)return true;}
return false;},checkSpilgamesEnvironment:function()
{return(typeof ExternalAPI!="undefined"&&ExternalAPI.type=="Spilgames"&&ExternalAPI.check());},mobileCorrectPixelRatio:function()
{var meta=document.createElement('meta');meta.name="viewport";var content="target-densitydpi=device-dpi, user-scalable=no";if(Utils.checkSpilgamesEnvironment())
{if(window.devicePixelRatio>1)content+=", initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5";else content+=", initial-scale=1, maximum-scale=1, minimum-scale=1";}
else
{if(Utils.mobileCheckIphone4())content+=", initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5";else content+=", initial-scale=1, maximum-scale=1, minimum-scale=1";}
meta.content=content;document.getElementsByTagName('head')[0].appendChild(meta);},getMobileScreenResolution:function(landscape)
{var scale=1;var w=0;var h=0;var container={width:window.innerWidth,height:window.innerHeight};if(!Utils.touchScreen||container.height>container.width)
{w=container.width;h=container.height;}
else
{w=container.height;h=container.width;}
if(Utils.touchScreen)
{if(w>320&&w<=480)scale=1.5;if(w>480)scale=2;if(Utils.mobileCheckIphone4())scale=2;}
else
{if(landscape)
{if(h>=640)scale=2;if(h<640&&h>=480)scale=1.5;}
else
{if(h>=800&&h<960)scale=1.5;if(h>=960)scale=2;}}
return Utils.getScaleScreenResolution(scale,landscape);},getScaleScreenResolution:function(scale,landscape)
{var w,h;w=Math.round(320*scale);h=Math.round(480*scale);if(landscape)
{var tmp=w;w=h;h=tmp;}
return{width:w,height:h,scale:scale};},imagesRoot:'images',createLayout:function(container,resolution)
{var scl=Utils.globalScale;var height=window.innerHeight;if("orientation"in window)height=1024;else document.body.style.overflow="hidden";var s="";s+='<div id="progress_container" align="center" style="width: 100%; height: '+height+'px; display: block; width: 100%; position: absolute; left: 0px; top: 0px;">';s+='<table cellspacing="0" cellpadding="0"><tr><td id="progress" align="center" valign="middle" style="width: '+resolution.width+'px; height: '+resolution.height+'px; color: #000; background: #fff; font-weight: bold; font-family: Verdana; font-size: '+(12*scl)+'px; vertical-align: middle;"></td></tr></table>';s+='</div>';s+='<div id="screen_background_container" align="center" style="width: 100%; height: '+height+'px; position: absolute; left: 0px; top: 0px; display: none; z-index: 2;">'
s+='<div id="screen_background_wrapper" style="width: '+resolution.width+'px; height: '+resolution.height+'px; overflow: hidden; position: relative;">';s+='<canvas id="screen_background" width="'+resolution.width+'" height="'+resolution.height+'"></canvas>';s+='</div>';s+='</div>';s+='<div id="screen_container" align="center" style="width: 100%; height: '+height+'px; position: absolute; left: 0px; top: 0px; display: none; z-index: 3;">';s+='<div id="screen_wrapper" style="width: '+resolution.width+'px; height: '+resolution.height+'px; overflow: hidden; position: relative;">';s+='<canvas id="screen" style="position: absolute; left: 0px; top: 0px; z-index: 1000000;" width="'+resolution.width+'" height="'+resolution.height+'">You browser does not support this application :(</canvas>';s+='</div>';s+='</div>';container.innerHTML=s;var p=document.createElement("div");p.setAttribute("id","p2l_container");p.setAttribute("align","center");var w=resolution.width;p.setAttribute("style","width: 100%; height: "+height+"px; position: absolute; left: 0px; top: 0px; display: none; z-index: 1000; background: #fff;");p.innerHTML='<img id="p2l" src="'+Utils.imagesRoot+'/p2l.jpg" style="padding-top: '+((w-240)/2)+'px" />';document.body.appendChild(p);},preventEvent:function(e)
{e.preventDefault();e.stopPropagation();e.cancelBubble=true;e.returnValue=false;return false;},addMobileListeners:function(landscape)
{Utils.bindEvent(document.body,"touchstart",Utils.preventEvent);Utils.bindEvent(window,"scroll",function(e){setTimeout("window.scrollTo(0, 1)",300);});Utils.bindEvent(window,"orientationchange",function(){eval("Utils.checkOrientation("+(landscape?"true":"false")+")",100);});setTimeout(Utils.mobileHideAddressBar,500);},storeOrient:null,checkOrientation:function(landscape)
{if(!("orientation"in window))return;if(!document.getElementById('screen_container'))return;var getParams=Utils.parseGet();if(getParams.nocheckorient==1)return;var orient=(Math.abs(window.orientation)==90);if(Utils.storeOrient===orient)return;Utils.storeOrient=orient;var ok=(orient==landscape);if(!ok)
{Utils.dispatchEvent("lockscreen");document.getElementById('p2l_container').style.display='block';document.getElementById('screen_background_container').style.display='none';document.getElementById('screen_container').style.display='none';}
else
{Utils.dispatchEvent("unlockscreen");document.getElementById('p2l_container').style.display='none';document.getElementById('screen_background_container').style.display='block';document.getElementById('screen_container').style.display='block';}
if(Utils.checkSpilgamesEnvironment())document.getElementById('p2l_container').style.display='none';setTimeout(Utils.mobileHideAddressBar,50);setTimeout(Utils.fitLayoutToScreen,100);},fitLayoutTimer:null,addFitLayoutListeners:function()
{Utils.fitLayoutTimer=setInterval(Utils.fitLayoutToScreen,500);},removeFitLayoutListeners:function()
{clearInterval(Utils.fitLayoutTimer);},fitLayoutLock:false,fitLayoutToScreen:function(container)
{if(Utils.fitLayoutLock)return;var p,s,width,height;if(typeof container!="object"||!container.width)
{width=window.innerWidth;height=window.innerHeight;if(Utils.checkSpilgamesEnvironment())height-=25;container={width:width,height:height};}
s=document.getElementById("screen");if(!s)return;if(!s.initWidth)
{s.initWidth=s.width;s.initHeight=s.height;}
width=s.initWidth;height=s.initHeight;var scale=1;var scaleX=container.width/width;var scaleY=container.height/height;scale=(scaleX<scaleY?scaleX:scaleY);Utils.globalPixelScale=scale;width=Math.floor(width*scale);height=Math.floor(height*scale);if(s.lastWidth==width&&s.lastHeight==height)return;s.lastWidth=width;s.lastHeight=height;Utils.resizeElement("screen",width,height);Utils.resizeElement("screen_background",width,height);s=document.getElementById("progress");if(s)
{s.style.width=(~~width)+"px";s.style.height=(~~height)+"px";}
s=document.getElementById("screen_wrapper");s.style.width=(~~width)+"px";s.style.height=(~~height)+"px";s=document.getElementById("screen_background_wrapper");s.style.width=(~~width)+"px";s.style.height=(~~height)+"px";Utils.dispatchEvent("fitlayout");setTimeout(Utils.mobileHideAddressBar,50);},resizeElement:function(id,width,height)
{var s=document.getElementById(id);if(!s)return;s.setAttribute("width",width);s.setAttribute("height",height);},drawIphoneLimiter:function(stage,landscape)
{if(landscape)stage.drawRectangle(240,295,480,54,"#f00",true,0.5,true);else stage.drawRectangle(160,448,320,64,"#f00",true,0.5,true);},drawGrid:function(stage,landscape,col)
{if(typeof landscape=='undefined')landscape=false;var dx=10;var dy=10;if(typeof col=='undefined')col='#FFF';var w=1/Utils.globalScale/Utils.globalPixelScale;var s={w:(landscape?480:320),h:(landscape?320:480)}
for(var x=dx;x<s.w;x+=dx)
{var o=0.1+0.1*(((x-dx)/dx)%10);stage.drawLine(x,0,x,s.h,w,col,o);}
for(var y=dy;y<s.h;y+=dy)
{var o=0.1+0.1*(((y-dy)/dy)%10);stage.drawLine(0,y,s.w,y,w,col,o);}
stage.drawLine(s.w/2,0,s.w/2,s.h,w,'#F00',1);stage.drawLine(0,s.h/2,s.w,s.h/2,w,'#F00',1);},drawScaleFix:function(stage,landscape)
{if(Utils.globalScale==0.75)
{if(landscape)stage.drawRectangle(507,160,54,320,"#000",true,1,true);else stage.drawRectangle(160,507,320,54,"#000",true,1,true);}
if(Utils.globalScale==1.5)
{if(landscape)stage.drawRectangle(510,160,60,320,"#000",true,1,true);else stage.drawRectangle(160,510,320,60,"#000",true,1,true);}},grad2radian:function(val){return val/(180/Math.PI);},radian2grad:function(val){return val*(180/Math.PI);},eventsListeners:[],onlockscreen:null,onunlockscreen:null,onfitlayout:null,addEventListener:function(type,callback)
{EventsManager.addEvent(Utils,type,callback);},removeEventListener:function(type,callback)
{EventsManager.removeEvent(Utils,type,callback);},dispatchEvent:function(type,params)
{return EventsManager.dispatchEvent(Utils,type,params);}}
var EventsManager={addEvent:function(obj,type,callback)
{if(!obj.eventsListeners)return;for(var i=0;i<obj.eventsListeners.length;i++)
{if(obj.eventsListeners[i].type===type&&obj.eventsListeners[i].callback===callback)return;}
obj.eventsListeners.push({type:type,callback:callback});},removeEvent:function(obj,type,callback)
{if(!obj.eventsListeners)return;for(var i=0;i<obj.eventsListeners.length;i++)
{if(obj.eventsListeners[i].type===type&&obj.eventsListeners[i].callback===callback)
{obj.eventsListeners=Utils.removeFromArray(obj.eventsListeners,obj.eventsListeners[i]);return;}}},dispatchEvent:function(obj,type,params)
{if(!obj.eventsListeners)return;var ret;if(typeof obj["on"+type]=="function")
{ret=obj["on"+type](params);if(ret===false)return false;}
for(var i=0;i<obj.eventsListeners.length;i++)
{if(obj.eventsListeners[i].type===type)
{ret=obj.eventsListeners[i].callback(params);if(ret===false)return false;}}}}
function Sprite(img,w,h,f,l)
{this.uid=0;this.stage=null;this.x=0;this.y=0;this.width=w;this.height=h;this.offset={left:0,top:0};this.scaleX=1;this.scaleY=1;this.rotation=0;this.zIndex=0;this.visible=true;this.opacity=1;this['static']=false;this.ignoreViewport=false;this.animated=true;this.currentFrame=0;this.totalFrames=Math.max(1,~~f);if(this.totalFrames<=1)this.animated=false;this.currentLayer=0;this.totalLayers=Math.max(1,~~l);this.bitmap=img;this.mask=null;this.fillColor=false;this.destroy=false;this.animStep=0;this.animDelay=1;this.drawAlways=false;this.dragged=false;this.dragX=0;this.dragY=0;this.getX=function(){return Math.round(this.x*Utils.globalScale);};this.getY=function(){return Math.round(this.y*Utils.globalScale);};this.getWidth=function(){return this.width*this.scaleX*Utils.globalScale;};this.getHeight=function(){return this.height*this.scaleY*Utils.globalScale;};this.startDrag=function(x,y)
{this.dragged=true;this.dragX=x;this.dragY=y;}
this.stopDrag=function()
{this.dragged=false;this.dragX=0;this.dragY=0;}
this.play=function(){this.animated=true;};this.stop=function(){this.animated=false;};this.gotoAndStop=function(frame)
{this.currentFrame=frame;this.stop();};this.gotoAndPlay=function(frame)
{this.currentFrame=frame;this.play();};this.removeTweens=function()
{if(!this.stage)return;this.stage.clearObjectTweens(this);};this.addTween=function(prop,end,duration,ease,onfinish,onchange)
{if(!this.stage)return;var val=this[prop];if(isNaN(val))return;var t=stage.createTween(this,prop,val,end,duration,ease);t.onchange=onchange;t.onfinish=onfinish;return t;};this.moveTo=function(x,y,duration,ease,onfinish,onchange)
{duration=~~duration;if(duration<=0)
{this.setPosition(x,y);}
else
{var t1=this.addTween('x',x,duration,ease,onfinish,onchange);if(t1)t1.play();var t2=this.addTween('y',y,duration,ease,(t1?null:onfinish),(t1?null:onchange));if(t2)t2.play();}
return this;}
this.moveBy=function(x,y,duration,ease,onfinish,onchange)
{return this.moveTo(this.x+x,this.y+y,duration,ease,onfinish,onchange);}
this.fadeTo=function(opacity,duration,ease,onfinish,onchange)
{duration=~~duration;if(duration<=0)
{this.opacity=opacity;}
else
{var t=this.addTween('opacity',opacity,duration,ease,onfinish,onchange);if(t)t.play();}
return this;}
this.fadeBy=function(opacity,duration,ease,onfinish,onchange)
{var val=Math.max(0,Math.min(1,this.opacity+opacity));return this.fadeTo(val,duration,ease,onfinish,onchange);}
this.rotateTo=function(rotation,duration,ease,onfinish,onchange)
{duration=~~duration;if(duration<=0)
{this.rotation=rotation;}
else
{var t=this.addTween('rotation',rotation,duration,ease,onfinish,onchange);if(t)t.play();}
return this;}
this.rotateBy=function(rotation,duration,ease,onfinish,onchange)
{return this.rotateTo(this.rotation+rotation,duration,ease,onfinish,onchange);}
this.scaleTo=function(scale,duration,ease,onfinish,onchange)
{duration=~~duration;if(duration<=0)
{this.scaleX=this.scaleY=scale;}
else
{var t1=this.addTween('scaleX',scale,duration,ease,onfinish,onchange);if(t1)t1.play();var t2=this.addTween('scaleY',scale,duration,ease,(t1?null:onfinish),(t1?null:onchange));if(t2)t2.play();}
return this;}
this.nextFrame=function()
{this.dispatchEvent("enterframe",{target:this});if(!this.history.created)this.updateHistory();if(!this.animated)return;this.animStep++;if(this.animStep>=this.animDelay)
{this.currentFrame++;this.animStep=0;}
if(this.currentFrame>=this.totalFrames)this.currentFrame=0;};this.updateHistory=function()
{this.history.x=this.getX();this.history.y=this.getY();this.history.rotation=this.rotation;this.history.frame=this.currentFrame;var rect=new Rectangle(this.history.x,this.history.y,this.getWidth(),this.getHeight(),this.rotation);rect.AABB[0].x-=1;rect.AABB[0].y-=1;rect.AABB[1].x+=1;rect.AABB[1].y+=1;this.history.AABB=rect.AABB;this.history.created=true;this.history.changed=false;};this.history={created:false,drawed:false,changed:false,x:0,y:0,rotation:0,frame:0,AABB:[]};this.eventsWhenInvisible=false;this.onmouseover=null;this.onmouseout=null;this.onmousedown=null;this.onmouseup=null;this.onclick=null;this.oncontextmenu=null;this.onmousemove=null;this.onenterframe=null;this.onrender=null;this.onadd=null;this.onremove=null;this.onbox2dsync=null;this.mouseOn=false;this.getPosition=function()
{return{x:this.x+0,y:this.y+0}}
this.setPosition=function(x,y)
{if((typeof y=='undefined')&&(typeof x['x']!='undefined')&&(typeof x['y']!='undefined'))
{return this.setPosition(x.x,x.y);}
this.x=parseFloat(x);this.y=parseFloat(y);}
this.setZIndex=function(z)
{this.zIndex=~~z;if(!this.stage)return;this.stage.setZIndex(this,~~z);}
this.eventsListeners=[];this.addEventListener=function(type,callback)
{EventsManager.addEvent(this,type,callback);}
this.removeEventListener=function(type,callback)
{EventsManager.removeEvent(this,type,callback);}
this.dispatchEvent=function(type,params)
{return EventsManager.dispatchEvent(this,type,params);}
this.hitTestPoint=function(x,y,checkPixel,checkDragged,debug)
{if(!this.stage)return false;return this.stage.hitTestPointObject(this,x,y,checkPixel,checkDragged,debug);}}
function Tween(obj,prop,start,end,duration,callback)
{var self=this;if(typeof obj!='object')obj=null;if(obj)
{if(typeof obj[prop]=='undefined')throw new Error('Trying to tween undefined property "'+prop+'"');if(isNaN(obj[prop]))throw new Error('Tweened value can not be '+(typeof obj[prop]));}
else
{if(isNaN(prop))throw new Error('Tweened value can not be '+(typeof prop));}
if(typeof callback!='function')callback=Easing.linear.easeIn;this.obj=obj;this.prop=prop;this.onchange=null;this.onfinish=null;this.start=start;this.end=end;this.duration=~~duration;this.callback=callback;this.playing=false;this._pos=-1;this.play=function()
{self.playing=true;self.tick();}
this.pause=function()
{self.playing=false;}
this.rewind=function()
{self._pos=-1;}
this.forward=function()
{self._pos=this.duration;}
this.stop=function()
{self.pause();self.rewind();}
this.updateValue=function(val)
{if(self.obj)
{self.obj[self.prop]=val;}
else
{self.prop=val;}}
this.tick=function()
{if(!self.playing)return false;self._pos++;if(self._pos<0)return false;if(self._pos>self.duration)return self.finish();var func=self.callback;var val=func(self._pos,self.start,self.end-self.start,self.duration);this.updateValue(val);self.dispatchEvent("change",{target:self,value:val});return false;}
this.finish=function()
{self.stop();self.updateValue(self.end);return self.dispatchEvent("finish",{target:self,value:self.end});}
this.eventsListeners=[];this.addEventListener=function(type,callback)
{EventsManager.addEvent(this,type,callback);}
this.removeEventListener=function(type,callback)
{EventsManager.removeEvent(this,type,callback);}
this.dispatchEvent=function(type,params)
{return EventsManager.dispatchEvent(this,type,params);}}
var Easing={back:{easeIn:function(t,b,c,d)
{var s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b;},easeOut:function(t,b,c,d)
{var s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b;},easeInOut:function(t,b,c,d)
{var s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b;}},bounce:{easeIn:function(t,b,c,d)
{return c-Easing.bounce.easeOut(d-t,0,c,d)+b;},easeOut:function(t,b,c,d)
{if((t/=d)<(1/2.75))return c*(7.5625*t*t)+b;else if(t<(2/2.75))return c*(7.5625*(t-=(1.5/2.75))*t+0.75)+b;else if(t<(2.5/2.75))return c*(7.5625*(t-=(2.25/2.75))*t+0.9375)+b;else return c*(7.5625*(t-=(2.625/2.75))*t+0.984375)+b;},easeInOut:function(t,b,c,d)
{if(t<d/2)return Easing.bounce.easeIn(t*2,0,c,d)*0.5+b;else return Easing.bounce.easeOut(t*2-d,0,c,d)*0.5+c*0.5+b;}},circular:{easeIn:function(t,b,c,d)
{return-c*(Math.sqrt(1-(t/=d)*t)-1)+b;},easeOut:function(t,b,c,d)
{return c*Math.sqrt(1-(t=t/d-1)*t)+b;},easeInOut:function(t,b,c,d)
{if((t/=d/2)<1)return-c/2*(Math.sqrt(1-t*t)-1)+b;return c/2*(Math.sqrt(1-(t-=2)*t)+1)+b;}},cubic:{easeIn:function(t,b,c,d)
{return c*(t/=d)*t*t+b;},easeOut:function(t,b,c,d)
{return c*((t=t/d-1)*t*t+1)+b;},easeInOut:function(t,b,c,d)
{if((t/=d/2)<1)return c/2*t*t*t+b;return c/2*((t-=2)*t*t+2)+b;}},exponential:{easeIn:function(t,b,c,d)
{return t==0?b:c*Math.pow(2,10*(t/d-1))+b;},easeOut:function(t,b,c,d)
{return t==d?b+c:c*(-Math.pow(2,-10*t/d)+1)+b;},easeInOut:function(t,b,c,d)
{if(t==0)return b;if(t==d)return b+c;if((t/=d/2)<1)return c/2*Math.pow(2,10*(t-1))+b;return c/2*(-Math.pow(2,-10*--t)+2)+b;}},linear:{easeIn:function(t,b,c,d)
{return c*t/d+b;},easeOut:function(t,b,c,d)
{return c*t/d+b;},easeInOut:function(t,b,c,d)
{return c*t/d+b;}},quadratic:{easeIn:function(t,b,c,d)
{return c*(t/=d)*t+b;},easeOut:function(t,b,c,d)
{return-c*(t/=d)*(t-2)+b;},easeInOut:function(t,b,c,d)
{if((t/=d/2)<1)return c/2*t*t+b;return-c/2*((--t)*(t-2)-1)+b;}},quartic:{easeIn:function(t,b,c,d)
{return c*(t/=d)*t*t*t+b;},easeOut:function(t,b,c,d)
{return-c*((t=t/d-1)*t*t*t-1)+b;},easeInOut:function(t,b,c,d)
{if((t/=d/2)<1)return c/2*t*t*t*t+b;return-c/2*((t-=2)*t*t*t-2)+b;}},quintic:{easeIn:function(t,b,c,d)
{return c*(t/=d)*t*t*t*t+b;},easeOut:function(t,b,c,d)
{return c*((t=t/d-1)*t*t*t*t+1)+b;},easeInOut:function(t,b,c,d)
{if((t/=d/2)<1)return c/2*t*t*t*t*t+b;return c/2*((t-=2)*t*t*t*t+2)+b;}},sine:{easeIn:function(t,b,c,d)
{return-c*Math.cos(t/d*(Math.PI/2))+c+b;},easeOut:function(t,b,c,d)
{return c*Math.sin(t/d*(Math.PI/2))+b;},easeInOut:function(t,b,c,d)
{return-c/2*(Math.cos(Math.PI*t/d)-1)+b;}}}
function StageTimer(callback,timeout,repeat)
{this.repeat=repeat;this.initialTimeout=timeout;this.timeout=timeout;this.callback=callback;this.paused=false;this.update=function()
{if(this.paused)return;this.timeout--;if(this.timeout==0)
{if(typeof this.callback=="function")this.callback();if(typeof this.callback=="string")eval(this.callback);if(this.repeat)this.timeout=this.initialTimeout;else return true;}
return false;};this.resume=function(){this.paused=false;};this.pause=function(){this.paused=true;};}
function Stage(cnsId,w,h)
{var self=this;this.canvas=document.getElementById(cnsId);this.canvas.renderController=this;this.canvas.ctx=this.canvas.getContext('2d');this.screenWidth=w;this.screenHeight=h;this.viewport={x:0,y:0};this.objects=[];this.objectsCounter=0;this.buffer=document.createElement('canvas');this.buffer.width=w*Utils.globalScale;this.buffer.height=h*Utils.globalScale;this.buffer.ctx=this.buffer.getContext('2d');this.delay=40;this.fillColor=false;this.started=false;this.fps=0;this.lastFPS=0;this.showFPS=false;this.pixelClickEvent=false;this.pixelMouseUpEvent=false;this.pixelMouseDownEvent=false;this.pixelMouseMoveEvent=false;this.ceilSizes=false;this.tmMain;this.tmFPS;this.partialUpdate=false;this.clearLock=false;this.destroy=function()
{clearTimeout(this.tmMain);clearTimeout(this.tmFPS);this.stop();this.clear();this.clearScreen(this.canvas);}
this.clearScreen=function(canvas)
{canvas.ctx.clearRect(0,0,this.screenWidth*Utils.globalScale*Utils.globalPixelScale,this.screenHeight*Utils.globalScale*Utils.globalPixelScale);}
this.findMaxZIndex=function()
{var max=-1;var ix=false;for(var i=0;i<this.objects.length;i++)
{if(this.objects[i].zIndex>max)
{max=this.objects[i].zIndex;ix=i;}}
return{index:ix,zIndex:max};};this.findMinZIndex=function()
{var min=-1;var ix=false;for(var i=0;i<this.objects.length;i++)
{if(i==0)
{min=this.objects[i].zIndex;ix=0;}
if(this.objects[i].zIndex<min)
{min=this.objects[i].zIndex;ix=i;}}
return{index:ix,zIndex:min};};this.addChild=function(item)
{var f=this.findMaxZIndex();var z=item.zIndex;if(f.index!==false)item.zIndex=f.zIndex+1;else item.zIndex=0;this.objectsCounter++;item.uid=this.objectsCounter;item.stage=this;this.objects.push(item);if(z!=0)
{this.setZIndex(item,~~z);}
item.dispatchEvent("add",{target:item});return item;};this.removeChild=function(item)
{if(item)
{this.clearObjectTweens(item);item.dispatchEvent("remove",{target:item});item.stage=null;this.objects=Utils.removeFromArray(this.objects,item);}};this.setZIndex=function(item,index)
{var bSort=true;var i,tmp;item.zIndex=index;while(bSort)
{bSort=false;for(i=0;i<this.objects.length-1;i++)
{if(this.objects[i].zIndex>this.objects[i+1].zIndex)
{tmp=this.objects[i];this.objects[i]=this.objects[i+1];this.objects[i+1]=tmp;bSort=true;}}}}
this.hitTestPointObject=function(obj,x,y,pixelCheck,includeDragged,debug)
{var cX,cY,cW,cH,mX,mY,r,present,imageData;cW=obj.width*Math.abs(obj.scaleX);cH=obj.height*Math.abs(obj.scaleY);cX=obj.x-cW/2;cY=obj.y-cH/2;mX=x;mY=y;if(!obj.ignoreViewport)
{mX+=this.viewport.x;mY+=this.viewport.y;}
present=false;if(obj.rotation==0)
{if(cX<=mX&&cY<=mY&&cX+cW>=mX&&cY+cH>=mY)present=true;}
else
{r=new Rectangle(obj.x,obj.y,cW,cH,obj.rotation);if(r.hitTestPoint(new Vector(mX,mY)))present=true;}
if(present&&pixelCheck)
{this.buffer.width=this.screenWidth*Utils.globalScale*Utils.globalPixelScale;this.buffer.height=this.screenHeight*Utils.globalScale*Utils.globalPixelScale;this.clearScreen(this.buffer);this.renderObject(this.buffer,obj);var pX=Math.floor(x*Utils.globalScale*Utils.globalPixelScale);var pY=Math.floor(y*Utils.globalScale*Utils.globalPixelScale);imageData=this.buffer.ctx.getImageData(pX,pY,1,1);if(imageData.data[3]==0)present=false;}
if(!present&&includeDragged&&obj.dragged)present=true;return present;}
this.getObjectsStackByCoord=function(x,y,pixelCheck,includeDragged,debug)
{var obj;var tmp=[];for(var i=0;i<this.objects.length;i++)
{if(this.objects[i].visible||this.objects[i].eventsWhenInvisible)
{obj=this.objects[i];if(this.hitTestPointObject(obj,x,y,pixelCheck,includeDragged,debug))
{tmp.push(obj);}}}
return tmp;};this.getMaxZIndexInStack=function(stack)
{var max=-1;var ix=0;for(var i=0;i<stack.length;i++)
{if(stack[i].zIndex>max)
{max=stack[i].zIndex;ix=i;}}
return ix;};this.sortStack=function(stack,revert)
{var bSort=true;var ok;var i,tmp;while(bSort)
{bSort=false;for(i=0;i<stack.length-1;i++)
{ok=false;if(stack[i].zIndex<stack[i+1].zIndex&&!revert)ok=true;if(stack[i].zIndex>stack[i+1].zIndex&&revert)ok=true;if(ok)
{tmp=stack[i];stack[i]=stack[i+1];stack[i+1]=tmp;bSort=true;}}}
return stack;}
this.finalizeMouseCoords=function(obj,m)
{if(!obj)return m;var eX=this.prepareMouseCoord(m.x);var eY=this.prepareMouseCoord(m.y);if(!obj.ignoreViewport)
{eX+=this.viewport.x;eY+=this.viewport.y;}
eX=eX-obj.x;eY=eY-obj.y;return{x:eX,y:eY};}
this.prepareMouseCoord=function(val)
{return val/Utils.globalScale/Utils.globalPixelScale;}
this.checkClick=function(event)
{var m=Utils.getMouseCoord(event,this.canvas);var stack=this.getObjectsStackByCoord(this.prepareMouseCoord(m.x),this.prepareMouseCoord(m.y),this.pixelClickEvent,false,true);var ret,f;if(stack.length>0)
{stack=this.sortStack(stack);for(var i=0;i<stack.length;i++)
{f=this.finalizeMouseCoords(stack[i],m);ret=stack[i].dispatchEvent("click",{target:stack[i],x:f.x,y:f.y});if(ret===false)return;}}};this.checkContextMenu=function(event)
{var m=Utils.getMouseCoord(event,this.canvas);var stack=this.getObjectsStackByCoord(this.prepareMouseCoord(m.x),this.prepareMouseCoord(m.y),this.pixelClickEvent);var ret,f;if(stack.length>0)
{stack=this.sortStack(stack);for(var i=0;i<stack.length;i++)
{f=this.finalizeMouseCoords(stack[i],m);ret=stack[i].dispatchEvent("contextmenu",{target:stack[i],x:f.x,y:f.y});if(ret===false)return;}}};this.checkMouseMove=function(event)
{var m=Utils.getMouseCoord(event,this.canvas);for(i=0;i<this.objects.length;i++)
{if(this.objects[i].dragged)
{var eX=m.x/Utils.globalScale/Utils.globalPixelScale;var eY=m.y/Utils.globalScale/Utils.globalPixelScale;if(!this.objects[i].ignoreViewport)
{eX+=this.viewport.x;eY+=this.viewport.y;}
this.objects[i].x=eX-this.objects[i].dragX;this.objects[i].y=eY-this.objects[i].dragY;}}
var stack=this.getObjectsStackByCoord(this.prepareMouseCoord(m.x),this.prepareMouseCoord(m.y),this.pixelMouseMoveEvent);var i,n,ret,bOk,f;var overStack=[];if(stack.length>0)
{stack=this.sortStack(stack);for(i=0;i<stack.length;i++)
{overStack.push(stack[i]);f=this.finalizeMouseCoords(stack[i],m);if(!stack[i].mouseOn)ret=stack[i].dispatchEvent("mouseover",{target:stack[i],x:f.x,y:f.y});stack[i].mouseOn=true;if(ret===false)break;}
for(i=0;i<stack.length;i++)
{f=this.finalizeMouseCoords(stack[i],m);ret=stack[i].dispatchEvent("mousemove",{target:stack[i],x:f.x,y:f.y});if(ret===false)break;}}
for(i=0;i<this.objects.length;i++)
{if(this.objects[i].mouseOn)
{bOk=false;for(n=0;n<overStack.length;n++)
{if(overStack[n]==this.objects[i])bOk=true;}
if(!bOk)
{this.objects[i].mouseOn=false;f=this.finalizeMouseCoords(stack[i],m);ret=this.objects[i].dispatchEvent("mouseout",{target:this.objects[i],x:f.x,y:f.y});if(ret===false)break;}}}};this.checkMouseDown=function(event)
{var m=Utils.getMouseCoord(event,this.canvas);var stack=this.getObjectsStackByCoord(this.prepareMouseCoord(m.x),this.prepareMouseCoord(m.y),this.pixelMouseDownEvent);var ret,f;if(stack.length>0)
{stack=this.sortStack(stack);for(var i=0;i<stack.length;i++)
{f=this.finalizeMouseCoords(stack[i],m);ret=stack[i].dispatchEvent("mousedown",{target:stack[i],x:f.x,y:f.y});if(ret===false)return;}}};this.checkMouseUp=function(event)
{var m=Utils.getMouseCoord(event,this.canvas);var stack=this.getObjectsStackByCoord(this.prepareMouseCoord(m.x),this.prepareMouseCoord(m.y),this.pixelMouseUpEvent,true);var ret,f;if(stack.length>0)
{stack=this.sortStack(stack);for(var i=0;i<stack.length;i++)
{f=this.finalizeMouseCoords(stack[i],m);ret=stack[i].dispatchEvent("mouseup",{target:stack[i],x:f.x,y:f.y});if(ret===false)return;}}};this.clear=function()
{for(var i=0;i<this.objects.length;i++)
{this.objects[i].dispatchEvent("remove",{target:this.objects[i]});}
this.objects=[];this.tweens=[];this.timers=[];this.eventsListeners=[];this.objectsCounter=0;};this.hitTest=function(obj1,obj2)
{if(obj1.rotation==0&&obj2.rotation==0)
{var cX1=obj1.getX()-obj1.getWidth()/2;var cY1=obj1.getY()-obj1.getHeight()/2;var cX2=obj2.getX()-obj2.getWidth()/2;var cY2=obj2.getY()-obj2.getHeight()/2;var top=Math.max(cY1,cY2);var left=Math.max(cX1,cX2);var right=Math.min(cX1+obj1.getWidth(),cX2+obj2.getWidth());var bottom=Math.min(cY1+obj1.getHeight(),cY2+obj2.getHeight());var width=right-left;var height=bottom-top;if(width>0&&height>0)return true;else return false;}
else
{var r1=new Rectangle(obj1.getX(),obj1.getY(),obj1.getWidth(),obj1.getHeight(),obj1.rotation);var r2=new Rectangle(obj2.getX(),obj2.getY(),obj2.getWidth(),obj2.getHeight(),obj2.rotation);return r1.hitTestRectangle(r2);}};this.drawRectangle=function(x,y,width,height,color,fill,opacity,ignoreViewport)
{var cns=this.canvas;if(typeof opacity!='undefined')cns.ctx.globalAlpha=opacity;else cns.ctx.globalAlpha=1;cns.ctx.fillStyle=color;cns.ctx.strokeStyle=color;if(!ignoreViewport)
{x-=this.viewport.x;y-=this.viewport.y;}
x=x*Utils.globalScale*Utils.globalPixelScale;y=y*Utils.globalScale*Utils.globalPixelScale;width=width*Utils.globalScale*Utils.globalPixelScale;height=height*Utils.globalScale*Utils.globalPixelScale;if(fill)cns.ctx.fillRect(x-width/2,y-height/2,width,height);else cns.ctx.strokeRect(x-width/2,y-height/2,width,height);};this.drawCircle=function(x,y,radius,width,color,opacity,ignoreViewport)
{this.drawArc(x,y,radius,0,Math.PI*2,false,width,color,opacity,ignoreViewport);};this.drawArc=function(x,y,radius,startAngle,endAngle,anticlockwise,width,color,opacity,ignoreViewport)
{var cns=this.canvas;var oldLW=cns.ctx.lineWidth;if(typeof color=="undefined")color="#000"
cns.ctx.strokeStyle=color;if(typeof width=="undefined")width=1;cns.ctx.lineWidth=width*Utils.globalScale*Utils.globalPixelScale;if(typeof opacity=="undefined")opacity=1;cns.ctx.globalAlpha=opacity;if(!ignoreViewport)
{x-=this.viewport.x;y-=this.viewport.y;}
x=x*Utils.globalScale*Utils.globalPixelScale;y=y*Utils.globalScale*Utils.globalPixelScale;radius=radius*Utils.globalScale*Utils.globalPixelScale;cns.ctx.beginPath();cns.ctx.arc(x,y,radius,startAngle,endAngle,anticlockwise);cns.ctx.stroke();cns.ctx.lineWidth=oldLW;};this.drawPolygon=function(points,width,color,opacity,ignoreViewport)
{if((typeof points!="object")||!(points instanceof Array)||points.length<2)return;for(var i=0;i<points.length-1;i++)
{this.drawLine(points[i].x,points[i].y,points[i+1].x,points[i+1].y,width,color,opacity,ignoreViewport);}
this.drawLine(points[i].x,points[i].y,points[0].x,points[0].y,width,color,opacity,ignoreViewport);}
this.drawLine=function(x1,y1,x2,y2,width,color,opacity,ignoreViewport)
{var cns=this.canvas;var oldLW=cns.ctx.lineWidth;if(color)cns.ctx.strokeStyle=color;else cns.ctx.strokeStyle='#000';if(width)cns.ctx.lineWidth=width*Utils.globalScale*Utils.globalPixelScale;else cns.ctx.lineWidth=1*Utils.globalScale*Utils.globalPixelScale;if(opacity)cns.ctx.globalAlpha=opacity;else cns.ctx.globalAlpha=1;if(!ignoreViewport)
{x1-=this.viewport.x;y1-=this.viewport.y;x2-=this.viewport.x;y2-=this.viewport.y;}
x1=x1*Utils.globalScale*Utils.globalPixelScale;y1=y1*Utils.globalScale*Utils.globalPixelScale;x2=x2*Utils.globalScale*Utils.globalPixelScale;y2=y2*Utils.globalScale*Utils.globalPixelScale;cns.ctx.beginPath();cns.ctx.moveTo(x1,y1);cns.ctx.lineTo(x2,y2);cns.ctx.closePath();cns.ctx.stroke();cns.ctx.lineWidth=oldLW;};this.start=function()
{if(this.started)return;this.started=true;clearFPS();render();}
this.forceRender=function()
{if(this.started)render();}
this.stop=function()
{this.started=false;}
function clearFPS()
{self.lastFPS=self.fps;self.fps=0;if(self.started)self.tmFPS=setTimeout(clearFPS,1000);}
this.setTextStyle=function(font,size,style,color,borderColor,canvas)
{var cns=(canvas?canvas:this.canvas);cns.ctx.fillStyle=color;cns.ctx.strokeStyle=borderColor;var s="";if(style)s+=style+" ";if(size)s+=Math.floor(size*Utils.globalScale*Utils.globalPixelScale)+"px ";if(font)s+=font;cns.ctx.font=s;}
this.drawText=function(text,x,y,opacity,ignoreViewport,alignCenter,canvas)
{var cns=(canvas?canvas:this.canvas);if(typeof opacity=="undefined")cns.ctx.globalAlpha=1;else cns.ctx.globalAlpha=opacity;if(!ignoreViewport)
{x-=this.viewport.x;y-=this.viewport.y;}
x=x*Utils.globalScale*Utils.globalPixelScale;y=y*Utils.globalScale*Utils.globalPixelScale;if(alignCenter)x=x-this.getTextWidth(text)/2;cns.ctx.fillText(text,x,y);}
this.strokeText=function(text,x,y,opacity,ignoreViewport,alignCenter,canvas)
{var cns=(canvas?canvas:this.canvas);if(typeof opacity=="undefined")cns.ctx.globalAlpha=1;else cns.ctx.globalAlpha=opacity;if(!ignoreViewport)
{x-=this.viewport.x;y-=this.viewport.y;}
x=x*Utils.globalScale*Utils.globalPixelScale;y=y*Utils.globalScale*Utils.globalPixelScale;if(alignCenter)x=x-this.getTextWidth(text)/2;cns.ctx.strokeText(text,x,y);}
this.getTextWidth=function(str,canvas)
{var cns=(canvas?canvas:this.canvas);return cns.ctx.measureText(str).width;}
this.renderObject=function(cns,obj)
{var canvasMod=false;var ow=obj.width*Utils.globalScale;var oh=obj.height*Utils.globalScale;var ox=obj.getX()*Utils.globalPixelScale-Math.floor(ow/2);var oy=obj.getY()*Utils.globalPixelScale-Math.floor(oh/2);if(!obj.ignoreViewport)
{ox-=this.viewport.x*Utils.globalPixelScale*Utils.globalScale;oy-=this.viewport.y*Utils.globalPixelScale*Utils.globalScale;}
var or=obj.rotation;var scX=obj.scaleX*Utils.globalPixelScale;var scY=obj.scaleY*Utils.globalPixelScale;if(or!=0||scX!=1||scY!=1)
{canvasMod=true;cns.ctx.save();cns.ctx.translate(ox+Math.floor(ow/2),oy+Math.floor(oh/2));cns.ctx.rotate(or);cns.ctx.scale(scX,scY);ox=-Math.floor(ow/2);oy=-Math.floor(oh/2);}
cns.ctx.globalAlpha=obj.opacity;if(this.ceilSizes)
{ow=Math.ceil(ow);oh=Math.ceil(oh);}
if(obj.fillColor)
{cns.ctx.fillStyle=obj.fillColor;cns.ctx.strokeStyle=obj.fillColor;cns.ctx.fillRect(ox,oy,ow,oh);}
if(obj.bitmap)
{var iw=obj.bitmap.width;var ih=obj.bitmap.height;var fx=obj.currentLayer*ow+obj.offset.left*Utils.globalScale;var fy=obj.currentFrame*oh+obj.offset.top*Utils.globalScale;if(fx<iw&&fy<ih)
{var fw=ow;if(fx+fw>iw)fw=iw-fx;var fh=oh;if(fy+fh>ih)fh=ih-fy;var masked=false;if(obj.mask&&obj.bitmap)
{this.buffer.ctx.save();this.buffer.ctx.clearRect(0,0,fw,fh);this.buffer.ctx.drawImage(obj.bitmap,fx,fy,fw,fh,0,0,fw,fh);this.buffer.ctx.globalCompositeOperation="destination-in";this.buffer.ctx.drawImage(obj.mask,0,0);fx=0;fy=0;masked=true;}
try
{cns.ctx.drawImage(masked?this.buffer:obj.bitmap,~~fx,~~fy,~~fw,~~fh,~~ox,~~oy,~~ow,~~oh);}
catch(e){}
if(masked)this.buffer.ctx.restore();}}
if(canvasMod)cns.ctx.restore();obj.dispatchEvent("render",{target:obj,canvas:cns});}
this.clearObjectAABB=function(cns,obj)
{var w=obj.history.AABB[1].x-obj.history.AABB[0].x;var h=obj.history.AABB[1].y-obj.history.AABB[0].y;if(!this.fillColor)cns.ctx.clearRect((obj.history.AABB[0].x-this.viewport.x)*Utils.globalPixelScale,(obj.history.AABB[0].y-this.viewport.y)*Utils.globalPixelScale,w*Utils.globalPixelScale,h*Utils.globalPixelScale);else
{cns.ctx.fillStyle=this.fillColor;cns.ctx.fillRect((obj.history.AABB[0].x-this.viewport.x)*Utils.globalPixelScale,(obj.history.AABB[0].y-this.viewport.y)*Utils.globalPixelScale,w*Utils.globalPixelScale,h*Utils.globalPixelScale);}};this.addPartialDraw=function(partialDraw,obj)
{partialDraw.push(obj);obj.history.drawed=true;obj.history.changed=true;for(var i=0;i<this.objects.length;i++)
{if(!this.objects[i].history.changed&&this.objects[i].visible&&!this.objects[i]['static'])
{var top=Math.max(obj.history.AABB[0].y,this.objects[i].history.AABB[0].y);var left=Math.max(obj.history.AABB[0].x,this.objects[i].history.AABB[0].x);var right=Math.min(obj.history.AABB[1].x,this.objects[i].history.AABB[1].x);var bottom=Math.min(obj.history.AABB[1].y,this.objects[i].history.AABB[1].y);var width=right-left;var height=bottom-top;if(width>0&&height>0)this.addPartialDraw(partialDraw,this.objects[i]);}}
return partialDraw;};this.drawScenePartial=function(cns)
{var partialDraw=[];var rect,obj;if(!cns.ctx)cns.ctx=cns.getContext("2d");for(var i=0;i<this.objects.length;i++)
{this.objects[i].nextFrame();}
for(i=0;i<this.objects.length;i++)
{obj=this.objects[i];if(obj.visible&&!obj['static'])
{if(obj.destroy||obj.drawAlways||!obj.history.drawed||obj.currentFrame!=obj.history.frame||obj.getX()!=obj.history.x||obj.getY()!=obj.history.y||obj.rotation!=obj.history.rotation)
{partialDraw=this.addPartialDraw(partialDraw,obj);}}}
partialDraw=this.sortStack(partialDraw,true);var w,h;for(i=0;i<partialDraw.length;i++)
{this.clearObjectAABB(cns,partialDraw[i]);}
for(i=0;i<partialDraw.length;i++)
{obj=partialDraw[i];if(obj.destroy)
{this.removeChild(obj);}
else
{this.renderObject(cns,obj);obj.updateHistory();}}}
this.drawScene=function(cns,drawStatic)
{var obj,ok;if(!cns.ctx)cns.ctx=cns.getContext("2d");if(!this.fillColor)
{if(!this.clearLock)this.clearScreen(cns);}
else
{cns.ctx.fillStyle=this.fillColor;cns.ctx.fillRect(0,0,this.screenWidth*Utils.globalScale*Utils.globalPixelScale,this.screenHeight*Utils.globalScale*Utils.globalPixelScale);}
for(var i=0;i<this.objects.length;i++)
{obj=this.objects[i];ok=false;if(!drawStatic&&!obj['static'])ok=true;if(drawStatic&&obj['static'])ok=true;if(ok)
{if(obj.destroy)
{this.removeChild(obj);i--;}
else
{obj.nextFrame();if(obj.visible)this.renderObject(cns,obj);}}}};this.tweens=[];this.createTween=function(obj,prop,start,end,duration,ease)
{var t=new Tween(obj,prop,start,end,duration,ease);self.tweens.push(t);return t;}
this.removeTween=function(t)
{var id=null;if(isNaN(t))
{for(var i=0;i<self.tweens.length;i++)if(self.tweens[i]===t)
{id=i;break;}}
else id=t;self.tweens[id].pause();self.tweens.splice(id,1);return id;}
this.clearObjectTweens=function(obj)
{for(var i=0;i<self.tweens.length;i++)if(self.tweens[i].obj===obj)
{i=self.removeTween(i);}}
this.updateTweens=function()
{for(var i=0;i<self.tweens.length;i++)
{if(self.tweens[i].tick())
{i=self.removeTween(i);}}}
this.timers=[];this.setTimeout=function(callback,timeout)
{var t=new StageTimer(callback,timeout);this.timers.push(t);return t;};this.clearTimeout=function(t)
{this.timers=Utils.removeFromArray(this.timers,t);};this.setInterval=function(callback,timeout)
{var t=new StageTimer(callback,timeout,true);this.timers.push(t);return t;};this.clearInterval=function(t)
{this.clearTimeout(t);};this.updateTimers=function()
{for(var i=0;i<this.timers.length;i++)
{if(this.timers[i].update())
{this.clearTimeout(this.timers[i]);i--;}}};function render()
{clearTimeout(self.tmMain);var tm_start=new Date().getTime();self.updateTweens();self.updateTimers();self.dispatchEvent("pretick");if(self.partialUpdate)self.drawScenePartial(self.canvas);else self.drawScene(self.canvas,false);if(self.showFPS)
{self.setTextStyle("sans-serif",10,"bold","#fff","#000");self.drawText("FPS: "+self.lastFPS,2,10,1,true);}
self.dispatchEvent("posttick");var d=new Date().getTime()-tm_start;d=self.delay-d-1;if(d<1)d=1;self.fps++;if(self.started)self.tmMain=setTimeout(render,d);};this.box2dSync=function(world)
{var p;for(b=world.m_bodyList;b;b=b.m_next)
{if(b.sprite)
{b.sprite.rotation=b.GetRotation();p=b.GetPosition();b.sprite.x=p.x;b.sprite.y=p.y;b.sprite.dispatchEvent("box2dsync",{target:b.sprite});}}}
this.processTouchEvent=function(touches,controller)
{for(var i=0;i<touches.length;i++)
{var e={clientX:touches[i].clientX,clientY:touches[i].clientY};self[controller](e);}}
if("ontouchstart"in this.canvas)
{this.canvas.ontouchstart=function(event)
{this.renderController.processTouchEvent(event.touches,"checkMouseDown");this.renderController.processTouchEvent(event.touches,"checkClick");};this.canvas.ontouchmove=function(event)
{this.renderController.processTouchEvent(event.touches,"checkMouseMove");};this.canvas.ontouchend=function(event)
{this.renderController.processTouchEvent(event.changedTouches,"checkMouseUp");};}
else
{this.canvas.onclick=function(event){this.renderController.checkClick(event);};this.canvas.onmousemove=function(event){this.renderController.checkMouseMove(event);};this.canvas.onmousedown=function(event){if(event.button==0)this.renderController.checkMouseDown(event);};this.canvas.onmouseup=function(event){if(event.button==0)this.renderController.checkMouseUp(event);};this.canvas.oncontextmenu=function(event){this.renderController.checkContextMenu(event);};}
this.onpretick=null;this.onposttick=null;this.eventsListeners=[];this.addEventListener=function(type,callback)
{EventsManager.addEvent(this,type,callback);}
this.removeEventListener=function(type,callback)
{EventsManager.removeEvent(this,type,callback);}
this.dispatchEvent=function(type,params)
{return EventsManager.dispatchEvent(this,type,params);}}
function Vector(x,y)
{if(typeof(x)=='undefined')x=0;this.x=x;if(typeof(y)=='undefined')y=0;this.y=y;this.clone=function(){return new Vector(this.x,this.y);}
this.add=function(p){this.x+=p.x;this.y+=p.y;}
this.subtract=function(p){this.x-=p.x;this.y-=p.y;}
this.rotate=function(angle,offset)
{if(typeof(offset)=='undefined')offset=new Vector(0,0);var r=this.clone();r.subtract(offset);r.x=this.x*Math.cos(angle)+this.y*Math.sin(angle);r.y=this.x*-Math.sin(angle)+this.y*Math.cos(angle);r.add(offset);this.x=r.x;this.y=r.y;}
this.normalize=function(angle,offset)
{if(typeof(offset)=='undefined')offset=new Vector(0,0);this.subtract(offset);this.rotate(-angle);}
this.getLength=function()
{return Math.sqrt(this.x*this.x+this.y*this.y);}}
var Rectangle=function(x,y,w,h,angle)
{this.center=new Vector(x,y);this.width=w;this.height=h;this.angle=angle;this.vertices=[];this.AABB=[];this.clone=function()
{return new Rectangle(this.center.x,this.center.y,this.width,this.height,this.angle);}
this.refreshVertices=function()
{var w=this.width/2;var h=this.height/2;this.vertices=[];this.vertices.push(new Vector(-w,h));this.vertices.push(new Vector(w,h));this.vertices.push(new Vector(w,-h));this.vertices.push(new Vector(-w,-h));this.AABB=[this.center.clone(),this.center.clone()];for(var i=0;i<4;i++)
{this.vertices[i].rotate(-this.angle,this.center);if(this.vertices[i].x<this.AABB[0].x)this.AABB[0].x=this.vertices[i].x;if(this.vertices[i].x>this.AABB[1].x)this.AABB[1].x=this.vertices[i].x;if(this.vertices[i].y<this.AABB[0].y)this.AABB[0].y=this.vertices[i].y;if(this.vertices[i].y>this.AABB[1].y)this.AABB[1].y=this.vertices[i].y;}}
this.move=function(x,y)
{this.center.add(new Vector(x,y));this.refreshVertices();}
this.rotate=function(angle)
{this.angle+=angle;this.refreshVertices();}
this.hitTestPoint=function(point)
{var p=point.clone();p.normalize(-this.angle,this.center);return((Math.abs(p.x)<=(this.width/2))&&(Math.abs(p.y)<=(this.height/2)));}
this.hitTestRectangle=function(rect)
{var r1=this.clone();var r2=rect.clone();var len,len1,len2;r1.move(-this.center.x,-this.center.y);r2.move(-this.center.x,-this.center.y);r2.center.rotate(this.angle);r1.rotate(-this.angle);r2.rotate(-this.angle);len=Math.max(r1.AABB[0].x,r1.AABB[1].x,r2.AABB[0].x,r2.AABB[1].x)-Math.min(r1.AABB[0].x,r1.AABB[1].x,r2.AABB[0].x,r2.AABB[1].x);len1=r1.AABB[1].x-r1.AABB[0].x;len2=r2.AABB[1].x-r2.AABB[0].x;if(len>len1+len2)return false;len=Math.max(r1.AABB[0].y,r1.AABB[1].y,r2.AABB[0].y,r2.AABB[1].y)-Math.min(r1.AABB[0].y,r1.AABB[1].y,r2.AABB[0].y,r2.AABB[1].y);len1=r1.AABB[1].y-r1.AABB[0].y;len2=r2.AABB[1].y-r2.AABB[0].y;if(len>len1+len2)return false;r1.move(-r2.center.x,-r2.center.y);r2.move(-r2.center.x,-r2.center.y);r1.center.rotate(r2.angle);r1.refreshVertices();r1.rotate(-r2.angle);r2.rotate(-r2.angle);len=Math.max(r1.AABB[0].x,r1.AABB[1].x,r2.AABB[0].x,r2.AABB[1].x)-Math.min(r1.AABB[0].x,r1.AABB[1].x,r2.AABB[0].x,r2.AABB[1].x);len1=r1.AABB[1].x-r1.AABB[0].x;len2=r2.AABB[1].x-r2.AABB[0].x;if(len>len1+len2)return false;len=Math.max(r1.AABB[0].y,r1.AABB[1].y,r2.AABB[0].y,r2.AABB[1].y)-Math.min(r1.AABB[0].y,r1.AABB[1].y,r2.AABB[0].y,r2.AABB[1].y);len1=r1.AABB[1].y-r1.AABB[0].y;len2=r2.AABB[1].y-r2.AABB[0].y;if(len>len1+len2)return false;return true;}
this.refreshVertices();}
var Asset=function(name,src,w,h,f,l)
{this.name=name+'';this.src=src+'';this.width=w;this.height=h;this.frames=f;this.layers=l;this.bitmap=null;this.object=null;this.ready=(this.width&&this.height);this.detectSize=function()
{if(!this.bitmap)return false;try
{if(isNaN(this.width))
{this.width=this.bitmap.width?parseInt(this.bitmap.width):0;}
if(isNaN(this.height))
{this.height=this.bitmap.height?parseInt(this.bitmap.height):0;}}
catch(e){if(CRENDER_DEBUG)console.log(e);}
return(!isNaN(this.width)&&!isNaN(this.height));}
this.normalize=function(scale)
{if(this.ready)return;if(!this.detectSize())return;if(isNaN(this.frames)||this.frames<1)this.frames=1;if(isNaN(this.layers)||this.layers<1)this.layers=1;this.width=Math.ceil((this.width/this.layers)/scale);this.height=Math.ceil((this.height/this.frames)/scale);this.ready=true;}}
var AssetsLibrary=function(path,scale,assets)
{var self=this;this.path='images';this.scale=1;this.items={};this.bitmaps={};this.loaded=false;this.onload=null;this.onloadprogress=null;this.spriteClass=Sprite;this.init=function(path,scale)
{if(typeof path!='undefined')
{this.path=path+'';}
if(typeof scale!='undefined')
{this.scale=parseFloat(scale);if(isNaN(this.scale))this.scale=1;}}
this.addAssets=function(data)
{if(typeof data=='undefined')return;if(typeof data!='object')return;for(var i=0;i<data.length;i++)
{var item=data[i];item.noscale=(typeof item.noscale=='undefined')?false:item.noscale;if(!item.noscale)item.src='%SCALE%/'+item.src;this.addAsset(item.src,item.name,item.width,item.height,item.frames,item.layers);}}
this.addAsset=function(src,name,w,h,f,l)
{function src2name(src)
{var name=src.split('/');name=name.pop();name=name.split('.');name=name.shift()+'';return name;}
src=src.replace('%SCALE%','%PATH%/'+this.scale);src=src.replace('%PATH%',this.path);if(typeof name=='undefined')name=src2name(src);var asset=new Asset(name,src,w,h,f,l);this.items[name]=asset;return asset;}
this.addObject=function(obj)
{var asset=this.addAsset('%SCALE%/'+obj.image,obj.name,obj.width*this.scale,obj.height*this.scale,obj.frames,obj.layers);if(asset)asset.object=obj;return asset;}
this.load=function(onload,onloadprogress)
{this.onload=onload;this.onloadprogress=onloadprogress;var preloader=new ImagesPreloader();var data=[];for(var n in this.items)data.push(this.items[n]);preloader.load(data,self.onLoadHandler,self.onLoadProgressHandler);}
this.onLoadProgressHandler=function(val)
{if(typeof self.onloadprogress=='function')
{self.onloadprogress(val);}}
this.onLoadHandler=function(data)
{self.loaded=true;for(var n in data)
{var bmp=data[n];var asset=self.items[n];asset.bitmap=bmp;asset.normalize(self.scale);}
if(typeof self.onload=='function')
{self.onload(self.items);}}
this.getAsset=function(name,checkLoad)
{var asset=null;if((typeof this.items[name]!='undefined')&&(this.items[name].bitmap))
{checkLoad=(typeof checkLoad=='undefined')?true:checkLoad;asset=(!checkLoad||this.items[name].ready)?this.items[name]:null;}
if(!asset)
{throw new Error('Trying to get undefined asset "'+name+'"');}
return asset;}
this.getSprite=function(name,params)
{var mc=null;try
{var asset=this.getAsset(name,true);mc=new this.spriteClass(asset.bitmap,asset.width,asset.height,asset.frames,asset.layers);}
catch(e)
{mc=new this.spriteClass(null,1,1,1,1);}
if(typeof params=='object')
{for(var prop in params)mc[prop]=params[prop];}
return mc;}
this.getBitmap=function(name)
{try
{var asset=this.getAsset(name,true);return asset.bitmap;}
catch(e)
{return null;}}
this.init(path,scale);this.addAssets(assets);}
if(typeof console=='undefined')
{console={log:function(){}}};function SimpleText(font,width,height)
{this.ALIGN_LEFT=0;this.ALIGN_RIGHT=1;this.ALIGN_CENTER=2;this.font=font;this.x=0;this.y=0;this.width=width;this.height=height;this.align=this.ALIGN_LEFT;this.rotation=0;this.charSpacing=0;this.static=false;this.charMap=['0','1','2','3','4','5','6','7','8','9'];this.sprites=[];this.text="";this.manageSprites=function(text)
{var i,char;var len=text.length;var sp_len=this.sprites.length;if(sp_len<len)
{for(i=0;i<len-sp_len;i++)
{char=new Sprite(this.font,this.width,this.height,this.charMap.length);this.sprites.push(char);stage.addChild(char);}}
if(sp_len>len)
{for(i=0;i<sp_len-len;i++)stage.removeChild(this.sprites[i]);this.sprites.splice(0,sp_len-len);}}
this.write=function(text)
{var curX,curY,p,p2,n;text=text+"";this.text=text;this.manageSprites(text);curX=this.x;curY=this.y;if(this.align==this.ALIGN_CENTER)curX=this.x-(text.length-1)/2*(this.width+this.charSpacing);if(this.align==this.ALIGN_RIGHT)curX=this.x-(text.length-1)*(this.width+this.charSpacing);p=new Vector(curX-this.x,0);p.rotate(-this.rotation);curX=p.x+this.x;curY=p.y+this.y;p=new Vector(0,0);for(var i=0;i<text.length;i++)
{this.sprites[i].visible=true;n=this.charMap.indexOf(text.substr(i,1));if(n<0)this.sprites[i].visible=false;else
{this.sprites[i].gotoAndStop(n);p2=p.clone();p2.rotate(-this.rotation);this.sprites[i].x=p2.x+curX;this.sprites[i].y=p2.y+curY;this.sprites[i].rotation=this.rotation;this.sprites[i].static=this.static;p.x+=this.width+this.charSpacing;}}}};function AudioPlayer()
{var self=this;this.disabled=false;this.basePath="";this.mp3Support=true;this.delayPlay=false;this.audioWrapper=null;this.locked=false;this.busy=false;this.startPlayTime=0;this.onend=null;this.createNewAudio=function()
{return document.createElement('audio');};this.init=function(path)
{this.basePath=path?path:"";this.delayPlay=("ontouchstart"in window);this.audioWrapper=this.createNewAudio();if(this.audioWrapper.canPlayType)this.mp3Support=this.audioWrapper.canPlayType('audio/mpeg')!="";else this.disabled=true;return!this.disabled;};this.play=function(file,loop)
{if(this.disabled)return false;var url=this.basePath+"/"+file+(this.mp3Support?".mp3":".ogg");this.stop();this.audioWrapper=this.createNewAudio();this.audioWrapper.src=url;this.audioWrapper.type=(this.mp3Support?"audio/mpeg":"audio/ogg");this.audioWrapper.loop=false;this.audioWrapper.doLoop=(loop?true:false);this.audioWrapper.preload="auto";this.audioWrapper.load();this.busy=true;this.audioWrapper.addEventListener("ended",this.controlPlay,false);if(this.delayPlay)this.audioWrapper.addEventListener("canplay",function(e){e.currentTarget.play();});else this.audioWrapper.play();this.startPlayTime=new Date().getTime();};this.stop=function()
{this.busy=false;try
{this.audioWrapper.pause();this.audioWrapper.currentTime=0.0;this.audioWrapper=null;}
catch(e){};};this.controlPlay=function()
{if(self.audioWrapper.doLoop)
{self.audioWrapper.pause();self.audioWrapper.currentTime=0.0;self.audioWrapper.play();}
else
{self.busy=false;if(typeof self.onend=="function")self.onend();}}}
function AudioMixer(path,channelsCount)
{this.channels=[];this.init=function(path,channelsCount)
{this.path=path;this.channels=[];for(var i=0;i<channelsCount;i++)
{this.channels[i]=new AudioPlayer(path);this.channels[i].init(path);}};this.play=function(file,loop,soft,channelID)
{var cID=-1;if(typeof channelID=="number")cID=channelID;else cID=this.getFreeChannel(soft);if(cID>=0&&cID<this.channels.length)
{this.channels[cID].stop();this.channels[cID].play(file,loop);}
return this.channels[cID];};this.stop=function(cID)
{if(cID>=0&&cID<this.channels.length)this.channels[cID].stop();};this.getFreeChannel=function(soft)
{var cID=-1;var freeChannels=[];var maxID=-1;var max=-1;var t=0;for(var i=0;i<this.channels.length;i++)
{if(!this.channels[i].locked)
{if(!this.channels[i].busy)freeChannels.push(i);else
{t=new Date().getTime();t-=this.channels[i].startPlayTime;if(t>max)
{max=t;maxID=i;}}}}
if(freeChannels.length==0)
{if(!soft&&max>=0)cID=max;}
else cID=freeChannels[0];return cID;};this.init(path,channelsCount);};var stage;var world;var mc;var fps=18;var bitmaps;var GET;var data=[];var LANDSCAPE_MODE=true;var STATE_LOAD=0;var STATE_SPLASH=1;var STATE_COVER=2;var STATE_MENU=3;var STATE_ABOUT=4;var STATE_GAME_START=5;var STATE_GAME_STAKES=6;var STATE_GAME_SPIN=7;var STATE_GAME_RESULTS=8;var STATE_GAME_LOSE=9;var gameState=STATE_LOAD;var gameScore;var mixer;window.onload=function()
{GET=Utils.parseGet();Utils.addMobileListeners(LANDSCAPE_MODE);Utils.mobileCorrectPixelRatio();Utils.addFitLayoutListeners();setTimeout(startLoad,600);};function startLoad()
{var resolution=Utils.getMobileScreenResolution(LANDSCAPE_MODE);if(GET["debug"]==1)resolution=Utils.getScaleScreenResolution(1,LANDSCAPE_MODE);Utils.globalScale=resolution.scale;Utils.createLayout(document.getElementById("main_container"),resolution);Utils.addEventListener("fitlayout",function()
{manageBackground();if(stage)
{stage.drawScene(document.getElementById("screen"));buildBackground();}});Utils.addEventListener("lockscreen",function(){if(stage&&stage.started)stage.stop();});Utils.addEventListener("unlockscreen",function(){if(stage&&!stage.started)stage.start();});Utils.mobileHideAddressBar();if(GET["debug"]!=1)Utils.checkOrientation(LANDSCAPE_MODE);var path=Utils.imagesRoot+"/"+Utils.globalScale+"/";var preloader=new ImagesPreloader();data.push({name:"about",src:path+"about.jpg"});data.push({name:"cover",src:path+"cover.jpg"});data.push({name:"splash",src:path+"splash.jpg"});data.push({name:"menu",src:path+"menu.jpg"});data.push({name:"button_about",src:path+"button_about.png"});data.push({name:"button_more_games",src:path+"button_more_games.png"});data.push({name:"button_start_game",src:path+"button_start_game.png"});data.push({name:"fill",src:path+"fill.png"});data.push({name:"text1",src:path+"text1.png"});data.push({name:"game_back_big",src:path+"game_back_big.png"});data.push({name:"game_back_small",src:path+"game_back_small.png"});data.push({name:"font1",src:path+"font1.png"});data.push({name:"font2",src:path+"font2.png"});data.push({name:"font3",src:path+"font3.png"});data.push({name:"wheel2",src:path+"wheel2.png"});data.push({name:"wheel_back",src:path+"wheel_back.png"});data.push({name:"win1",src:path+"win1.png"});data.push({name:"win3",src:path+"win3.png"});data.push({name:"win2",src:path+"win2.png"});data.push({name:"win0",src:path+"win0.png"});data.push({name:"wheel",src:path+"wheel.png"});data.push({name:"ball",src:path+"ball.png"});data.push({name:"ball2",src:path+"ball2.png"});data.push({name:"result_token",src:path+"result_token.png"});data.push({name:"stake_token5",src:path+"stake_token5.png"});data.push({name:"stake_token4",src:path+"stake_token4.png"});data.push({name:"stake_token3",src:path+"stake_token3.png"});data.push({name:"stake_token2",src:path+"stake_token2.png"});data.push({name:"stake_token1",src:path+"stake_token1.png"});data.push({name:"stake5",src:path+"stake5.png"});data.push({name:"stake4",src:path+"stake4.png"});data.push({name:"stake3",src:path+"stake3.png"});data.push({name:"stake2",src:path+"stake2.png"});data.push({name:"stake1",src:path+"stake1.png"});data.push({name:"stake_unmark",src:path+"stake_unmark.png"});data.push({name:"button_spin",src:path+"button_spin.png"});data.push({name:"button_repeat",src:path+"button_repeat.png"});data.push({name:"button_clear",src:path+"button_clear.png"});data.push({name:"button_play_again",src:path+"button_play_again.png"});data.push({name:"button_clear_s",src:path+"button_clear_s.png"});data.push({name:"button_repeat_s",src:path+"button_repeat_s.png"});data.push({name:"button_spin_s",src:path+"button_spin_s.png"});data.push({name:"game_back_small",src:path+"game_back_small.png"});data.push({name:"result_token_s",src:path+"result_token_s.png"});data.push({name:"stake_token1_s",src:path+"stake_token1_s.png"});data.push({name:"stake_token2_s",src:path+"stake_token2_s.png"});data.push({name:"stake_token3_s",src:path+"stake_token3_s.png"});data.push({name:"stake_token4_s",src:path+"stake_token4_s.png"});data.push({name:"stake_token5_s",src:path+"stake_token5_s.png"});data.push({name:"stake_unmark_s",src:path+"stake_unmark_s.png"});data.push({name:"stake1_s",src:path+"stake1_s.png"});data.push({name:"stake2_s",src:path+"stake2_s.png"});data.push({name:"stake3_s",src:path+"stake3_s.png"});data.push({name:"stake4_s",src:path+"stake4_s.png"});data.push({name:"stake5_s",src:path+"stake5_s.png"});data.push({name:"win0_s",src:path+"win0_s.png"});data.push({name:"win1_s",src:path+"win1_s.png"});data.push({name:"win2_s",src:path+"win2_s.png"});data.push({name:"win3_s",src:path+"win3_s.png"});data.push({name:"win_text",src:path+"win_text.png"});data.push({name:"lose_text",src:path+"lose_text.png"});data.push({name:"button_sound",src:path+"button_sound.png"});preloader.load(data,loadImagesEnd,Utils.showLoadProgress);}
function manageBackground()
{var c=Utils.globalScale*Utils.globalPixelScale;document.getElementById("screen_background_container").style.backgroundSize=window.innerWidth+"px "+Math.floor(320*c)+"px";}
function loadImagesEnd(data)
{document.getElementById('progress_container').style.display='none';document.getElementById('screen_container').style.display='block';document.getElementById('screen_background_container').style.display='block';bitmaps=data;mixer=new AudioMixer("sounds",1);if(GET["debug"]!=1)
{showSplash();}}
function playSound(file)
{if(!soundDisabled)
{var ok=true;if(Utils.touchScreen)
{if(SOUNDS_MODE=="disabled")ok=false;if(SOUNDS_MODE=="results"&&file!="win"&&file!="win2")ok=false;}
if(ok)
{mixer.play(file,false,false,0);}}}
var soundDisabled=false;function loadSettings()
{var v=Utils.getCookie("roulette_sound_disabled")*1;if(v==1)soundDisabled=true;else soundDisabled=false;}
function saveSettings()
{Utils.setCookie("roulette_sound_disabled",(soundDisabled?1:0));}
function changeSound()
{soundDisabled=!soundDisabled;saveSettings();setSound();}
function setSound()
{soundsButton.gotoAndStop(soundDisabled?1:0);}
function playSound(file)
{if(!soundDisabled)
{var ok=true;if(Utils.touchScreen)
{if(SOUNDS_MODE=="disabled")ok=false;if(SOUNDS_MODE=="results"&&file!="win"&&file!="win2")ok=false;}
if(ok)
{mixer.play(file,false,false,0);}}}
function showSplash()
{gameState=STATE_SPLASH;createScene();}
function showCover()
{gameState=STATE_COVER;createScene();}
function showMenu()
{gameState=STATE_MENU;createScene();}
function showAbout()
{gameState=STATE_ABOUT;createScene();}
function startGame()
{gameState=STATE_GAME_START;createScene();}
function createStage()
{if(stage)
{stage.destroy();stage.stop();}
stage=new Stage('screen',480,320,false);stage.delay=1000/fps;stage.onpretick=preTick;stage.onposttick=postTick;stage.ceilSizes=true;stage.showFPS=false;}
function setBackFill(img)
{document.getElementById("screen_background_container").style.background="url('images/"+Utils.globalScale+"/"+img+"')";document.getElementById("screen_background_container").style.backgroundRepeat="repeat-x";document.getElementById("screen_background_container").style.backgroundColor="#3db600";manageBackground();}
function showMoreGames()
{window.open(MORE_GAMES_URL);}
function createScene()
{createStage();if(gameState==STATE_SPLASH)
{document.getElementById("screen_background_container").style.background="#fee002";mc=new Sprite(bitmaps.splash,480,320);mc.x=240;mc.y=160;mc.static=true;stage.addChild(mc);stage.setTimeout(showCover,fps*3);}
if(gameState==STATE_COVER)
{setBackFill("fill.png");mc=new Sprite(bitmaps.cover,480,320);mc.x=240;mc.y=160;mc.static=true;stage.addChild(mc);mc.onclick=showMenu;mc=new Sprite(bitmaps.text1,119,25);mc.x=240;mc.y=300;mc.static=true;stage.addChild(mc);}
if(gameState==STATE_ABOUT)
{document.getElementById("screen_background_container").style.background="#fee002";mc=new Sprite(bitmaps.about,480,320);mc.x=240;mc.y=160;mc.static=true;mc.onclick=showMenu;stage.addChild(mc);}
if(gameState==STATE_MENU)
{setBackFill("fill.png");mc=new Sprite(bitmaps.menu,480,320);mc.x=240;mc.y=160;mc.static=true;stage.addChild(mc);mc=new Sprite(bitmaps.button_start_game,81,18);mc.x=100;mc.y=282;mc.static=true;mc.onclick=startGame;stage.addChild(mc);mc=new Sprite(bitmaps.button_about,44,18);mc.x=240;mc.y=282;mc.static=true;mc.onclick=showAbout;stage.addChild(mc);mc=new Sprite(bitmaps.button_more_games,91,18);mc.x=390;mc.y=282;mc.static=true;mc.onclick=showMoreGames;stage.addChild(mc);}
if(gameState==STATE_GAME_START)
{document.getElementById("screen_background_container").style.background="#175a13";if(Utils.globalScale>=2)createBigGameScene();else createSmallGameScene();startNewGame();}
buildBackground();stage.start();}
function createBigGameScene()
{mc=new Sprite(bitmaps.game_back_big,480,320);mc.x=240;mc.y=160;mc.static=true;stage.addChild(mc);stakesUnmarks=[];for(var i=0;i<5;i++)
{mc=new Sprite(bitmaps["stake"+(i+1)],33,32);mc.x=i*35+48;mc.y=276;mc.stakeID=i*1;mc.onclick=setCurrentStake;mc.static=true;stage.addChild(mc);var mc2=new Sprite(bitmaps.stake_unmark,33,32);mc2.x=mc.x;mc2.y=mc.y;stage.addChild(mc2);stakesUnmarks[i]=mc2;}
resultToken=new Sprite(bitmaps.result_token,27,25);resultToken.x=190;resultToken.y=200;stage.addChild(resultToken);wheel=new Sprite(bitmaps.wheel,125,125);wheel.x=98;wheel.y=114.5;wheel.onenterframe=doSpinWheel;stage.addChild(wheel);ball=new Sprite(bitmaps.ball,7,7);ball.x=180;ball.y=30;ball.visible=false;stage.addChild(ball);fundsText=new SimpleText(bitmaps.font1,10,12);fundsText.x=102;fundsText.y=245;paidText=new SimpleText(bitmaps.font1,10,12);paidText.x=217;paidText.y=245;mc=new Sprite(bitmaps.button_clear,56,18);mc.x=395;mc.y=244;mc.static=true;mc.onclick=function(){clearStakes(true);playSound("button");};stage.addChild(mc);mc=new Sprite(bitmaps.button_repeat,56,18);mc.x=362;mc.y=276;mc.static=true;mc.onclick=repeatStakes;stage.addChild(mc);mc=new Sprite(bitmaps.button_spin,46,18);mc.x=420;mc.y=276;mc.static=true;mc.onclick=spinWheel;stage.addChild(mc);mc=new Sprite(null,266,188);mc.x=340;mc.y=133;mc.onclick=setStake;stage.addChild(mc);boardSprite=mc;winMarks=[];mc=new Sprite(bitmaps.win0,34,47);mc.x=211;mc.y=102;mc.visible=false;stage.addChild(mc);winMarks[0]=mc;mc=new Sprite(bitmaps.win1,25,34);mc.x=254;mc.y=109;mc.visible=false;stage.addChild(mc);winMarks[1]=mc;mc=new Sprite(bitmaps.win1,25,34);mc.x=254;mc.y=109;mc.visible=false;stage.addChild(mc);winMarks[2]=mc;mc=new Sprite(bitmaps.win3,82,58);mc.x=340;mc.y=148;mc.visible=false;stage.addChild(mc);winMarks[3]=mc;mc=new Sprite(bitmaps.win2,44,57);mc.x=340;mc.y=200;mc.visible=false;stage.addChild(mc);winMarks[4]=mc;mc=new Sprite(bitmaps.win2,44,57);mc.x=340;mc.y=200;mc.visible=false;stage.addChild(mc);winMarks[5]=mc;mc=new Sprite(bitmaps.win2,44,57);mc.x=340;mc.y=200;mc.visible=false;stage.addChild(mc);winMarks[6]=mc;for(var i=0;i<winMarks.length;i++)stage.setZIndex(winMarks[i],1000);stage.setZIndex(resultToken,3000);mc=new Sprite(bitmaps.button_sound,60,58);mc.x=45;mc.y=218;mc.scaleX=mc.scaleY=0.5;stage.addChild(mc);mc.onclick=changeSound;soundsButton=mc;setSound();if(SOUNDS_MODE=="disabled")soundsButton.visible=false;mc=new Sprite(null,480,320);mc.x=240;mc.y=160;mc.onclick=function(){return false;};mc.visible=false;stage.addChild(mc);stage.setZIndex(mc,4000);lockScreen=mc;mc=new Sprite(bitmaps.button_play_again,62,32);mc.x=260;mc.y=274;mc.visible=false;mc.onclick=function(){playSound("button");startNewGame()};stage.addChild(mc);stage.setZIndex(mc,5000);playAgainButton=mc;startNewGame();}
function createSmallGameScene()
{document.body.style.background="#005a00";mc=new Sprite(bitmaps.game_back_small,480,320);mc.x=240;mc.y=160;mc.static=true;stage.addChild(mc);fundsText=new SimpleText(bitmaps.font2,12,14);fundsText.x=22;fundsText.y=224;paidText=new SimpleText(bitmaps.font2,12,14);paidText.x=22;paidText.y=178.5;stakesUnmarks=[];for(var i=0;i<5;i++)
{mc=new Sprite(bitmaps["stake"+(i+1)+"_s"],44,42);mc.x=i*46+24;mc.y=276;mc.stakeID=i*1;mc.onclick=setCurrentStake;mc.static=true;stage.addChild(mc);var mc2=new Sprite(bitmaps.stake_unmark,44,42);mc2.x=mc.x;mc2.y=mc.y;stage.addChild(mc2);stakesUnmarks[i]=mc2;}
resultToken=new Sprite(bitmaps.result_token_s,48,42);resultToken.x=26;resultToken.y=124;stage.addChild(resultToken);mc=new Sprite(bitmaps.button_clear_s,58,18);mc.x=28;mc.y=20;mc.static=true;mc.onclick=function(){clearStakes(true);playSound("button");};stage.addChild(mc);mc=new Sprite(bitmaps.button_repeat_s,116,36);mc.x=310;mc.y=276;mc.static=true;mc.onclick=repeatStakes;stage.addChild(mc);mc=new Sprite(bitmaps.button_spin_s,96,36);mc.x=426;mc.y=276;mc.static=true;mc.onclick=spinWheel;stage.addChild(mc);mc=new Sprite(null,410,220);mc.x=274;mc.y=131;mc.onclick=setStake;stage.addChild(mc);boardSprite=mc;winMarks=[];mc=new Sprite(bitmaps.win0_s,56,76);mc.x=75;mc.y=116;mc.visible=false;stage.addChild(mc);winMarks[0]=mc;mc=new Sprite(bitmaps.win1_s,40,54);mc.x=254;mc.y=109;mc.visible=false;stage.addChild(mc);winMarks[1]=mc;mc=new Sprite(bitmaps.win1_s,40,54);mc.x=254;mc.y=109;mc.visible=false;stage.addChild(mc);winMarks[2]=mc;mc=new Sprite(bitmaps.win3_s,128,56);mc.x=390;mc.y=171;mc.visible=false;stage.addChild(mc);winMarks[3]=mc;mc=new Sprite(bitmaps.win2_s,70,58);mc.x=200;mc.y=217;mc.visible=false;stage.addChild(mc);winMarks[4]=mc;mc=new Sprite(bitmaps.win2_s,70,58);mc.x=340;mc.y=217;mc.visible=false;stage.addChild(mc);winMarks[5]=mc;mc=new Sprite(bitmaps.win2_s,70,58);mc.x=340;mc.y=217;mc.visible=false;stage.addChild(mc);winMarks[6]=mc;for(var i=0;i<winMarks.length;i++)stage.setZIndex(winMarks[i],1000);stage.setZIndex(resultToken,3000);mc=new Sprite(bitmaps.button_sound,60,58);mc.x=22;mc.y=68;mc.scaleX=mc.scaleY=0.5;stage.addChild(mc);mc.onclick=changeSound;soundsButton=mc;setSound();if(SOUNDS_MODE=="disabled")soundsButton.visible=false;mc=new Sprite(null,480,320);mc.x=240;mc.y=160;mc.visible=false;mc.onclick=function(){return false;};stage.addChild(mc);stage.setZIndex(mc,4000);lockScreen=mc;mc=new Sprite(bitmaps.button_play_again,62,32);mc.x=240;mc.y=160;mc.visible=false;mc.scaleX=mc.scaleY=1.8;mc.onclick=function(){playSound("button");startNewGame()};stage.addChild(mc);stage.setZIndex(mc,5000);playAgainButton=mc;mc=new Sprite(bitmaps.wheel_back,321,320);mc.x=240;mc.y=160;mc.visible=false;mc.screen2=true;mc.static=true;stage.addChild(mc);wheel=new Sprite(bitmaps.wheel2,210,210);wheel.x=240;wheel.y=160;wheel.visible=false;wheel.screen2=true;wheel.onenterframe=doSpinWheel;stage.addChild(wheel);ball=new Sprite(bitmaps.ball2,11,11);ball.x=180;ball.y=30;ball.opacity=0;ball.screen2=true;stage.addChild(ball);startNewGame();}
function buildBackground()
{stage.drawScene(document.getElementById("screen_background"),true);}
var funds=0;var paid=0;var stakes=[];var stakesVals=[5,10,25,50,100];var wheelNumbers=[0,32,15,19,4,21,2,25,17,27,6,34,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26];var currentStake=5;var board;var fundsText;var paidText;var stakesUnmarks=[];var resultToken;var wheel;var ball;var playAgainButton;var boardSprite;var winMarks;var lockScreen;var soundsButton;var resultText;var resultSumText;function startNewGame()
{board=[];stakes=[];board[0]=[{id:3,color:0},{id:6,color:1},{id:9,color:0},{id:12,color:0},{id:15,color:1},{id:18,color:0},{id:21,color:0},{id:24,color:1},{id:27,color:0},{id:30,color:0},{id:33,color:1},{id:36,color:0}];board[1]=[{id:2,color:1},{id:5,color:0},{id:8,color:1},{id:11,color:1},{id:14,color:0},{id:17,color:1},{id:20,color:1},{id:23,color:0},{id:26,color:1},{id:29,color:1},{id:32,color:0},{id:35,color:1}];board[2]=[{id:1,color:0},{id:4,color:1},{id:7,color:0},{id:10,color:1},{id:13,color:1},{id:16,color:0},{id:19,color:0},{id:22,color:1},{id:25,color:0},{id:28,color:1},{id:31,color:1},{id:34,color:0}];funds=START_FUNDS;setCurrentStake({target:{stakeID:0}});unmarkResults();lockScreen.visible=false;playAgainButton.visible=false;startNewMatch();}
var oldStakes;function startNewMatch()
{gameState=STATE_GAME_STAKES;oldStakes=[];for(var i=0;i<stakes.length;i++)
{oldStakes.push({id:stakes[i].id,vars:stakes[i].vars,value:stakes[i].value});}
clearStakes();paid=0;if(funds<=0)
{lockScreen.visible=true;playAgainButton.visible=true;}
showFunds();showPaid();}
function setCurrentStake(e)
{var id=e.target.stakeID;currentStake=stakesVals[id];for(var i=0;i<5;i++)
{stakesUnmarks[i].visible=(i!=id);}
if(e.target.bitmap)playSound("button");}
function showFunds()
{fundsText.write(funds);}
function showPaid()
{paidText.write(paid);}
function getBoardWidth()
{if(Utils.globalScale>=2)return 266;else return 410;}
function getBoardHeight()
{if(Utils.globalScale>=2)return 188;else return 220;}
function getCellWidth()
{if(Utils.globalScale>=2)return 19;else return 29.3;}
function getCellHeight()
{if(Utils.globalScale>=2)return 28;else return 42;}
function addStake(id,vars,val)
{if(funds<currentStake)return;var value=(val?val:currentStake);var stake={"id":id,"vars":vars,"value":value};var id=stakesVals.indexOf(value)+1;if(Utils.globalScale>=2)var d=new Sprite(bitmaps["stake_token"+id],17,16);else
{var d=new Sprite(bitmaps["stake_token"+id+"_s"],32,32);d.scaleX=d.scaleY=0.7;}
stage.addChild(d);stage.setZIndex(d,2000);stake.sprite=d;stakes.push(stake);funds-=value;paid+=value;showFunds();showPaid();showStakes();}
function getCountSameStakes(stake,start)
{var cnt=0;var ok;for(var i=0;i<start;i++)
{if(stake.id==stakes[i].id)
{ok=true;for(var n in stake.vars)
{if(stake.vars[n]!=stakes[i].vars[n])ok=false;}
if(ok)cnt++;}}
return cnt;}
function showStakes()
{var bw=getBoardWidth();var bh=getBoardHeight();var cw=getCellWidth();var ch=getCellHeight();var px=0;var py=0;for(var i=0;i<stakes.length;i++)
{var st=stakes[i];if(st.id==1)
{if(st.vars.color==0)px=cw*6;else px=cw*8;if(Utils.globalScale>=2)
{px-=1;py=161;}
else
{px-=2;py=196;}}
if(st.id==2)
{if(st.vars.odd==0)px=cw*4;else px=cw*10;if(Utils.globalScale>=2)py=161;else py=196;}
if(st.id==3)
{if(st.vars.part==0)px=cw*2;else px=cw*12;if(Utils.globalScale>=2)py=161;else py=196;}
if(st.id==4)
{px=cw*(3+st.vars.group*4);if(Utils.globalScale>=2)py=110;else py=150;}
if(st.id==5)
{px=cw*13+cw/2;py=ch*st.vars.row+ch/2;}
if(st.id==6)
{px=(st.vars.col+2)*cw;py=ch*3;}
if(st.id==7)
{px=cw;py=ch*3;}
if(st.id==8)
{px=cw*(st.vars.x+2);py=ch*(st.vars.y+1);}
if(st.id==9)
{px=cw*(st.vars.col+2)-cw/2;py=ch*3;}
if(st.id==10)
{px=cw;py=ch*st.vars.row+ch;}
if(st.id==11)
{if(st.vars.x1==st.vars.x2)
{px=cw*(st.vars.x1+2)-cw/2;py=ch*(st.vars.y1+1);}
else
{px=cw*(st.vars.x1+2);py=ch*(st.vars.y1+1)-ch/2;}}
if(st.id==12)
{var c=getNumberCellCoords(st.vars.x,st.vars.y);px=c.x;py=c.y;}
if(Utils.globalScale<2&&st.id>4)
{px-=1;py+=1;}
px=Math.floor(px);py=Math.floor(py);var c=getNumberCellCoordsOnBoard(px,py);st.sprite.x=c.x;st.sprite.y=c.y;var preCnt=getCountSameStakes(st,i);st.sprite.x+=preCnt*1;st.sprite.y+=preCnt*1;}}
function getNumberCellCoords(x,y)
{var cw=getCellWidth();var ch=getCellHeight();var px,py;if(x<0)
{px=cw/2-2;py=ch*2+ch/4;}
else
{px=x*cw+cw+cw/2;py=y*ch+ch/2;}
return{x:px,y:py};}
function getNumberCellCoordsOnBoard(x,y)
{var px=boardSprite.x-boardSprite.width/2+x;var py=boardSprite.y-boardSprite.height/2+y;if(Utils.globalScale<2)py+=1;return{x:px,y:py};}
function clearStakes(retFunds)
{if(gameState!=STATE_GAME_STAKES)return;for(var i=0;i<stakes.length;i++)
{stage.removeChild(stakes[i].sprite);if(retFunds)funds+=stakes[i].value;}
stakes=[];paid=0;showFunds();showPaid();showStakes();}
function setStake(e)
{if(gameState!=STATE_GAME_STAKES)return;var rowWidth=getCellWidth()/4;var rowHeight=getCellHeight()/4;var col=Math.floor((e.x+getBoardWidth()/2)/rowWidth);var row=Math.floor((e.y+getBoardHeight()/2)/rowHeight);if(row<=12)
{if(col>=52)
{if(row<4)addStake(5,{row:0});if(row>=4&&row<8)addStake(5,{row:1});if(row>=8)addStake(5,{row:2});}
else
{if(row==11||row==12)
{var p=col%4;if(p==1||p==2)addStake(9,{col:Math.floor((col-4)/4)});if(p==0||p==3)
{var c=Math.floor((col-2)/4);if(c==0)addStake(7,{});else
{if(c<12)addStake(6,{col:c-1});}}}
else
{var c=Math.floor((col-3)%4);var r=Math.floor(row%4);if(col<51&&row>2&&(c==0||c==1)&&(r==0||r==3))
{if(col>4)addStake(8,{x:Math.floor((col-6)/4),y:Math.floor((row-2)/4)});else addStake(10,{row:Math.floor((row-2)/4)});}
else if(col<51&&col>4&&(c==2||c==3)&&(r==1||r==2))
{addStake(12,{x:Math.floor((col-4)/4),y:Math.floor(row/4)});}
else if(col<4)
{addStake(12,{x:-1,y:-1});}
else
{if(c==0||c==1)
{if(col>4&&col<51)
{var b=col;if(c==1)b=col-4;addStake(11,{x1:Math.floor((b-4)/4),y1:Math.floor(row/4),x2:Math.floor(b/4),y2:Math.floor(row/4)});}}
else
{if(row>=3)
{var b=row;if(r==0)b=row-4;addStake(11,{x1:Math.floor((col-4)/4),y1:Math.floor(b/4),x2:Math.floor((col-4)/4),y2:Math.floor((b+4)/4)});}}}}}}
var groupMax=16;if(Utils.globalScale>=2)groupMax=19;if(row>12&&row<groupMax)
{if(col>=4&&col<=19)addStake(4,{group:0});if(col>=20&&col<=35)addStake(4,{group:1});if(col>=36&&col<=51)addStake(4,{group:2});}
if(row>=groupMax)
{if(col>=20&&col<=27)addStake(1,{color:0});if(col>=28&&col<=35)addStake(1,{color:1});if(col>=12&&col<=19)addStake(2,{odd:0});if(col>=36&&col<=43)addStake(2,{odd:1});if(col>=4&&col<=11)addStake(3,{part:0});if(col>=44&&col<=51)addStake(3,{part:1});}
playSound("button");}
var currentWheelNumber=0;var spinWheelSpeed=0;var spinWheelStartSpeed=0;var spinBallSpeed=0;var spinBallAngle=0;var spinBallAngleDiff=0;var spinBallState=0;var wheelSpined=false;var spinBallJump=0;var spinBallJumpMax=0;var spinBallDelay=0;function spinWheel()
{if(gameState!=STATE_GAME_STAKES)return;if(stakes.length<1)return;playSound("button");gameState=STATE_GAME_SPIN;unmarkResults();if(Utils.globalScale<2)
{for(var i=0;i<stage.objects.length;i++)
{if(stage.objects[i].screen2)stage.objects[i].visible=true;else
{stage.objects[i].oldVisible=stage.objects[i].visible;stage.objects[i].visible=false;}}
buildBackground();}
ball.visible=true;spinWheelSpeed=0.2+Math.random()/4;if(spinWheelSpeed<0.32)spinWheelSpeed=0.32;spinWheelStartSpeed=spinWheelSpeed;spinBallSpeed=spinWheelSpeed-(Math.random()*0.1+0.1);spinBallAngle=Math.PI+Math.PI/4;spinBallState=0;ball.opacity=1;wheelSpined=true;}
function doSpinWheel()
{if(!wheelSpined)return;if(spinWheelSpeed<=0)return;wheel.rotation-=spinWheelSpeed;spinWheelSpeed-=0.002;if(spinWheelSpeed<0.2&&spinBallState==0)
{spinBallState=1;spinBallJumpMax=Math.floor(Math.random()*4);spinBallJump=0;spinBallDelay=0;}
if(spinBallState==0)
{spinBallAngle+=spinBallSpeed;spinBallSpeed-=0.002;}
if(spinBallState==1)
{var jend=false;if(spinBallJumpMax==0)jend=true;else
{spinBallDelay++;if(spinBallDelay<=3)
{ball.scaleX=ball.scaleY=1+spinBallDelay/10;}
if(spinBallDelay>3)
{ball.scaleX=ball.scaleY=1+(7-spinBallDelay)/10;if(spinBallDelay==7)
{ball.scaleX=ball.scaleY=1;spinBallDelay=0;spinBallJump++;if(spinBallJump>=spinBallJumpMax)jend=true;}}}
if(jend)
{spinBallState=2;var n=Math.round(Math.abs((wheel.rotation-spinBallAngle)/(Math.PI*2/37)));var k=Math.floor(n/37);n=n-k*37;currentWheelNumber=wheelNumbers[n];spinBallAngleDiff=n*Math.PI*2/37-0.09;}}
if(spinBallState==2)
{spinBallAngle=wheel.rotation+spinBallAngleDiff;}
var minPos=(Utils.globalScale>=2?5:12);var maxPos=(Utils.globalScale>=2?21:39);var len=(wheel.width/2+minPos);if(spinBallState>0)len-=maxPos;else
{var delta=(spinWheelSpeed-0.2)/(spinWheelStartSpeed-0.2);if(delta>1)delta=1;len-=(maxPos-delta*maxPos);}
ball.x=wheel.x+Math.cos(spinBallAngle-Math.PI/2)*len;ball.y=wheel.y+Math.sin(spinBallAngle-Math.PI/2)*len;ball.rotation=spinBallAngle;if(spinWheelSpeed<=0)
{if(Utils.globalScale>=2)endSpinWheel();else stage.setTimeout(endSpinWheel,fps);}}
function getNumberX(val)
{for(var y=0;y<3;y++)
{for(var x=0;x<12;x++)
{if(board[y][x].id==val)return x;}}
return-1;}
function getNumberY(val)
{for(var y=0;y<3;y++)
{for(var x=0;x<12;x++)
{if(board[y][x].id==val)return y;}}
return-1;}
function endSpinWheel()
{gameState=STATE_GAME_RESULTS;if(Utils.globalScale<2)
{for(var i=0;i<stage.objects.length;i++)
{if(stage.objects[i].screen2)stage.objects[i].visible=false;else stage.objects[i].visible=stage.objects[i].oldVisible;}
buildBackground();}
wheelSpined=false;var winSumm=checkStakes(currentWheelNumber);if(winSumm>0)
{lockScreen.visible=true;mc=new Sprite(bitmaps.win_text,200,90);mc.x=240;mc.y=160;stage.addChild(mc);resultText=mc;resultSumText=new SimpleText(bitmaps.font3,30,34);resultSumText.charMap=['0','1','2','3','4','5','6','7','8','9','$'];resultSumText.x=240;resultSumText.y=166;resultSumText.align=resultSumText.ALIGN_CENTER;resultSumText.write("$"+winSumm);lockScreen.onclick=function()
{resultText.destroy=true;resultSumText.write("");lockScreen.visible=false;lockScreen.onclick=null;playSound("win");funds+=winSumm;startNewMatch();return false;}}
else
{lockScreen.visible=true;mc=new Sprite(bitmaps.lose_text,200,59);mc.x=240;mc.y=160;stage.addChild(mc);resultText=mc;lockScreen.onclick=function()
{resultText.destroy=true;lockScreen.visible=false;startNewMatch();lockScreen.onclick=null;return false;}}
var c=getNumberCellCoords(getNumberX(currentWheelNumber),getNumberY(currentWheelNumber));c=getNumberCellCoordsOnBoard(c.x,c.y);if(Utils.globalScale>=2)
{c.x+=6;c.y-=4;}
else
{c.x+=9;c.y-=4;}
resultToken.moveTo(c.x,c.y,fps/2,null,markResults);}
function returnResultToken()
{if(Utils.globalScale>=2)resultToken.moveTo(190,200,fps/2);else resultToken.moveTo(26,124,fps/2);}
function markResults()
{stage.setTimeout(returnResultToken,fps*2);if(currentWheelNumber>0)
{var c=getNumberCellCoords(getNumberX(currentWheelNumber),getNumberY(currentWheelNumber));c=getNumberCellCoordsOnBoard(c.x,c.y);winMarks[1].visible=true;winMarks[1].x=c.x-1;winMarks[1].y=c.y;if(Utils.globalScale>=2)
{winMarks[2].visible=true;winMarks[2].x=463;winMarks[2].y=getNumberY(currentWheelNumber)*28+53;winMarks[3].visible=true;winMarks[3].y=149;winMarks[3].x=263.5+Math.floor((currentWheelNumber-1)/12)*76.5;winMarks[4].visible=true;winMarks[4].y=200;var num=getNumberOnBoard(currentWheelNumber);if(num.color==0)winMarks[4].x=320;else winMarks[4].x=358;winMarks[5].visible=true;winMarks[5].y=200;if(currentWheelNumber%2==0)winMarks[5].x=282;else winMarks[5].x=396;winMarks[6].visible=true;winMarks[6].y=200;if(currentWheelNumber<=18)winMarks[6].x=244;else winMarks[6].x=435;}
else
{winMarks[2].visible=true;winMarks[2].x=463;winMarks[2].y=getNumberY(currentWheelNumber)*43+42;winMarks[3].visible=true;winMarks[3].y=171;winMarks[3].x=155+Math.floor((currentWheelNumber-1)/12)*117;winMarks[4].visible=true;winMarks[4].y=217;var num=getNumberOnBoard(currentWheelNumber);if(num.color==0)winMarks[4].x=243;else winMarks[4].x=302;winMarks[5].visible=true;winMarks[5].y=217;if(currentWheelNumber%2==0)winMarks[5].x=184;else winMarks[5].x=361;winMarks[6].visible=true;winMarks[6].y=217;if(currentWheelNumber<=18)winMarks[6].x=126;else winMarks[6].x=419;}}
else
{winMarks[0].visible=true;if(Utils.globalScale>=2)
{winMarks[0].x=211;winMarks[0].y=102;}
else
{winMarks[0].x=75;winMarks[0].y=116;}}}
function unmarkResults()
{for(var i=0;i<winMarks.length;i++)
{winMarks[i].visible=false;}}
function checkStakes(val)
{var summ=0;for(var i=0;i<stakes.length;i++)
{summ+=checkStake(stakes[i],val);}
return summ;}
function getNumberOnBoard(val)
{for(var y=0;y<3;y++)
{for(var x=0;x<12;x++)
{if(board[y][x].id==val)return board[y][x];}}
return{id:0,color:-1};}
function checkStake(stake,val)
{var coef=0;if(stake.id==1&&val>0)
{if(stake.vars.color==getNumberOnBoard(val).color)coef=1;}
if(stake.id==2&&val>0)
{if(stake.vars.odd==val%2)coef=1;}
if(stake.id==3&&val>0)
{if(stake.vars.part==0&&val<=18)coef=1;if(stake.vars.part==1&&val>18)coef=1;}
if(stake.id==4&&val>0)
{if(stake.vars.group==0&&val>=1&&val<=12)coef=2;if(stake.vars.group==1&&val>=13&&val<=24)coef=2;if(stake.vars.group==2&&val>=25&&val<=36)coef=2;}
if(stake.id==5&&val>0)
{for(var i=0;i<board[stake.vars.row].length;i++)
{if(board[stake.vars.row][i].id==val)coef=2;}}
if(stake.id==6&&val>0)
{for(var x=stake.vars.col;x<=stake.vars.col+1;x++)
{for(var y=0;y<3;y++)
{if(board[y][x].id==val)coef=5;}}}
if(stake.id==7)
{if(val<4)coef=8;}
if(stake.id==8&&val>0)
{for(var x=stake.vars.x;x<=stake.vars.x+1;x++)
{for(var y=stake.vars.y;y<=stake.vars.y+1;y++)
{if(board[y][x].id==val)coef=8;}}}
if(stake.id==9&&val>0)
{for(var y=0;y<3;y++)
{if(board[y][stake.vars.col].id==val)coef=11;}}
if(stake.id==10)
{if(stake.vars.row==0&&(val==0||val==3||val==2))coef=11;if(stake.vars.row==1&&(val==0||val==2||val==1))coef=11;}
if(stake.id==11&&val>0)
{if(board[stake.vars.y1][stake.vars.x1].id==val||board[stake.vars.y2][stake.vars.x2].id==val)coef=17;}
if(stake.id==12)
{if(val<1)
{if(stake.vars.x<0&&stake.vars.y<0)coef=35;}
else
{if(stake.vars.x>0&&stake.vars.y>0)
{if(board[stake.vars.y][stake.vars.x].id==val)coef=35;}}}
if(coef==0)return 0;return(coef+1)*stake.value;}
function repeatStakes()
{if(gameState!=STATE_GAME_STAKES)return;if(oldStakes.length<1)return;clearStakes(true);for(var i=0;i<oldStakes.length;i++)
{addStake(oldStakes[i].id,oldStakes[i].vars,oldStakes[i].value);}
playSound("button");}
function preTick()
{}
function postTick()
{};