var Term=StudyMode.extend({initialize:function(a){this.curTerm=a;this.duration=13000;
this.now=0;this.el=new Element("div").setHTML(this.getPrompt("m")).addClass("free").injectInside("space");
var b=$("space"),c=this.el.offsetWidth;if(c>300){c=300}b.setStyle("width",b.offsetWidth+"px");
this.el.setStyle("width",c+"px");this.x=-c;this.y=$random(b.getTop(),$("land").getTop()-this.el.offsetHeight);
this.el.setStyles({width:c+"px",top:this.y+"px",left:this.x+"px"});this.advancer=new Fx.Style(this.el,"left",{duration:this.duration,transition:Fx.Transitions.linear,onComplete:this.die.bind(this)});
this.maxX=window.getWidth();this.play()},getPrompt:function(c){var b=$("the-prompt"),a=b.options[b.selectedIndex].value;
if(a=="random"){a=$random(0,1)==0?"word":"definition"}if(a=="word"&&this.curTerm.definition==""){a="definition"
}this.showing=a;return this.display_item(this.curTerm,a,c)},getAnswer:function(){return this.showing=="word"?this.curTerm.definition:this.curTerm.word
},die:function(){this.pause();Game.memorial(this)},kill:function(){this.pause();new Fx.Styles(this.el,{duration:300}).start({top:[this.y,this.y+20],opacity:[0.99,0]}).chain(function(){this.el.remove()
}.bind(this))},pause:function(){var a=Math.round((this.advancer.now||0)/this.maxX*this.duration);
this.advancer.stop();this.advancer.options.duration=this.duration-a},rewind:function(b,a){this.advancer.stop();
new Fx.Style(this.el,"left",{duration:a,transition:Fx.Transitions.linear,onComplete:this.pause.bind(this)}).start(this.advancer.now-b);
this.advancer.now-=b},play:function(){this.advancer.start(this.maxX)}});var SpaceRace=new Class({initialize:function(a){this.qnonce=a.qnonce;
this.session=a.session;this.ids=a.ids;this.allterms=a.terms;this.terms=[];this.usedUp=[];
this.level=1;this.lives=2;this.points=0;this.kills=0;this.paused=false;this.consecutiveKills=0;
this.lastLaunch=0;this.showingMessage=false;this.status="new";this.startPeriod=8200;
this.speedup=300;if(Cookie.get("showAccents")){this.toggleSymbols($("symboltoggler"))
}},start:function(){if(this.showingMessage){this.hideMessage();this.newTimer.delay(400,this)
}else{this.newTimer()}var a=$("playagain");if(a){a.onclick=function(){return false
}}this.status="in progress";var b=$("gun");curInput=b;b.onkeydown=this.thumbTrigger.bind(this);
b.value="";b.disabled=false;b.focus();$("pauser").removeClass("dnone").onclick=this.pause.bind(this);
$("restarter").removeClass("dnone").onclick=this.restart.bind(this);$("instructionser").removeClass("dnone").onclick=this.showInstructions.bind(this);
$("highscoreser").removeClass("dnone").onclick=this.showHighScores.bind(this);$("accents").getElements("input").each(function(c){c.onclick=enterAccent
})},showHighScores:function(){this.pause();new Ajax(window.location.toString(),{data:{action:"high_scores",id:this.ids},method:"get",onComplete:function(a){this.showMessage(function(){$("messagebox").setHTML(a);
if(this.status=="in progress"){var b=new Element("a").setProperty("href","#").setProperty("id","playagain").setHTML("Continue Playing");
b.onclick=this.play.bind(this);$("messagebox").adopt(b)}else{var b=new Element("a").setProperty("href",window.location.toString()).setProperty("id","playagain").setHTML("Play Again");
$("messagebox").adopt(b)}}.bind(this))}.bind(this)}).request();return false},launchNew:function(){if(this.allterms.length==0){if(this.usedUp.length!=0){this.allterms=shuffle(this.usedUp);
this.usedUp=[]}else{return false}}this.lastLaunch=new Date().getTime();this.terms.push(new Term(this.allterms.pop()))
},thumbTrigger:function(a){var a=new Event(a);if(this.paused&&!this.showingMessage){this.play()
}if(a.key=="enter"){this.fire()}},fire:function(){var e=$("gun"),c=trim(e.value),b=this.kills,d=0,a=this.terms.length;
e.value="";for(d=0;d<a;d++){if(c.matches(this.terms[d].getAnswer())){this.hit(d);
return true}}if(b==this.kills&&c!=""){this.miss(d)}return false},hit:function(a){this.kills++;
$("killvalue").setHTML(this.kills);if(this.kills%5==0){this.levelUp()}this.terms[a].kill();
this.removeTerm(a);this.addPoints(this.getPoints());this.consecutiveKills++},removeTerm:function(a){this.usedUp.push(this.terms[a].curTerm);
this.terms.splice(a,1)},miss:function(a){this.consecutiveKills=0;this.addPoints(-10)
},levelUp:function(){this.level++;$("levelvalue").setHTML(this.level);var a=new Element("span").setHTML("Level "+this.level+"").setProperty("id","levelStatus").addClass("correct").injectInside("space");
this.addLives(1);ef=a.effect("opacity",{duration:800,onComplete:function(){a.remove()
}});ef.start.pass([1,0],ef).delay(1000,ef);this.paused=true;this.pauseTime=new Date().getTime();
this.newTimer()},getPoints:function(){return this.level*100+10*this.consecutiveKills
},newTimer:function(){$clear(this.timer);var a=this.startPeriod-this.level*this.speedup;
if(this.paused){this.paused=false;this.timer=this.newTimer.delay(a-(this.pauseTime-this.lastLaunch),this)
}else{this.launchNew();this.timer=this.launchNew.periodical(a,this)}},pause:function(){this.paused=true;
curInput=null;$clear(this.timer);this.pauseTime=new Date().getTime();$("gun").disabled=true;
if(this.status!="new"){this.terms.each(function(a){a.pause()})}$("pauser").setHTML("Play").onclick=this.play.bind(this);
return false},play:function(){if(this.status=="finalbow"){return this.gameOver()}if(this.status=="over"){return false
}if(this.status=="loading"){alert("Sorry, still loading everything");return false
}curInput=$("gun");curInput.disabled=false;if(this.showingMessage){this.hideMessage();
this.playNow.delay(400,this)}else{this.playNow()}return false},playNow:function(){this.terms.each(function(a){a.play()
});$("pauser").setHTML("Pause").onclick=this.pause.bind(this);$("gun").focus();this.newTimer();
return false},addPoints:function(a){this.points+=a;$("scorevalue").setHTML(this.points)
},addLives:function(c){this.lives+=c;if(this.lives>4){b="&hearts; &times; "+this.lives
}else{if(this.lives>0){var b="";for(var a=0;a<this.lives;a++){b+=" &hearts;"}}else{b="Ø"
}}$("livesvalue").setHTML(b)},memorial:function(a){this.removeTerm(0);this.consecutiveKills=0;
this.addLives(-1);if(this.lives==0){this.status="finalbow"}this.deadTerm=a;this.pause();
this.showMessage(this.printAnswer.pass(a,this))},printAnswer:function(b){var d=new Element("input").addClass("value"),a=b.getPrompt("t");
$("messagebox").setHTML("").adopt(new Element("h2").appendText("Copy the answer"),new Element("p").setHTML(a+" &rarr; "+b.getAnswer()),new Element("p").setHTML(a+" &rarr; ").adopt(d));
d.addEvent("keyup",this.checkTyping.pass(d,this)).setStyle("font-weight","bold").setStyle("color","#b00");
var c=$("gun");(function(){this.blur()}).delay(100,c);(function(){this.focus();curInput=this
}).delay(100,d)},checkTyping:function(d){if(d.value.matches(this.deadTerm.getAnswer())){d.removeEvents();
d.setStyle("color","#01921B");var c=trim($("gun").value);var f=false;for(var e=0,b=this.terms.length;
e<b;e++){var a=reduceStrings(c,this.terms[e].getAnswer());if(a[1].indexOf(a[0])==0){f=true
}}if(!f){$("gun").value=""}(function(){this.deadTerm=null;this.hideMessage();curInput=$("gun");
this.play()}).delay(500,this)}},gameOver:function(){$("gun").value="GAME OVER";$("gun").blur();
this.pause();if(this.points>0&&this.session!=0){new Ajax(window.location.toString().split("#")[0],{data:{action:this.obfuscate(Object.toQueryString({session:this.session,score:this.points,qnonce:this.qnonce}))},onComplete:function(a){this.showMessage(function(){$("messagebox").setHTML(a)
})}.bind(this)}).request()}else{this.showHighScores()}$("pauser").addClass("dnone")
},obfuscate:function(d){var c="";for(var b=0,a=d.length;b<a;b++){c+="-"+(d.charCodeAt(b)+77%(b+1))
}return c.substr(1)},showInstructions:function(a){if(this.status=="in progress"){this.pause()
}this.showMessage(function(){var b=this.lastLaunch==0;$("messagebox").setHTML("				<h2>Instructions</h2>				<p>"+this.instructionsText()+"</p>				<a href='#' onclick='"+(b?"Game.start();":"Game.play();")+" return false;' id='playagain'>"+(b?"Start Playing":"Continue Playing")+"</a>			")
}.bind(this));return false},instructionsText:function(){return"Kill the scrolling words by typing in their corresponding term and pressing <strong>enter</strong>. You may kill them in any order, but make sure they don't scroll past the screen."
},hideMessage:function(b){if(this.showingMessage){this.showingMessage=false;$("space").effect("opacity").start(0.5,1);
var a=$("space").getTop();new Fx.Styles("messagewrap").start({top:[a-20,a],opacity:[1,0]}).chain($type(b)=="function"?b:Class.empty)
}return false},showMessage:function(b){var a=function(){b();this.showingMessage=true;
var c=$("space").getTop();$("space").effect("opacity").start(1,0.5);new Fx.Styles("messagewrap").start({top:[c-40,c-20],opacity:[0,1]})
}.bind(this);if(this.showingMessage){this.hideMessage(a)}else{a()}return false},restart:function(){var a=this.paused;
if(!this.paused){this.pause()}if(a||(!a&&confirm("Are you sure you want to restart?"))){window.location.reload(true)
}else{if(!a){this.play()}}return false},highScorePaging:function(a){$$("#messagebox div").each(function(b){b.addClass("dnone")
});$("highScores"+a).removeClass("dnone");return false},toggleSymbols:function(a){if(a.innerHTML=="Show Symbols"){a.innerHTML="Hide Symbols";
Cookie.set("showAccents","true",{path:"/"})}else{a.innerHTML="Show Symbols";Cookie.remove("showAccents")
}if(swrap=$("accents")){new Fx.Height(swrap,{duration:300}).toggle()}return false
},toggleCase:function(a){if(a.innerHTML=="Uppercase"){var b=function(c){c.value=c.value.toUpperCase()
};a.innerHTML="Lowercase"}else{var b=function(c){c.value=c.value.toLowerCase()};a.innerHTML="Uppercase"
}$("accentwrap").getElements("input").each(b);return false},customizeSymbols:function(){var a=this.paused;
if(!a){this.pause();customize_symbols();symbolCallback=this.play.bind(this)}else{customize_symbols();
symbolCallback=null}return false}});var symbolCallback;