(function(){var A=function(){var T=12;var Z=Stage.init({element:document.getElementById("main"),fps:T});UITool.makeMenu(document.getElementById("menucontainer"),Stage.width,[{label:"Home",action:function(){location.href="../"}},{label:"Pause",action:function(){p.wait();alert("PAUSE");p.start()}}]);UITool.createModalPanelFromDOMElement({target:document.getElementById("container"),element:document.getElementById("help"),width:320,height:338,margin:32,button:[{label:"ok",func:function(){n()}}],remove:true});document.addEventListener("touchmove",function(u){u.preventDefault()},false);var C;var e=[];var U=15,F=-1;var H=4*4;var a=[3,1,1,4,0,3,4,0,0,2,6,5,2,1,5,5];var V=40,S=12;var m={type0:{up:true,down:true},type1:{left:true,right:true},type2:{down:true,left:true},type3:{left:true,up:true},type4:{right:true,up:true},type5:{down:true,right:true},type6:{up:true,down:true,left:true,right:true}};var O={down:"up",up:"down",right:"left",left:"right"};var Q=4,k=4;var J=60;var p;var g,P;var E,d;var c=0,b=0;var r="down";var h=1;var f=-0.006;var N=-2;var Y=-1;var K=function(){this.prevfocus=undefined;this.initialize()};K.prototype={life_max:5,life_gauge:new Array(),opacity_min:0.1,incLife:function(u){if(this.life==0){return }this.life+=u;if(this.life>this.life_max){this.life=this.life_max}if(this.life<0){this.life=0}this.redraw();if(this.life==0){p.wait();p.stop();if(P){P.stop();delete P.onEnterFrame}if(d){d.stop();delete d.onEnterFrame}C=true;G();setTimeout(l,2000)}},redraw:function(){var x=Math.floor(this.life);var u=this.life_gauge[x];var v=Math.max(this.life%1,this.opacity_min);if(u){u.style.opacity=v;if(u!=this.prevfocus){for(var w=0;w<this.life_max;w++){if(w<x){this.life_gauge[w].style.opacity=1}else{if(w>x){this.life_gauge[w].style.opacity=this.opacity_min}}}}}this.prevfocus=u},initialize:function(){this.life=this.life_max;for(var u=0;u<this.life_gauge.length;u++){this.life_gauge[u].style.opacity=1}this.redraw()}};var j=new K();var R;var D;s();function s(){var z=j.life_max;var x=document.getElementById("heart_img");for(var v=0;v<z;v++){var y=x.cloneNode(false);document.getElementById("main").appendChild(y);j.life_gauge[j.life_gauge.length]=y;y.style.position="absolute";y.style.top="267px";y.style.left=(v*24+158)+"px"}var w=Z.createTextField("score_static",Z.getNextHighestDepth(),40,272,148,24);w._element.style.fontSize=12;w._element.style.color="white";w._element.style.fontWeight="normal";w.text="SCORE";R=Z.createTextField("score",Z.getNextHighestDepth(),92,272,148,24);R._element.style.fontSize=12;R._element.style.color="white";R._element.style.fontWeight="normal";R.text="0";var u;for(var v=0;v<H;v++){u={_x:v%4*60+V,_y:Math.floor(v/4)*60+S,_visible:false};var AA=Z.attachMovie("panel","p"+v,Z.getNextHighestDepth(),u);AA.onLoad=function(){this.gotoAndStop(a[this.id]+1);this._visible=true};AA.id=v;AA.loc=v;AA.type=a[v];e[v]=v;document.addEventListener("touchstart",(function(){var AB=AA;return function(AC){if(AC.touches[0].target.parentNode==AB._element){i.apply(AB)}}})(),false)}Z["p"+U].removeMovieClip();p=Z.attachMovie("tekuteku","teku",Z.getNextHighestDepth(),{_x:c*60+V+30,_y:b*60+S+30+5,_xscale:50,_yscale:50,_origin:"bottom",_visible:false});p.onLoad=function(){this._visible=true;this.stop()};p.addFrameScript(5,function(){this.gotoAndPlay("down")});p.addFrameScript(10,function(){this.gotoAndPlay("up")});p.addFrameScript(15,function(){this.gotoAndPlay("right")});p.addFrameScript(20,function(){this.gotoAndPlay("left")});p.setDirection=(function(){var AB={down:{x:0,y:1},up:{x:0,y:-1},right:{x:1,y:0},left:{x:-1,y:0}};return function(AD){r=AD;this.gotoAndPlay(AD);var AC=AB[AD];this.vX=AC.x;this.vY=AC.y}})();p.checkNextPanel=(function(){var AB={down:{x:0,y:1},up:{x:0,y:-1},right:{x:1,y:0},left:{x:-1,y:0}};return function(AG){var AF,AD,AK,AJ,AC,AH;var AE=AB[AG],AI=0;AF=c+AE.x;AD=b+AE.y;AC=AD*Q+AF;if(AF==Q||AF<0||AD==k||AD<0){AI=1}AH=Z["p"+e[AC]];if(AH==undefined){AI=1}else{if(!m["type"+AH.type][r]){AI=1}}if(AI){this.setDirection(O[r]);j.incLife(Y);this.damage()}else{this.currentpaneltype=Z["p"+e[AC]].type;this.loc=AC;c=AF;b=AD}}})();p.turn=(function(){var AB={down:{2:"right",5:"left"},up:{3:"right",4:"left"},right:{4:"down",5:"up"},left:{2:"up",3:"down"}};return function(){var AD,AC=AB[r];if(AD=AC[this.currentpaneltype]){this.setDirection(AD)}D++;t(D);if(e[this.loc]==g){L()}else{if(e[this.loc]==E){if(d._alpha>50){W()}}}}})();p.damage=function(){q.blink(this,4)};p.start=function(){this.onEnterFrame=function(){this._x+=this.spd*this.vX;this._y+=this.spd*this.vY;this.count=(this.count+1)%this.step;j.incLife(f);if(this.count==0){this.checkNextPanel(r)}else{if(this.count==this.step/2){this.turn()}}}};p.wait=function(){delete this.onEnterFrame};document.addEventListener("touchstart",function(AB){if(AB.touches[0].target.parentNode==p._element){i.apply(Z["p"+e[p.loc]])}},false)}function n(){for(var u=0;u<H;u++){if(u!=U){var v=Z["p"+u];v._x=u%4*60+V;v._y=Math.floor(u/4)*60+S;v.loc=u}e[u]=u}if(P){P.removeMe()}if(d){d.removeMe()}g=5;E=10;U=15;C=false;c=0;b=0;p.loc=b*Q+c;p.currentpaneltype=Z["p"+p.loc].type;p.step=30;p.count=p.step/2;p.spd=J/p.step;p._x=c*60+V+30;p._y=b*60+S+30+5;p.wait();setTimeout(function(){p.start()},1000);p.setDirection("down");B(g);I(E);d._alpha=100;j.initialize();D=0;t(D)}function t(u){R.text=u}function i(){if(!C){X(this)}}function X(z){var x=0;var w;var AA,u;var y=[];AA=z.loc;u=AA;while(x==0&&u>=Q){y[y.length]={panel:u,replace:u-Q};u-=Q;if(e[u]==U){x=1}}if(!x){y=[]}u=AA;while(x==0&&u%4<3){y[y.length]={panel:u,replace:u+1};u++;if(e[u]==U){x=2}}if(!x){y=[]}u=AA;while(x==0&&u<Q*(k-1)){y[y.length]={panel:u,replace:u+Q};u+=Q;if(e[u]==U){x=3}}if(!x){y=[]}u=AA;while(x==0&&u%4>0){y[y.length]={panel:u,replace:u-1};u--;if(e[u]==U){x=4}}if(!x){y=[]}if(x){for(var v=y.length-1;v>=0;v--){C=true;M(Z["p"+e[y[v].panel]],x);o(y[v].panel,y[v].replace)}}}function M(AB,u){var z=0,y=0;var x=30;var w=2;var AA=false;if(u==1){y=-1}if(u==2){z=1}if(u==3){y=1}if(u==4){z=-1}if(AB.loc==p.loc){AA=true;p.wait()}AB.onEnterFrame=function(){if(w--){this._x+=x*z;this._y+=x*y;if(AA){p._x+=x*z;p._y+=x*y}}else{C=false;if(AA){c+=z;b+=y;p.loc=b*Q+c;p.start()}delete this.onEnterFrame}}}function o(w,v){var x=Z["p"+e[w]].loc;Z["p"+e[w]].loc=v;var u=e[w];e[w]=e[v];e[v]=u}function B(v){if(P){return }g=v;var u={_x:30,_y:34,_origin:"bottom"};P=Z["p"+v].attachMovie("heart","heart",Z["p"+v].getNextHighestDepth(),u);P.onEnterFrame=(function(){var y=1,w=0,x=4;P._y-=x*y;P._yscale+=x*y*4;return function(){if(w++<x){this._y+=y;this._yscale-=y*4}else{w=0;this._y-=x*y;this._yscale+=x*y*4}}})();P.touch=function(w){if(w.touches[0].target.parentNode==this._element){i.apply(this._parent)}};P.touchListner=function(w){P.touch(w)};document.addEventListener("touchstart",P.touchListner,false);P.removeMe=function(){document.removeEventListener("touchstart",this.touchListner,false);this.removeMovieClip();P=undefined}}function L(){var u=g;g=undefined;P.removeMe();j.incLife(h);setTimeout(function(){var v;do{v=Math.round(Math.random()*(Q*k-1))}while(v==u||v==U||v==E||v==p.loc);B(v)},4000)}function I(v){if(d){return }E=v;var u={_x:30,_y:34,_origin:"bottom",_alpha:0};d=Z["p"+v].attachMovie("skull","skull",Z["p"+v].getNextHighestDepth(),u);d.addFrameScript(d._totalframes,function(){this.gotoAndPlay(Math.round(Math.random()*(this._totalframes-1)))});d.onEnterFrame=function(){this._alpha++;if(this._alpha>=100){this._alpha=100;this.onEnterFrame=(function(){var w=T*14;return function(){if(--w==0){this.onEnterFrame=function(){this._alpha--;if(this._alpha==0){this.removeMe();I(e[p.loc])}}}}})()}};d.touch=function(w){if(w.touches[0].target.parentNode==this._element){i.apply(this._parent)}};d.touchListner=function(w){d.touch(w)};document.addEventListener("touchstart",d.touchListner,false);d.removeMe=function(){document.removeEventListener("touchstart",this.touchListner,false);this.removeMovieClip();d=undefined}}function W(){var u=E;E=undefined;d.removeMe();j.incLife(N);setTimeout(function(){var v;do{v=Math.round(Math.random()*(Q*k-1))}while(v==u||v==U||v==g||v==p.loc);I(v)},2000);p.damage()}function l(){var v=25;var w="<center><h3>GAME OVER</h3><br />Score : "+D+"</center><br />";var u=[{label:"Try again",func:function(){n();return false}},{label:"Other games",func:function(){document.location="http://www.grkt.com/iphone/";return true}},{label:"Tell a friend",func:function(){document.location="mailto:?body="+document.location;return true}}];UITool.createModalPanel(document.getElementById("container"),320,338,{margin:v,text:w,button:u})}function G(){var u=0;Z.onEnterFrame=function(){for(var v=0;v<j.life_gauge.length;v++){j.life_gauge[v].style.visibility=u%2?"visible":"hidden"}if(++u==14){for(var v=0;v<j.life_gauge.length;v++){j.life_gauge[v].style.visibility="visible"}delete this.onEnterFrame}}}var q=Z.createEmptyMovieClip("blk",Z.getNextHighestDepth());q.blink=function(w,u){if(this.target){this.target._visible=true}this.target=w;this.target._visible=false;var v=u||10;this.onEnterFrame=function(){w._visible=!(v%2);if(v--==0){w._visible=true;delete this.onEnterFrame}}}};window.addEventListener("load",function(){var B=10;var D=document.getElementById("loading");D.style.opacity=1;var C=setInterval(function(){D.style.opacity-=0.1;if(B--==0){clearInterval(C);A();D.parentNode.removeChild(D);document.getElementById("container").style.display="block";document.getElementById("ads").style.display="block";window.scrollTo(0,1)}},50)},false)})();