var LearnMode=StudyMode.extend({initialize:function(d,c,a,b,e,g,f){this.remaining=d;
this.correct=c;this.incorrect=a;this.round=b;this.session=e;this.roundTotal=g;this.transports=[];
this.autofocus=f;this.sendSoon=false;$("accentwrap").getElements("input").each(function(h){h.addEvent("click",enterAccent)
});this.launch()},launch:function(){this.sendScore();if(this.remaining.length==0&&this.incorrect.length==0){return this.analyze()
}else{if(this.remaining.length==0){return this.newRound()}}this.curTerm=this.remaining.shift();
this.showing=$("term-first").checked?"word":"definition";this.hiding=this.showing=="word"?"definition":"word";
if(this.showing=="word"&&this.curTerm.definition==""){this.showing="definition";this.hiding="word"
}this.allowSymbols();$("learn-in").setOpacity(0).setHTML("").adopt(new Element("a",{events:{click:this.giveUp.bind(this)},"class":"giveup",href:"#"}).setHTML("Give Up"),new Element("h3").setHTML(this.display_item(this.curTerm,this.showing,"m")),new Element("input",{id:"user-answer","class":"value",events:{keydown:this.answerListen.bind(this)}}),new Element("span").setHTML(" &nbsp;"),new Element("input",{type:"submit",value:"Answer",events:{click:this.answerListen.bind(this)}}));
var a=new Fx.Style("learn-in","opacity",{duration:300,onComplete:this.autofocus?function(){var b=$("user-answer");
(function(){try{this.focus();this.focus()}catch(c){}}).delay(50,b);curInput=b}:function(){}});
a.start(0,1)},analyze:function(){$("learn-in").setHTML("<b>Loading...</b>");new Ajax(window.location.toString(),{data:{action:"analyze",session:this.session,pad:"1"},onComplete:function(a){new Fx.Style("learn-in","opacity",{duration:300}).start(0,1);
$("learn-in").setHTML(a)}}).request()},listenForAnyKey:function(a){new Element("a",{id:"anykey",href:"#",events:{click:function(b){new Event(b).stop();
document.onkeydown=function(){};a()}}}).setHTML("Press any key to continue").injectInside("learn-in");
document.onkeydown=function(b){b=new Event(b);el=b.target;if(el.value){return true
}Game.stopListening();a();b.stop()}},stopListening:function(){document.onkeydown=function(){}
},startNewRound:function(){this.round++;this.transfer("incorrect","remaining",this.incorrect.length);
this.roundTotal=this.incorrect.length;this.remaining=shuffle(this.incorrect);this.incorrect=[];
this.launch()},sendScore:function(){if(this.sendSoon!=false){this.transports[this.sendSoon.tid]=new Ajax(document.location.toString(),this.sendSoon).request();
this.sendSoon=false}},newRound:function(){this.disallowSymbols();$("learn-in").setHTML("			<table>				<tr> <th>End of Round</th> <th colspan='3' style='width: auto'>Round "+this.round+" Standings</th> </tr>				<tr>					<td id='roundNumber' rowspan='4'>"+this.round+"</td>					<td class='right-q'>Correct</td>					<td>"+(this.roundTotal-this.incorrect.length)+"</td>					<td>"+Math.round((this.roundTotal-this.incorrect.length)/this.roundTotal*100)+"%</td>				</tr>				<tr>					<td class='wrong-q'>Incorrect</td>					<td>"+(this.incorrect.length)+"</td>					<td>"+Math.round(this.incorrect.length/this.roundTotal*100)+"%</td>				</tr>				<tr>					<td class='right-q'>Overall Progress</td>					<td>"+(this.correct+" / "+(this.correct+this.incorrect.length))+"</td>					<td>"+Math.round(this.correct/(this.correct+this.incorrect.length)*100)+"%</td>				</tr>			</table>		");
this.listenForAnyKey(this.startNewRound.bind(this))},giveUp:function(a){if(a){new Event(a).stop()
}$("user-answer").value="";this.gradeAnswer();return false},toggleShowFirst:function(){if($("user-answer")){this.remaining.push(this.curTerm);
this.remaining=shuffle(this.remaining);this.launch()}},answerListen:function(a){a=new Event(a);
if(a.type=="click"){a.target.removeEvents("click");this.gradeAnswer()}else{if(a.key=="enter"){a.target.removeEvents("keypress");
this.gradeAnswer()}else{if(a.key=="esc"){a.target.removeEvents("keypress");this.giveUp()
}}}},gradeAnswer:function(){var f=$("user-answer").value.trim(),a=this.curTerm[this.hiding],b=f.matches(a),c=this.curTerm.can_edit?"<a href='#' class='editlink' onclick='return Game.startEdit()'>Edit</a>":(this.session?'<span class="editlink">not editable</span>':"");
this.disallowSymbols();if(b){this.correct++;this.transfer("remaining","correct");
$("learn-in").setHTML("				"+c+"				<h3 class='correct'>CORRECT</h3>				<table>					<tr><th>Prompt</th><td>"+this.display_item(this.curTerm,this.showing,"m")+"</td></tr>					<tr><th>Correct</th><td class='right-q'>"+htmlescape(a)+"</td></tr>				</table>			");
this.listenForAnyKey(this.launch.bind(this))}else{this.incorrect.push(this.curTerm);
this.transfer("remaining","incorrect");if(f!=""){var e=diffString2(f,a);$("learn-in").setHTML("					"+c+"					<h3 class='incorrect'>INCORRECT</h3>					<table>						<tr><th>Prompt</th><td>"+this.display_item(this.curTerm,this.showing,"m")+"</td></tr>						<tr><th>You said</th><td class='wrong-q'>							<a href='#' id='override' onclick='return Game.wrongOverride()'>Override: I was right</a>							"+e.o+"							</td></tr>						<tr><th>Correct</th><td class='right-q'>"+e.n+"</td></tr>					</table>				");
this.listenForAnyKey(this.launch.bind(this))}else{$("learn-in").setHTML("					"+c+"					<h3 class='incorrect'>Copy the answer</h3>					<table>						<tr><th>Prompt</th><td>"+this.display_item(this.curTerm,this.showing,"m")+"</td></tr>						<tr><th>Answer</th><td class='right-q'>"+htmlescape(a)+"</td></tr>						<tr><th>Copy the answer</th><td class='wrong-q'><input id='copyanswer' class='value' type='text' /></td></tr>					</table>				");
curInput=$("copyanswer");curInput.addEvent("keyup",function(g){el=new Event(g).target;
if(el.value.matches(this.curTerm[this.hiding])){el.parentNode.className="right-q";
el.disabled=true;el.removeEvents();this.launch.delay(1100,this)}}.bind(this));(function(){this.focus();
this.focus()}).delay(50,curInput);this.allowSymbols()}}if(this.session){var d=""+$random(0,99999)+this.round+this.curTerm.id;
this.sendSoon={tid:d,data:{action:"addGrade",quiz_id:this.curTerm.quiz_id,word_id:this.curTerm.id,round:this.round,session:this.session,correct:b?"1":"0",pad:"x"},onComplete:this.verifyServer.bind(this,d),timeout:this.badConnection.delay(10000,this)};
if(b){this.sendScore()}}},wrongOverride:function(){if(this.session){this.sendSoon.data.correct="1"
}this.correct++;this.incorrect.pop();this.transfer("incorrect","correct");this.stopListening();
this.launch();return false},badConnection:function(){},startEdit:function(){this.allowSymbols();
this.stopListening();$("learn-in").setHTML("			<form onsubmit='return Game.saveEdit()'>			<h3>Edit Term</h3>			<table class='editing'>				<tr>					<th>Term</th>					<td><input type='text' id='editTerm' onfocus='curInput=this;' class='value' value='"+QTerm.display_item(this.curTerm,"word")+"' /></td></tr>				<tr>					<th>Definition</th>					<td>"+QTerm.display_item(this.curTerm,"photo_only","sm")+"<input type='text' id='editDefinition' onfocus='curInput=this;' class='value' value='"+QTerm.display_item(this.curTerm,"definition_only")+"' /></td>				</tr>				<tr><th><input type='submit' value='Cancel' onclick='return Game.cancelEdit()' /></th><th style='width: auto'><input type='submit' value='Save' /></th></tr>			</table>			</form>		");
(function(){var a=$("editTerm");a.focus();a.focus()}).delay(50);return false},saveEdit:function(){var c={action:"saveEdit",word_id:this.curTerm.id,id:this.curTerm.quiz_id},b=false,a=$("editTerm").value.trim(),e=$("editDefinition").value.trim();
if(hasBadWords(a)||hasBadWords(e)){return false}if(a!=""&&a!=this.curTerm.word){c.term=a;
this.curTerm.word=a;b=true}if(e!=""&&e!=this.curTerm.definition){c.def=e;this.curTerm.definition=e;
b=true}if(b){$("learn-in").setHTML("<h3 class='correct'>Loading</h3>");new Ajax("/edit.php",{data:c,onComplete:this.editComplete.bind(this)}).request()
}else{this.cancelEdit()}return false},editComplete:function(){$("learn-in").setHTML("<h3 class='correct'>Edit Saved</h3>");
this.listenForAnyKey(this.launch.bind(this))},cancelEdit:function(){this.launch();
return false},verifyServer:function(a){$clear(this.transports[a].options.timeout);
this.transports[a]=null},allowSymbols:function(){var a=$("show-symbols");if(a.checked){$("symbols").setStyle("height","")
}a.disabled=false},disallowSymbols:function(){var a=$("show-symbols");if(a.checked){$("symbols").setStyle("height",0)
}a.disabled=true},toggleSymbols:function(){new Fx.Height("symbols",{duration:300}).toggle();
if($("show-symbols").checked){Cookie.set("showAccents","true",{path:"/"})}else{Cookie.remove("showAccents")
}},toggleSymbolCase: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"
}$("symbols").getElements("input").each(b);return false},transfer:function(g,f,a){var g=$(g+"-count"),f=$(f+"-count"),a=a||1,c=g.getPosition(),e=f.getPosition(),b=this.remaining.length+this.incorrect.length+this.correct,d=$("bullet");
now=parseInt(g.innerHTML)-a,wview=parseInt(g.className.replace(/wview/,""));g.innerHTML=now;
new Fx.Style(g,"paddingLeft").start(5+Math.round(now/b*wview));d.setStyle("visibility","visible");
new Fx.Style(d,"top",{duration:1000}).start(c.y,e.y);new Fx.Style(d,"left",{duration:500,transition:Fx.Transitions.Expo.easeOut}).start(c.x,c.x-15).chain(function(){new Fx.Style(d,"left",{duration:500,transition:Fx.Transitions.Expo.easeIn}).start(c.x-15,c.x).chain(function(){var i=parseInt(f.innerHTML)+a,h=parseInt(g.className.replace(/wview/,""));
new Fx.Style(f,"paddingLeft").start(5+Math.round(i/b*h));f.innerHTML=i})})}});function htmlescape(a){var b=a;
b=b.replace(/&/g,"&amp;");b=b.replace(/</g,"&lt;");b=b.replace(/>/g,"&gt;");b=b.replace(/"/g,"&quot;");
return b}function diffString2(b,c){b=b.replace(/\s+$/,"");c=c.replace(/\s+$/,"");
var e=diff(b==""?[]:b.split(/\s+/),c==""?[]:c.split(/\s+/)),j=b.match(/\s+/g),g=c.match(/\s+/g),d="",h="",a=[],f;
if(j==null){j=["\n"]}else{j.push("\n")}if(g==null){g=["\n"]}else{g.push("\n")}for(f=0;
f<e.o.length;f++){if(e.o[f].text!=null){d+=htmlescape(e.o[f].text)+j[f]}else{d+="<del>"+htmlescape(e.o[f])+j[f]+"</del>"
}}for(f=0;f<e.n.length;f++){if(e.n[f].text!=null){h+=htmlescape(e.n[f].text)+g[f]
}else{h+="<ins>"+htmlescape(e.n[f])+g[f]+"</ins>"}}return{o:d,n:h}}function diff(d,e){var b={},c={},a;
for(a=0;a<e.length;a++){if(b[e[a]]==null){b[e[a]]={rows:[],o:null}}b[e[a]].rows.push(a)
}for(a=0;a<d.length;a++){if(c[d[a]]==null){c[d[a]]={rows:[],n:null}}c[d[a]].rows.push(a)
}for(a in b){if(b[a].rows.length==1&&typeof(c[a])!="undefined"&&c[a].rows.length==1){e[b[a].rows[0]]={text:e[b[a].rows[0]],row:c[a].rows[0]};
d[c[a].rows[0]]={text:d[c[a].rows[0]],row:b[a].rows[0]}}}for(a=0;a<e.length-1;a++){if(e[a].text!=null&&e[a+1].text==null&&e[a].row+1<d.length&&d[e[a].row+1].text==null&&e[a+1].matches(d[e[a].row+1])){e[a+1]={text:e[a+1],row:e[a].row+1};
d[e[a].row+1]={text:d[e[a].row+1],row:a+1}}}for(a=e.length-1;a>0;a--){if(e[a].text!=null&&e[a-1].text==null&&e[a].row>0&&d[e[a].row-1].text==null&&e[a-1].matches(d[e[a].row-1])){e[a-1]={text:e[a-1],row:e[a].row-1};
d[e[a].row-1]={text:d[e[a].row-1],row:a-1}}}return{o:d,n:e}};