mesa.chat.Client=new function(z){var f=new Template('<div class="playerName">#{name}</div><div class="chatText">#{msg}</div><div class="clear"></div>');var i=new Template('<div class="playerName" style="color:#900B09">System</div><div class="chatText" style="color:#900B09">#{msg}</div><div class="clear"></div>');var n={};var d={msg:"We are unable to save your message at the moment, please try again later and sorry for the inconvenience!"};var j=true;var M=false;var g=false;var k=0;var N=0;var m,c,K,o;var G,J,C,F,r;var l;var t;var y=new Array();var q=1.4;var a=0;var H=0;var h=false;var E=0;var I=12;var p=0;var A=0;var u=0;var s=0;var e=true;var L=0;var v=0;this.init=function(P,O){c=P;K=O;G=$(K.dialogPanel);J=$(K.chatContainer);C=$(K.inputPanel);F=$(K.inputBox);r=$(K.channelPanel);t=$(K.measureLine);k=0;if(mesa.game.SocialNetwork.FACEBOOK==K.socialNetwork){getLoginUserId(K.sessionId,K.socialNetwork,function(Q){w()})}Event.observe(document,"keyup",function(Q){if(Event.KEY_RETURN==Q.keyCode){F.focus();if("Click here or press enter to chat"!=F.value){saveChatLine()}else{F.value=""}}});setChatter();getChatLine()};this.switchChannel=function(O){switchChannel(O)};this.hideChat=function(){J.hide()};this.showChat=function(){J.show()};this.toggleInput=function(){toggleInput()};this.saveChatLine=function(){saveChatLine()};this.focusInputBox=function(){F.focus()};saveChatLine=function(){var O=F.value;if(!g&&!O.blank()){g=true;new mesa.Ajax.Request(K.mesaBasePath+"chat/saveChatLine.do",{socialNetwork:K.socialNetwork,msg:O},function(P){F.value="";g=false;getChatLine()},function(P){g=false;d.msg=P;showError(d)}).send()}};toggleInput=function(){C.toggle();if(""!=F.value){F.value=""}if(F.visible()){F.focus()}};getLoginUserId=function(R,O,Q){var P="";if(mesa.game.SocialNetwork.SOSAUCE==O){P=K.mesaBasePath+"user/getSessionUser.do"}else{if(mesa.game.SocialNetwork.FACEBOOK==O){P=K.mesaBasePath+"user/loginViaFacebook.do"}}new mesa.Ajax.Request(P,{sessionId:R},Q,function(S){}).send()};function w(){new mesa.Ajax.Request(K.mesaBasePath+"user/getSessionUser.do",null,function(){setTimeout(w,5*60*1000)}).send()}getChatLine=function(){if(!M){M=true;clearTimeout(o);new mesa.Ajax.Request(K.mesaBasePath+"chat/getChatLine.do",{chatLineId:k},function(O){if(O!=null){if(N!=O.channel.id){N=O.channel.id;var Q=O.channel.name.escapeHTML();r.innerHTML=Q+" chat"}if(O.msgList.length>0){for(var P=0;P<O.msgList.length;P++){createNewChatLine(O.msgList[P])}k=O.msgList[O.msgList.length-1].id}}M=false;o=setTimeout(getChatLine,5000)},function(O){M=false;o=setTimeout(getChatLine,5000);d.msg=O;showError(d)}).send()}};createNewChatLine=function(O){if("object"==typeof(O)){if(O.guest!=null&&O.guest.name!=null){n.name=O.guest.name.escapeHTML()}else{if(O.user!=null){if(O.user.name!=null){n.name=O.user.name.escapeHTML()}}}n.id=O.id;n.msg=O.msg.escapeHTML()}else{n.name=K.userInfo.firstName;n.msg=O}var P=document.createElement("div");P.className=j?"message oddMessage":"message evenMessage";P.innerHTML=f.evaluate(n);G.appendChild(P);y.push(P);x();j=!j};showError=function(O){var P=document.createElement("div");P.className="message";P.innerHTML=i.evaluate(O);G.appendChild(P)};switchChannel=function(O){var P=O.escapeHTML();r.innerHTML=P+" chat";G.innerHTML="";k=0;getChatLine()};setChatter=function(){if(K.chatter){if(K.userInfo&&K.userInfo.firstName){var O=K.userInfo.firstName;if(K.userInfo.lastName){O=O+K.userInfo.lastName}$(K.chatter).innerHTML=O}}};function D(){A=y.length;u=G.getHeight();v=t.getHeight()}function x(){A=y.length;if(!e){var O=(y[A-1]).getHeight();E=E+O;G.style.top=(E+"px")}else{I=A-1}}function B(){I==A-1;E=parseInt(G.style.top,10);a=0;H=0;if(!h){setTimeout(b,10);h=true}e=true}function b(){if(H<10){var O=a-E;E=(E+O/2);G.style.top=(E+"px");H++;setTimeout(b,40)}else{G.style.top=(a+"px");h=false}}this.setScroll=function(O){D();if(A>0){if(O=="up"){if(I>0){if(e){e=false}var P=(Position.positionedOffset(y[I-1]));p=u-P[1];E=parseInt(G.style.top,10);if(p<a+1.5*v){a=p;I-=1}else{a=E+v}H=0;if(!h){setTimeout(b,10);h=true}}}else{if(O=="down"){if(I<A-1){var P=(Position.positionedOffset(y[I+1]));p=u-P[1];E=parseInt(G.style.top,10);if(p>a-1.5*v){a=p;I+=1}else{a=E-v}H=0;if(!h){setTimeout(b,10);h=true}}else{if(I==A-1){B()}}}}}}}();
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"}}}}};
var BarChooser=new function(){var a=170;var i=0;var d;var g=0;var b=0;var h=false;var e=0;var c={games:6,display:4,width:150,height:25,background:"#f4f4f4"};this.init=function(j){c=j;a=c.width+20};function f(){if(b<100){var j=g-e;e=(e+j/8);d.style.left=(e+"px");b++;setTimeout(f,20)}else{d.style.left=(g+"px");h=false}}this.setChooser=function(j){if(j=="left"){if(i>0){i-=1;d=document.getElementById("gameBrowseItems");g=i*-a;e=parseInt(d.style.left,10);b=0;if(!h){setTimeout(f,20);h=true}}}else{if(j=="right"){if(i<c.games-c.display){i+=1;d=document.getElementById("gameBrowseItems");g=i*-a;e=parseInt(d.style.left,10);b=0;if(!h){setTimeout(f,20);h=true}}}}}}();
mesa.Achievement=new function(){this.loadAchievements=function(a,c){var b=this;this.gameTitle=c;new mesa.Ajax.Request("game/loadAchievements.do",{gameId:a},function(d){$("achvContent").innerHTML=mesa.WebUtils.applyTemplate("achievement",{achvs:d,gameTitle:b.gameTitle})}).send()};this.updateUI=function(b){var c=$("userTokens");if(c){c.innerHTML=b.credits}var a=$(b.achvName);if(a){a.innerHTML='<div class="achievementBadgeDone"><img class="'+b.achvName+'"/></div><div class="clear"></div>'}}};
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/"}};