text: !function($){function shuffle(e){for(var a,t,s=e.length;s;a=parseInt(Math.random()*s),t=e[--s],e[s]=e[a],e[a]=t);return e}function movecube(){$(".turnLink").css("visibility","visible");var onfront=["top","bottom"],ontop=["back","front"],onback=["bottom","top"],onbottom=["front","back"],turnCubeLinks=onfront;$bottom=$(".turnLink").Touchable(),$bottom.on("touchableend",function(){$("#cube").attr("class","show-"+turnCubeLinks[$(this).attr("data-goto")]),turnCubeLinks=eval("on"+turnCubeLinks[$(this).attr("data-goto")])})}function createCube(e){$(".wrapper").html('<div data-goto="0" class="turnLink inTop icon-arrow-down"></div><div id="container" class="'+e+'"><div id="cube" class="show-front"><div class="cubeFace left"></div><div class="cubeFace right"></div></div></div><div data-goto="1" class="turnLink inBottom icon-arrow-up"></div>')}function startTimer(e){e&&(current=1),timeCounter=setInterval(function(){actualSeconds=current-start,$(".chrono").attr("data-seconds",actualSeconds),$(".chrono").text(actualSeconds),$(".chrono").time_from_seconds(),current++},1e3)}function stopTimer(){clearInterval(timeCounter)}function openLateral(){$("#container").hasClass("game")&&stopTimer(),$("#appMenu").addClass("open"),$("#container").hasClass("index")||(lateralCubeClass=$("#cube").attr("class"),$("#container").addClass("startAnimation"),$("#cube").attr("class","show-back"))}function closeLateral(e){$("#container").hasClass("game")&&e&&startTimer(!1),$("#appMenu").removeClass("open"),$("#container").hasClass("index")||($("#container").removeClass("startAnimation"),$("#cube").attr("class",lateralCubeClass))}function showLevels(){createCube("levels");var e;localStorage?localStorage.getItem("levelsStored")?e=JSON.parse(localStorage.getItem("levelsStored")):(newLevelsSet=[["world-flags",!0,0],["world-flags2",!1,0],["world-monuments",!1,0],["world-monuments2",!1,0],["cards",!1,0],["cards2",!1,0],["cards3",!1,0],["cards-11",!1,0],["colors",!1,0],["colors-names",!1,0],["colors-double",!1,0],["colors-names2",!1,0],["maths-sums",!1,0],["maths-subtractions",!1,0],["maths-multiplications",!1,0],["maths-equations",!1,0]],localStorage.setItem("levelsStored",JSON.stringify(newLevelsSet)),e=JSON.parse(localStorage.getItem("levelsStored"))):e=[["world-flags",!0,0],["world-flags2",!0,0],["world-monuments",!0,0],["world-monuments2",!0,0],["cards",!0,0],["cards2",!0,0],["cards3",!0,0],["cards-11",!0,0],["colors",!0,0],["colors-names",!0,0],["colors-double",!0,0],["colors-names2",!0,0],["maths-sums",!0,0],["maths-subtractions",!0,0],["maths-multiplications",!0,0],["maths-equations",!0,0]];for(var a=["front","bottom","back","top"],t=0,s=0;s<e.length;s++){if(s%4===0&&($("#cube").append('<div class="cubeFace '+a[t]+'"></div>'),t++),e[s][1])if(0!==e[s][2]){for(var o="",n=1;3>=n;n++)o+=n<=e[s][2]?'<span class="icon-star-3"></span>':'<span class="icon-star"></span>';var l='<div class="levelScore">'+o+"</div>",r="readyToPlay"}else var l="",r="newToPlay";else var l='<div class="icon-lock"></div>',r="levelBlocked";var c=s+1;$(".cubeFace").last().append('<div class="flip"><div class="card" id="level'+s+'"><div class="face fontFace '+r+'" data-level="'+e[s][0]+'" style="background-image: url(levels/'+e[s][0]+'/level-icon.png);"><div class="levelNumber">'+c+"</div>"+l+"</div></div></div>")}$t=$(".readyToPlay, .newToPlay").Touchable(),$t.on("touchableend",function(){startGame($(this).attr("data-level"))}),movecube()}function endGame(e,a){for(var t=$(".chrono").html(),s="",o=1;3>=o;o++)s+=a>=o?'<span class="icon-star-3"></span>':'<span class="icon-star"></span>';if($("#appMenu").append('<div class="gameFinished"><h1>Well Done</h1><p>You have finished "'+e+'" in '+t+'</p><p class="finishedLevelScore">'+s+'</p><a href="#" class="repeatGame">Play Again</a><a href="#" class="goToLevels">Next Level</a></div>'),$("#appMenu .icon-cog, #appMenu .contentAppMenu").css("display","none"),openLateral(),localStorage){for(var n=JSON.parse(localStorage.getItem("levelsStored")),l=0;l<n.length;l++)if(0===$.inArray(e,n[l])){n[l][2]<a&&(n[l][2]=a),n[l+1]&&(n[l+1][1]=!0);break}localStorage.setItem("levelsStored",JSON.stringify(n))}$(".goToLevels").click(function(){return $(".chrono").html(""),closeLateral(!1),showLevels(),$(".gameFinished").remove(),$("#appMenu .icon-cog, #appMenu .contentAppMenu").css("display","block"),!1}),$(".repeatGame").click(function(){return $(".chrono").html(""),closeLateral(!1),startGame(e),$(".gameFinished").remove(),$("#appMenu .icon-cog, #appMenu .contentAppMenu").css("display","block"),!1})}function startGame(e){function a(e){e.hasClass("select")||($(".card").removeClass("flipped"),setTimeout(function(){e.addClass("flipped")},300),setTimeout(function(){e.removeClass("flipped")},2e3))}function t(a){if($(".card").removeClass("flipped"),a.hasClass("select"))l="empty",a.removeClass("select");else{var t=a.data("content");if(l==t){if($(".card").removeClass("select"),l="empty",$('div[data-content="'+t+'"]').addClass("solved"),$(".solved").size()==$(".card").size()){stopTimer();var s=0;s=$(".chrono").attr("data-seconds")<60?3:$(".chrono").attr("data-seconds")<120?2:1,endGame(e,s)}}else if(a.addClass("select"),"empty"==l)l=t;else{var o=["FAIL!","MAL","NO,NO!","NO WAY","TRY AGAIN","WRONG","TIC TOC","ERROR","NOPE"];shuffle(o),$(".message").html(o[0]),$(".message").addClass("showMessage"),setTimeout(function(){$(".message").removeClass("showMessage")},1500),$(".card").removeClass("select"),l="empty"}}}createCube("game");var s=[[1,"img-1-1"],[1,"img-1-2"],[2,"img-2-1"],[2,"img-2-2"],[3,"img-3-1"],[3,"img-3-2"],[4,"img-4-1"],[4,"img-4-2"],[5,"img-5-1"],[5,"img-5-2"],[6,"img-6-1"],[6,"img-6-2"],[7,"img-7-1"],[7,"img-7-2"],[8,"img-8-1"],[8,"img-8-2"]],o=["front","bottom","back","top"],n=0,l="empty";shuffle(s);for(var r=0;r<s.length;r++)r%4===0&&($("#cube").append('<div class="cubeFace '+o[n]+'"></div>'),n++),$(".cubeFace").last().append('<div class="flip"><div class="card" id="card'+r+'" data-content="'+s[r][0]+'"><div class="face fontFace"></div><img src="levels/'+e+"/"+s[r][1]+'.png" alt="card'+s[r][1]+'" class="face backFace" /></div></div>');$(".wrapper").append('<div class="message"></div>'),startTimer(!0),$t=$(".face").Touchable();var c=!1;$t.on("doubleTap",function(e,a){c=!0;var s=a.elem.parentElement.id,o=$("#"+s);t(o),setTimeout(function(){c=!1},600),e.preventDefault()}),$t.on("touchableend",function(e,t){setTimeout(function(){if(c!==!0){var e=t.elem.parentElement.id,s=$("#"+e);a(s)}},300)}),movecube()}Zepto.fn.time_from_seconds=function(){return this.each(function(){var e=parseInt($(this).text(),10);$(this).data("original",e);var a=Math.floor(e/3600);e%=3600;var t=Math.floor(e/60),s=Math.floor(e%60);$(this).text((a>0?a+" : ":"")+(t>0?10>t?"0"+t+" : ":t+" : ":"00 : ")+(10>s?"0"+s:s))})};var start=1,current=1,timeCounter,lateralCubeClass;$(".startGame").click(function(){return showLevels(),!1}),$(".icon-cog").click(function(){$("#appMenu").hasClass("open")?closeLateral(!0):openLateral()}),$(".menuToLevels").click(function(){return $(".chrono").html(""),closeLateral(!1),showLevels(),!1})}(window.Zepto);