mesa.StoreManager=Class.create();mesa.StoreManager.prototype={initialize:function(c,b,a){this.basePath=c;this.creditsOwned=0;if(!b.blank()){this.creditsOwned=parseInt(b)}this.loginUserId=a;this.moreTokensTitle="You need some tokens!";this.purchasedMsg="We've brought you back to the store, where you can turn your tokens into upgrades! \n\n Please note, it may take up to 10 minutes for your account to be credited. ";this.purchasedGunsMsg="The full version of Guns of Icarus has been unlocked! You may now play it in your browser, or download a copy to your PC or Mac.\n\n Please note it may take up to 10 minutes for your account to be credited, and for the full version to be activated.";this.purchasedMbbMsg="The full version of Make Bouncy Bouncy has been unlocked! You may now play it in your browser, or download a copy to your PC or Mac.\n\n Please note it may take up to 10 minutes for your account to be credited, and for the full version to be activated.";this.buyNowFailed="We're Sorry, We are unable to complete this transaction at this time.  You have not been charged, and the error has been logged.";this.confirmUpgradeMsg="Upgrade?"},buyNow:function(c,b,d,a){if(this.loginUserId!=null){if(this.enoughCredits(b)){this.confirmBuyNow(c,b,d,a)}else{this.showPurchaseCreditsWin()}}else{mesa.home.LoginUtil.openLogin()}},enoughCredits:function(a){if(a!=null&&this.creditsOwned>=a){return true}return false},showPurchaseCreditsWin:function(){if(this.loginUserId!=null){new mesa.Popup.MessageWindow(this.basePath,this.moreTokensTitle,"inventory/purchaseTokens.jsp",600,320,true,null,function(a){new mesa.Ajax.Request("credit/purchase.do",{credits:a.credits,method:a.method},mesa.PaymentUtil.submitPaymentForm).send()},function(){}).show()}else{mesa.home.LoginUtil.openLogin()}},purchaseFullVersion:function(b){var a=this;new mesa.Ajax.Request("inventory/getItem.do",{itemId:b},function(c){new mesa.Popup.MessageWindow(null,"Login and Purchase","inventory/purchaseFullVersion.jsp",950,500,true,{item:c},function(d){if(d=="login"){mesa.home.LoginUtil.openLogin()}}).show()}).send()},confirmBuyNow:function(d,c,e,a){var b=this;new mesa.Ajax.Request("inventory/getItem.do",{itemId:d},function(f){new mesa.Popup.MessageWindow(this.basePath,f.name,"inventory/confirmBuyNow.jsp",440,350,true,{item:f,creditsNeeded:c,photoUrl:e},function(){new mesa.Ajax.Request("inventory/upgrade.do",{itemId:d},function(g){mesa.WebUtils.reload()},function(g){b.storeAlert(b.buyNowFailed)}).send()},function(){}).show()}).send()},storeAlert:function(a){new mesa.Popup.MessageWindow(this.basePath,"Alert","popup/alert.jsp",400,100,true,a).show()},thanksForShopping:function(b){var a=this;var c;if("gunsOfIcarus"==b){c=this.purchasedGunsMsg}else{if("makeBouncyBouncy"==b){c=this.purchasedMbbMsg}else{c=this.purchasedMsg}}new mesa.Popup.MessageWindow(pageContext.basePath,"Thanks for shopping and Enjoy!","popup/alert.jsp",500,100,true,c,function(){a.goBackToStore()},function(){a.goBackToStore()}).show()},goBackToStore:function(){location.href=this.basePath+"store/"}};
mesa.game={};mesa.game.loadGame=function(e,b,g,c,a,f){if(g&&!pageContext.loginUserId){var d=mesa.WebUtils.readCookie("playAsGuest");if(!d){new mesa.Popup.MessageWindow(null,"Login","home/loginFirst.jsp",540,230,true,null,function(){mesa.WebUtils.reload()},function(){mesa.WebUtils.createCookie("playAsGuest",true,1);mesa.UnityUtils.embedUnity(e,b,c,a,f)}).show()}else{mesa.UnityUtils.embedUnity(e,b,c,a,f)}}else{mesa.UnityUtils.embedUnity(e,b,c,a,f)}};mesa.game.getGameImage=function(a,b){return siteConfig.gameImageLocation+a+"/"+b};mesa.game.getAchievementImage=function(b,a){return siteConfig.gameImageLocation+b+"/achievements/"+a+".png"};mesa.game.navigateTo=function(b,a){};mesa.game.showInstruction=function(b,a){$(a).innerHTML=mesa.WebUtils.applyTemplate("installUnityInstruction",{game:b})};mesa.game.showInstructionStep2=function(){Effect.Fade("installUnityStep1",{duration:1,afterFinish:function(){Effect.Appear("installUnityStep2",{duration:1})}})};mesa.game.showTrailer=function(a){if(mesa.WebUtils.isMac()){window.open("home/video.jsp?gameName="+a,"video","width=500,height=300,top=150,left=150")}else{new mesa.Ajax.Request("game/getTrailer.do",{name:a},function(b){new mesa.Popup.VideoPlayer(null,b.filePath,b.width,b.height).show()},function(){mesa.Popup.alert("Sorry, this trailer is not available")}).send()}};mesa.game.loadGames=function(b,a){new mesa.Ajax.Request("game/loadGames.do",a,b).send()};mesa.game.loadAchievements=function(a,b){new mesa.Ajax.Request("game/loadAchievements.do",{gameId:a},b).send()};mesa.game.getGameModes=function(d){var c=[];if(d){var e=d.split(",");for(var b=0;b<e.length;++b){var a=e[b].strip();if(a){c.push(a)}}}return c};mesa.game.loadLevelBlock=function(a,b,f,d,e){var c={gameId:a,timeSpan:b};if(d&&d!="NULL"){c.mode=d}if(f!=null&&(typeof(f)=="number"||typeof(f)=="string")){c.level=f}else{if(f!=null&&f.length){c.levels=f.join(",")}}new mesa.Ajax.Request("game/getScoreLevelBlock.do",c,e).send()};mesa.game.paintLevelBlock=function(a){return mesa.WebUtils.applyTemplate("scoreLevelBlock",{r:a})};mesa.game.getStarsImage=function(e,c){var a=e;var d="";for(var b=0;b<5;++b){if(a>=2){a-=2;d+=c?"<img src='images/game/stars/starDarkFull.png'/>":"<img src='images/game/stars/starLightFull.png'/>"}else{if(a==1){a-=1;d+=c?"<img src='images/game/stars/starDarkHalf.png'/>":"<img src='images/game/stars/starLightHalf.png'/>"}else{d+=c?"<img src='images/game/stars/starDarkEmpty.png'/>":"<img src='images/game/stars/starLightEmpty.png'/>"}}}return d};mesa.game.getStarsText=function(a){if(a<=2){return"NOOB"}else{if(a<=4){return"OKAY"}else{if(a<=6){return"DECENT"}else{if(a<=8){return"STRONG"}else{return"EXCELLENT"}}}}};