text: !function(){var e,t="060316",n=document.querySelector("#footer"),o=document.querySelector("#mainContent"),i=document.querySelector("#addAdvancementButton"),a=document.querySelector("#showSettingsModalButton"),r=document.querySelector("#settingsModal"),c=document.querySelector("#normalViewButton"),s=document.querySelector("#compactViewButton"),d=document.querySelector("#resetButton"),m=document.querySelector("#resetGameModal"),u=m.querySelector("#resetModalYesButton"),l=m.querySelector("#resetModalCancelButton"),f=document.querySelector("#newAdvancementModal"),g=document.querySelector("#numberOfOutcomes"),v=document.querySelector("#showAdvancementModal"),h=document.querySelector("#outcomeResultModal"),y=h.querySelector("#outcomeContent"),S=h.querySelector("#shuffleOutcomesButton"),b=h.querySelector("#removeOutcomeButton"),p={nasa:{name:"NASA",bgColor:"#0099ff",fgColor:"#fff"},okb1:{name:"&#1054;&#1050;&#1041;-1",bgColor:"#ff4d4d",fgColor:"#fff"},sac:{name:"SAC",bgColor:"#ffff66",fgColor:"#000"},cnes:{name:"CNES",bgColor:"#737373",fgColor:"#fff"},isas:{name:"ISAS",bgColor:"#f2f2f2",fgColor:"#000"}},w=document.querySelector("#blanket"),L=navigator.userAgent.indexOf("iPhone")>-1||navigator.userAgent.indexOf("iPad")>-1?"touchend":"click",k={},D=function(e){var t,n,o;for(t=e.length-1;t>0;t--)n=Math.floor(Math.random()*(t+1)),o=e[t],e[t]=e[n],e[n]=o;return e},E=function(){var e,t=[];for(e=1;90>=e;e++)t.push(e);return D(t)},M=function(){return{version:t,config:{mode:"normal"},currentPlayer:"nasa",outcomesDeck:E(),discardDeck:[],players:{nasa:{advancements:{}},okb1:{advancements:{}},sac:{advancements:{}},cnes:{advancements:{}},isas:{advancements:{}}}}},q=function(){var t=document.documentElement.clientWidth,n=e.config;"normal"===n.mode&&(n.containerWidth=350>t?t-25:325,n.outcomeMargin=25,n.outcomeDimension=n.containerWidth/2-60,n.advancementMargin=n.outcomeDimension+40,n.advancementFontSize="20px"),"compact"===n.mode&&(n.containerWidth=185>t?t-25:160,n.outcomeMargin=20,n.outcomeDimension=n.containerWidth/2-50,n.advancementMargin=n.outcomeDimension+25,n.advancementFontSize="12px"),n.containerHeight=n.containerWidth/2,n.dialogWidth=350>t?t-25:325,n.advancementHeight=n.containerHeight-40,n.advancementWidth=n.containerWidth-25,n.maximumOutcomes={Surveying:1}},C=function(t){var n=t.querySelector(".close");n.removeEventListener(L,F),n.addEventListener(L,F),t.style.width=e.config.dialogWidth+"px",t.style.bottom="50%",t.style.left="50%",t.style.marginBottom="-"+t.offsetHeight/2+"px",t.style.marginLeft="-"+t.offsetWidth/2+"px",t.style.visibility="visible"},x=function(e){var t,n,o=f.querySelectorAll("span");for(t in e.advancements)if(e.advancements.hasOwnProperty(t))for(n=0;n<o.length;n++)e.advancements[t].name===o[n].getAttribute("data-name")&&-1===o[n].className.indexOf("disabled")&&W(o[n],"disabled")},A=function(){w.style.visibility="visible",R(),W(g.querySelector('[data-number="3"]'),"selected"),x(e.players[e.currentPlayer]),C(f)},O=function(){w.style.visibility="visible",C(m)},P=function(){window.Storage&&window.localStorage.removeItem("storedState"),window.location.reload()},N=function(e,t){e.className=e.className.replace(new RegExp(t,"g"),"").replace(/\s$/,"")},W=function(e,t){e.className+=" "+t},B=function(){var e,t,n=document.querySelectorAll("svg"),o=document.querySelectorAll("#newAdvancementModal span.disabled");for(e=0,t=n.length;t>e;e++)SVG(n[e]).remove();for(e=0,t=o.length;t>e;e++)N(o[e],"disabled");k={},Z()},H=function(t){e.currentPlayer=t.target.id,F(),B(),ee()},F=function(){var e,t=document.querySelectorAll(".modal");for(e=0;e<t.length;e++)t[e].style.visibility="hidden";w.style.visibility="hidden"},I=function(){var e=function(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},R=function(){var e=g.querySelector("span.selected"),t=g.querySelector("span.warning");e&&N(e,"selected"),t&&N(t,"warning")},V=function(t){var n,o,i,a,r=t.target,c=I(),s=g.querySelector("span.selected");if(r.className.indexOf("advancement")>-1&&-1===r.className.indexOf("disabled"))if(i=e.config.maximumOutcomes[r.getAttribute("data-name")],o=s.getAttribute("data-number"),o>i)n=g.querySelector('[data-number="'+i+'"]'),-1===n.className.indexOf("warning")&&W(n,"warning");else{if(e.outcomesDeck.length+e.discardDeck.length<o)return F(),void R();a={player:e.currentPlayer,id:c,name:r.getAttribute("data-name"),outcomes:[],maxLength:o,finalRevealed:!1},e.players[e.currentPlayer].advancements[c]=a,k[c]=new X(a),F(),R(),Z()}r.className.indexOf("number")>-1&&-1===r.className.indexOf("selected")&&(R(),W(r,"selected"))},z=function(){T(),w.style.visibility="visible",C(r)},T=function(){"normal"===e.config.mode&&(N(c,"disabled"),W(s,"disabled")),"compact"===e.config.mode&&(N(s,"disabled"),W(c,"disabled"))},G=function(){T(),B(),ee()},j=function(t){"normalViewButton"===t.target.id&&"compact"===e.config.mode&&(e.config.mode="normal",G()),"compactViewButton"===t.target.id&&"normal"===e.config.mode&&(e.config.mode="compact",G()),t.target.id in p&&(t.target.id!==e.currentPlayer?H(t):F())},J=function(){i.addEventListener(L,A),a.addEventListener(L,z),f.addEventListener(L,V),r.addEventListener(L,j),d.addEventListener(L,O),u.addEventListener(L,P),l.addEventListener(L,F),w.addEventListener(L,F)},Y=function(){var t,n=e.players[e.currentPlayer].advancements;for(t in n)n.hasOwnProperty(t)&&(k[t]=new X(n[t]))},$=function(){e.outcomesDeck=D(e.discardDeck),e.discardDeck=[]},K=function(t){var n=SVG(o).size(e.config.containerWidth,e.config.containerHeight);return n.rect(e.config.advancementWidth,e.config.advancementHeight).attr({x:15,y:15,fill:"#fff",stroke:"#000"}).radius(3),n.text(t).attr({x:e.config.advancementMargin,y:e.config.outcomeMargin}).font({family:"Helvetica",size:e.config.advancementFontSize}),n.image("img/0.png").attr({width:e.config.outcomeDimension,height:e.config.outcomeDimension,x:e.config.outcomeMargin,y:e.config.outcomeMargin}),n},Q=function(t,n,o){var i;switch(t){case 2:i="img/3.png";break;case 1:i="img/2.png";break;case 0:i="img/1.png"}return{outcomeCard:n.rect(e.config.outcomeDimension,e.config.outcomeDimension).attr({x:e.config.outcomeMargin,y:e.config.outcomeMargin,fill:"#fff",stroke:"#000",id:o}).radius(3),outcomeImage:n.image(i).attr({width:e.config.outcomeDimension,height:e.config.outcomeDimension,x:e.config.outcomeMargin,y:e.config.outcomeMargin,id:o})}},U=function(){S.className.indexOf("disabled")>-1&&N(S,"disabled")},X=function(t){var n,o,i,a,r=this;for(this.player=t.player,this.outcomes=t.outcomes,this.maxLength=t.maxLength,this.name=t.name,this.finalRevealed=t.finalRevealed,this.id=t.id,this.showOutcomeResult=function(t){t.stopPropagation();var n,o=r.outcomesDeck.last().attr("outcome"),i=1===r.outcomesDeck.members.length,a=function(){y.innerHTML="Success!",i?(W(S,"disabled"),S.removeEventListener(L,s),w.addEventListener(L,d),n.removeEventListener(L,s),n.addEventListener(L,d)):w.addEventListener(L,s)},c=function(){w.addEventListener(L,s),76>o?y.innerHTML="Minor Failure!":91>o&&(y.innerHTML="Major Failure!")},s=function(){var t=r.id,o=[],a=0;i&&(r.showFinalCard(),e.players[e.currentPlayer].advancements[t].finalRevealed=!0),r.outcomesDeck.each(function(){o.push(this.attr("outcome"))}),o=D(o),r.outcomesDeck.each(function(){this.attr({outcome:o[a]}),a++}),Z(),n.removeEventListener(L,s),m()},d=function(){var t,i,a=r.id,c=[],s=0;for(r.outcomesDeck.last().remove(),r.outcomesDeck.members.pop(),t=r.outcomesDeck.members,i=0;i<t.length;i++)c.push(t[i].attr("outcome")),s+=1;e.players[e.currentPlayer].advancements[a].outcomes=c,e.players[e.currentPlayer].advancements[a].maxLength=s,e.discardDeck.push(o),Z(),n.removeEventListener(n,d),m()},m=function(){w.removeEventListener(L,s),w.removeEventListener(L,d),h.removeEventListener(L,d),S.removeEventListener(L,s),b.removeEventListener(L,d),w.addEventListener(L,F),F()};S.addEventListener(L,s),b.addEventListener(L,d),w.style.visibility="visible",U(),C(h),n=h.querySelector(".close"),n.removeEventListener(L,F),n.addEventListener(L,s),w.removeEventListener(L,F),61>o?a():c()},this.showFinalCard=function(){var e=1===this.outcomesDeck.members.length,t=this.outcomesDeck.last().attr("outcome"),n=76>t?"img/minor.png":"img/major.png";e&&this.outcomesDeck.last().get(1).load(n)},this.discardAdvancement=function(){var t,n;for(t=0,n=r.outcomes.length;n>t;t++)e.discardDeck.push(r.outcomes[t]);delete e.players[e.currentPlayer].advancements[r.id],B(),ee(),F()},this.setupShowAdvancementModal=function(){var e=v.querySelector(".modalContent"),t=v.querySelector("#cancelAdvancement"),n=v.querySelector("#discardAdvancement");t.addEventListener(L,F),n.addEventListener("click",r.discardAdvancement),e.innerHTML=r.name,w.style.visibility="visible",C(v)};this.outcomes.length<this.maxLength;)e.outcomesDeck.length||$(),this.outcomes.push(e.outcomesDeck.shift());for(this.outcomes=D(this.outcomes),this.advancementContainer=K(this.name),this.outcomesDeck=this.advancementContainer.set(),n=0,o=this.outcomes.length;o>n;n++)i=Q(n,this.advancementContainer,this.id),a=this.advancementContainer.group(),a.add(i.outcomeCard),a.add(i.outcomeImage),a.attr({id:this.id,outcome:this.outcomes[n],x:i.outcomeCard.x(),y:i.outcomeImage.y()}),this.outcomesDeck.add(a);this.finalRevealed===!0&&1===this.outcomesDeck.members.length&&this.showFinalCard(),this.outcomesDeck.on("click",this.showOutcomeResult),this.advancementContainer.on("click",this.setupShowAdvancementModal)},Z=function(){window.Storage&&(window.localStorage.removeItem("storedState"),window.localStorage.setItem("storedState",JSON.stringify(e)))},_=function(){var t=p[e.currentPlayer].bgColor,o=p[e.currentPlayer].fgColor;n.style.backgroundColor=t,n.style.color=o,a.innerHTML=p[e.currentPlayer].name},ee=function(){e=window.Storage&&window.localStorage.getItem("storedState")?JSON.parse(window.localStorage.getItem("storedState")):{},e.version!==t&&(e=M()),_(),q(),J(),Y(),Z()};ee(),FastClick.attach(document.body)}();