function play(id){window.location.href="/play/"+id;}
function openEditor(id){window.open("/edit?id="+(id||""),"lt_editor"+(id||""),"directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=yes,toolbar=no,width=560px,height=665px");}
function openTermsOfUse(){window.open("terms_of_use.html","lt_legal","width=560px,height=665px");}
function openPrivacy(){window.open("privacy.html","lt_legal","width=560px,height=665px");}
var searchBar={langs:[],changeListeners:[],init:function(){this.readCookie();this.updateBarLangs();if(this.checkAdvChanges()>0){this.highlightAdvSearchButton();}},readCookie:function(){this.clearSelectedLangs();var v=readCookie("langs");if(v&&v.length>0){var l0=v.split(","),l1;for(var i=0;i<l0.length;i++){l1=l0[i].split("|");this.addSelectedLang(l1[0],l1[1]);}}},writeCookie:function(){var v="";for(var i=0;i<this.langs.length;i++){if(i>0){v+=",";}
v+=this.langs[i].lang;if(this.langs[i].level){v+="|"+this.langs[i].level;}}
createCookie("langs",v,120);},updateLangs:function(){var self=this;this.clearSelectedLangs();$("#lt-lang-select-form input[name=lang]:checked").each(function(){var lang=$(this).val();var level=parseLevelImageURL($(this).prev().find("img.level").attr("src"));self.addSelectedLang(lang,(level=="all")?null:level);});this.writeCookie();this.updateBarLangs();},addSelectedLang:function(lang,level){var obj=this.findSelectedLang(lang);if(obj){obj.level=level;}else{this.langs[this.langs.length]=obj={"lang":lang};if(level){obj.level=level;}}
return obj;},findSelectedLang:function(lang){for(var i=0;i<this.langs.length;i++){if(this.langs[i].lang==lang){return this.langs[i];}}
return null;},clearSelectedLangs:function(){this.langs.length=0;},updateBarLangs:function(){var N=2;var out="";if(this.langs.length>0){for(var i=0;i<this.langs.length&&i<N;i++){if(i>0){out+=",&nbsp;";}
out+="<img class='flag' src='/images/flags/"+this.langs[i].lang+".png' />"+
LANGUAGES[this.langs[i].lang];if(this.langs[i].level){out+="<img class='level' src='"+formatLevelImageURL(this.langs[i].level)+"' />";}}
if(this.langs.length>N){out+=",&nbsp;<b>...</b>";}}else{out+="All Languages";}
$("#lt-search-langs span:first-child").html(out);},showLangSelectBox:function(){var self=this;$("#lt-lang-select-form input[name=lang]:checkbox").each(function(){var lang=self.findSelectedLang($(this).val());if(lang==null){$(this).attr("checked",false);$(this).parent().removeClass("selected");$(this).prev().hide().find("img.level").attr("src",formatLevelImageURL(null));}else{$(this).attr('checked',true);$(this).parent().addClass("selected");$(this).prev().show().find("img.level").attr("src",formatLevelImageURL(lang.level));}});$("#lt-lang-select-box").show("blind",{direction:"vertical"},100);$("#lt-search-langs").addClass("on");},hideLangSelectBox:function(){this.updateLangs();$("#lt-lang-select-box").hide("blind",{direction:"vertical"},100);$("#lt-search-langs").removeClass("on");if(this.changes){this.notifyChanges();this.changes=false;}},toggleLangSelectBox:function(){if($("#lt-lang-select-box").is(":visible")){this.hideLangSelectBox();}else{this.showLangSelectBox();}},checkLangItem:function(item){if($(item).hasClass("selected")){$(item).removeClass("selected");$(item).find("input[name=lang]").attr("checked",false);$(item).find("div.level").hide();}else{$(item).addClass("selected");$(item).find("input[name=lang]").attr("checked",true);$(item).find("div.level").show();}
this.updateLangs();this.changes=true;},changeLangLevel:function(e){var level=parseLevelImageURL($(e).find("img.level").attr("src"));if(level){var li=LEVELS.indexOf(level);if(li!=-1){li=(li+1)%LEVELS.length;$(e).find("img.level").attr("src",formatLevelImageURL(LEVELS[li]));}}
this.updateLangs();this.changes=true;},showAdvancedSearchBox:function(){$("#lt-advanced-search-box").show("blind",{direction:"vertical"},200);$("#lt-advanced-search-button").addClass("on");},hideAdvancedSearchBox:function(){$("#lt-advanced-search-box").hide("blind",{direction:"vertical"},200);$("#lt-advanced-search-button").removeClass("on");},toggleAdvancedSearchBox:function(){if($("#lt-advanced-search-box").is(":visible")){this.hideAdvancedSearchBox();}else{this.showAdvancedSearchBox();}},checkGenreItem:function(item){if($(item).hasClass("selected")){$(item).removeClass("selected");$(item).find("input[name=genre]").attr("checked",false);}else{$(item).addClass("selected");$(item).find("input[name=genre]").attr("checked",true);}},checkAllGenres:function(){$("#lt-advanced-search-form input[name=genre]").each(function(){$(this).attr("checked",true);$(this).parent().addClass("selected");});},checkNoneGenres:function(){$("#lt-advanced-search-form input[name=genre]").each(function(){$(this).attr("checked",false);$(this).parent().removeClass("selected");});},checkMyLyrics:function(check){var form=$("#lt-advanced-search-form");if(check){check=$(check);}else{check=form.find("input[name='my-lyrics']");check.attr("checked",!check.is(':checked'));}
var checked=check.is(':checked');form.find("input[name='user']").attr("disabled",checked);var role=form.find("input[name='user_role']").val();var p=$("#lt-advanced-search-status-row");var c1=p.find("select[name='status']");var c2=p.find("span.status-inc");if(role=="admin"||checked){c1.show();c2.hide();}else{c1.hide();c2.show();}},highlightAdvSearchButton:function(){$("#lt-advanced-search-button").show("pulsate",{times:3},750);},search:function(query){if(typeof(query)=="undefined"){if($("#lt-advanced-search-box").is(":visible")){this.searchAdv();return;}
query="qry="+encodeURIComponent($('#lt-search-text').val());}
window.location.href="/search?"+query;},searchAdv:function(){var query="time="+new Date().getTime();var text=$("#lt-search-text").val();if(text.length>0){query+="&qry="+encodeURIComponent(text);}
var form=$("#lt-advanced-search-form");var title=form.find("input[name='title']").val();if(title.length>0){query+="&title="+encodeURIComponent(title);}
var artist=form.find("input[name='artist']").val();if(artist.length>0){query+="&artist="+encodeURIComponent(artist);}
var album=form.find("input[name='album']").val();if(album.length>0){query+="&album="+encodeURIComponent(album);}
var genres="";form.find("input[name='genre']:checked").each(function(){if(genres.length>0){genres+=",";}
genres+=$(this).val();});if(genres.length>0){query+="&genres="+encodeURIComponent(genres);}
var my=form.find("input[name='my-lyrics']").is(":checked");var user=form.find("input[name='user']").val();if(my){query+="&my=1";}else if(user.length>0){query+="&user="+encodeURIComponent(user);}
var status=form.find("select[name='status']");if(status.css("display")!="none"){query+="&status="+encodeURIComponent(status.val());}else{if(form.find("input[value='include_pending']:checked").length>0){query+="&pending=1";}}
window.location.href="/search?"+query;},checkAdvChanges:function(){var changes=0;var form=$("#lt-advanced-search-form");var title=form.find("input[name='title']").val();if(title.length>0){changes++;}
var artist=form.find("input[name='artist']").val();if(artist.length>0){changes++;}
var album=form.find("input[name='album']").val();if(album.length>0){changes++;}
var genres="";form.find("input[name='genre']:checked").each(function(){if(genres.length>0){genres+=",";}
genres+=$(this).val();});if(genres.length>0){changes++;}
var my=form.find("input[name='my-lyrics']").is(":checked");var user=form.find("input[name='user']").val();if(my){changes++;}else if(user.length>0){changes++;}
var status=form.find("select[name='status']");if(status.css("display")!="none"){if(status.val()!="published"){changes++;}}else{if(form.find("input[value='include_pending']:checked").length>0){changes++;}}
return changes;},includePendingReview:function(){var form=$("#lt-advanced-search-form");var status=form.find("select[name='status']");if(status.css("display")!="none"){status.val("any");}else{form.find("input[value='include_pending']").attr("checked",true);}
this.searchAdv();},notifyChanges:function(){if(this.changeListeners.length>0){for(var i=0;i<this.changeListeners.length;i++){if(typeof(this.changeListeners[i])=="function"){this.changeListeners[i].call();}else if(typeof(this.changeListeners[i])=="string"){eval(this.changeListeners[i]);}}}},addChangeListener:function(listener){this.changeListeners[this.changeListeners.length]=listener;}};var game={PLAYER_WIDTH:560,PLAYER_HEIGHT:315,TRACK_HEIGHT:165,LINE_HEIGHT:33,PRE_TIME:1000,POST_TIME:1000,ADV_TIME:2500,RECORD_TIME:20000,MASK_CHAR:"•",MODE_BLANKS_PERCENT:{"blanks1":0.1,"blanks2":0.25,"full":1},GAME_OPTIONS:{"karaoke":{label:"Karaoke",action:"game.start(\"karaoke\");",style:"bt-w65-blue"},"withdraw":{label:"Withdraw",action:"game.withdraw();",style:"bt-w65-blue"},"replay":{label:"Replay",action:"game.replay();",style:"bt-w65-blue"},"restart":{label:"Restart",action:"game.restart();",style:"bt-w65-blue"},"help":{label:"Help",action:"game.toggleScreen(\"help\");",style:"bt-w65-gray"}},GAME_SCREENS:["start","score","resume","help"],ALPHABET:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZàáâãäåÀÁÂÃÄÅçÇÐèéêëÈÉÊËìíîïÌÍÎÏñÑòóôõöøÒÓÔÕÕÖØšŠùúûüÙÚÛÜÿŸýžŽ",lyrics:null,trackLines:null,playLine:-1,seekLineIndex:null,cursor:{line:0,pos:-1},wordCount:0,totalWordCount:0,skipCount:0,wordChars:"",vocabulary:"",playTime:0,playStartTime:0,playOffsetTime:0,ready:false,started:false,completed:false,active:false,mode:null,points:0,pauseTimer:null,videoPlayer:null,videoSuspended:false,videoOut:false,volume:-1,init:function(lyrics){this.lyrics=lyrics;},reset:function(init){this.started=false;this.clearTrackLines();this.hideAllScreens();this.hideGameScores();if(typeof(friend_mode)!="undefined"&&init){this.start(friend_mode);}else{this.showScreen("start");this.showGameOptions("karaoke","help");}
if(typeof(translateBar)!="undefined"){translateBar.show();}},start:function(mode){this.mode=mode;this.resetTrackLines(mode);this.points=0;this.wordCount=this.skipCount=0;this.updateGameScores();this.playTime=this.playOffsetTime=0;this.playStartTime=new Date().getTime();this.updatePlayTime();this.hideScreen("start");if(mode=="karaoke"){this.showGameOptions("restart","help");}else{this.showGameScores();this.showGameOptions("withdraw","restart","help");}
this.resetCursor();this.restartVideo();this.started=this.active=true;this.completed=false;this.recordGame(true);if(highScores){highScores.changeMode(mode);}},pause:function(){if(this.started&&this.active){this.active=false;this.playOffsetTime+=(this.playStartTime==0)?0:new Date().getTime()-this.playStartTime;this.playStartTime=0;this.showScreen("resume");this.pauseVideo();}},resume:function(){if(this.started&&!this.active){this.active=true;this.playStartTime=new Date().getTime();this.hideScreen("resume");this.playVideo();}},complete:function(){if(this.started){this.showScreen("score");this.showGameOptions("replay","restart","help");if(!this.completed){this.playTime=this.computePlayTime();this.points=this.computeFinalScore();this.completed=true;this.recordGame();}}},lyricsComplete:function(){if(this.started&&this.mode!="karaoke"){this.hideGameOptions("withdraw");if(this.videoOut||this.videoPlayer.getPlayerState()==0){this.complete();}}},videoEnd:function(){if(this.started&&this.mode!="karaoke"){if(this.isLyricsCompleted()){this.complete();}}},restart:function(){if(this.started){this.reset();}},replay:function(){if(this.started){this.hideAllScreens();this.hideGameOptions("replay");this.restartVideo();}},withdraw:function(){if(this.started&&!this.completed){setTimeout("while (game.skipWord()) {}",250);this.hideGameOptions("withdraw");}},computePlayTime:function(){return(this.completed)?this.playTime:(this.playOffsetTime+((this.playStartTime==0)?0:(new Date().getTime()-this.playStartTime)));},computeFinalScore:function(){var wp=this.getLevelWordPoints(this.lyrics.level);var wc=this.wordCount;var cp=wp*wc;var lt=parseInt(this.getPlayDuration()),pt;if((pt=parseInt(this.playTime/1000))<lt){pt=lt;}
var tp=parseInt((1-(lt/pt))*100);cp-=parseInt(cp*tp/100);var self=this;$("#lt-friend-score").hide();computeScoreAnimation.reset(wc,wp,tp,function(){if(typeof(username)!="undefined"&&myAccount.updatePoints&&self.lyrics.status=="published"){myAccount.updatePoints(cp);}
highScores.reloadModeScores(self.mode,self.gameRecordId);self.showFriendScore(cp);});return cp;},showFriendScore:function(score){if(typeof(friend_mode)=="undefined"||typeof(friend_score)=="undefined"){return;}
if(friend_mode==this.mode){if(score>friend_score){$("#lt-friend-score").html("Congratulations!, you've got more than <b>{0}</b> points.".format(friend_score));}else{$("#lt-friend-score").html("Sorry, you haven't got more than <b>{0}</b> points.".format(friend_score));}
var e=$("#lt-friend-score");for(var i=0;i<2;i++){e.fadeTo(500,1).fadeTo(100,1).fadeTo(250,0);}
e.fadeTo(500,1);}else{$("#lt-friend-score").hide();}},gameRecordId:null,recordTimer:null,recordGame:function(reset){if(!this.started||(this.lyrics.status!="published"&&this.lyrics.status!="pending_review")){return false;}
if(this.recordTimer){clearTimeout(this.recordTimer);}
if(reset){this.gameRecordId=null;this.vocabulary="";this.recordTimer=setTimeout("game.recordGame();",20000);}else{var self=this;var post={};if(this.gameRecordId){post.id=this.gameRecordId;}else{if(typeof(username)!="undefined"){post.user=username;}
post.lyrics_id=this.lyrics.id;post.game_mode=this.mode;}
post.progress=(this.completed)?100:0;post.score=this.points;post.words=this.vocabulary.trim();$.ajax({url:"/data/save_game",data:post,type:"POST",success:function(data,status,xhr){self.gameRecordId=parseInt(xhr.responseText);}});}},shareScore:function(to){if(this.completed){if(to=="facebook"){this.shareScoreOnFacebook();}else if(to=="twitter"){this.shareScoreOnTwitter();}}},shareScoreOnFacebook:function(){var url="/fb_share_score"+"?lyrics_id="+this.lyrics.id+"&game_mode="+this.mode+"&game_score="+this.points;window.open(url);},shareScoreOnTwitter:function(){var url="http://www.lyricstraining.com/play/"+this.lyrics.id+"?mode="+this.mode+"&score="+this.points;var via="lyricstraining";var text="I've got {0} points in this song in {1} mode, do you think you can beat me?".format(this.points,GAME_MODES[this.mode].toLowerCase());window.open("http://twitter.com/share"+"?url="+encodeURIComponent(url)+"&via="+encodeURIComponent(via)+"&text="+encodeURIComponent(text));},votePublish:function(v){if(!this.completed||this.lyrics.status!="pending_review"){return;}
$("#lt-vote-box").hide();$.ajax("/data/vote_pub?id="+this.lyrics.id+"&v="+v);},resetTrackLines:function(mode){var p=(this.MODE_BLANKS_PERCENT[mode])?this.MODE_BLANKS_PERCENT[mode]:0;var blanks=(p>0)?this.generateBlanks(p):null;this.trackLines=this.prepareTrackLines(blanks);this.updateTrackLines();},generateBlanks:function(p){var blanks=new WordIndex();var wordIndex=new WordIndex(this.lyrics);if(p==1){this.totalWordCount=wordIndex.getWordCount();}else{var count=Math.round(wordIndex.getWordCount()*p);var backWordIndex=new WordIndex();var lei,wei,li,wi,word;while(count>0){if(wordIndex.getWordCount()==0){wordIndex.merge(backWordIndex);backWordIndex.clear();}
lei=parseInt(Math.random()*wordIndex.getLineCount());wei=parseInt(Math.random()*wordIndex.getWordCount(lei));li=wordIndex.getLineIndex(lei);wi=wordIndex.getWordIndex(lei,wei);word=wordIndex.getWord(lei,wei).toLowerCase();wordIndex.remove(lei,wei);blanks.put(li,wi,word);wordIndex.extractLine(lei,backWordIndex);wordIndex.extractWord(word,backWordIndex);count--;}
this.totalWordCount=blanks.getWordCount();}
return blanks;},prepareTrackLines:function(blanks){var trackLines=[];if(blanks){for(var li=0,wc,cc,bc=0,b,line0,line1;li<this.lyrics.lines.length;li++){line0=this.lyrics.lines[li].text;line1="";wc=0;cc=0;b=(blanks.isEmpty()||blanks.checkPos(li,wc));for(var ci=0,c;ci<line0.length;ci++){c=line0.charAt(ci);if(isAlpha(c)){if(bc==0){line1+=(b)?game.MASK_CHAR:c;cc++;}else{line1+=c;}}else{line1+=c;if(cc>0){wc++;cc=0;b=(blanks.isEmpty()||blanks.checkPos(li,wc));}
if(c=="("){bc++;}else if(c==")"&&bc>0){bc--;}}}
trackLines[trackLines.length]=line1;}}else{for(var li=0;li<this.lyrics.lines.length;li++){trackLines[trackLines.length]=this.lyrics.lines[li].text;}}
return trackLines;},clearTrackLines:function(){this.trackLines=[];this.updateTrackLines();},checkTime:function(){if(this.videoPlayer&&this.videoPlayer.getPlayerState){var state=this.videoPlayer.getPlayerState();if((state==0||state==1||state==2||state==3)){var ct=this.videoPlayer.getCurrentTime();if(this.lyrics.end>0){if(ct>(this.lyrics.end/1000)){this.suspendVideo();if(!this.videoOut){this.videoOut=true;this.videoEnd();}}else if(this.videoOut){this.videoOut=false;}}
if(this.started&&!this.videoOut){var suspend=false;var pt=ct*1000;var pl=this.lyrics.findLineByTime(pt);if(pl>this.cursor.line){var lt=this.lyrics.getLineTime(pl);if(pt>lt){suspend=true;}}else{if(this.seekLineIndex!=null){if(this.seekLineIndex==pl&&state==1){this.seekLineIndex=null;}else{pl=this.seekLineIndex;}}
if(this.playLine!=pl){this.updatePlayLine(pl);}}
if(suspend){this.suspendVideo();}else{this.resumeVideo();}}
this.updateVideoTime();if(this.started){this.updatePlayTime();}}}},setVideoPlayer:function(videoPlayer){this.videoPlayer=videoPlayer;this.videoPlayer.addEventListener("onStateChange","game.onVideoPlayerStateChange");this.videoPlayer.addEventListener("onError","game.onVideoPlayerError");this.checkTimer=setInterval("game.checkTime();",100);volumeControl.set(this.videoPlayer.getVolume());try{this.videoPlayer.loadVideoById(this.lyrics.yt_video_id,this.lyrics.start/1000);}catch(error){}},onVideoPlayerStateChange:function(state){this.updateVideoTime();this.updateVideoControl(state);if(state==0){this.videoEnd();}else if(state==1&&!this.ready){this.ready=true;this.reset(true);}},onVideoPlayerError:function(errorCode){if(!this.ready){this.checkError();}},checkError:function(){var self=this;$.ajax({url:"http://gdata.youtube.com/feeds/api/videos/"+encodeURIComponent(this.lyrics.yt_video_id)+"?alt=json",dataType:"json",complete:function(xhr,textStatus){var error="We're sorry, this video is not available";if(xhr.status==200){try{var data=$.parseJSON(xhr.responseText);var re=data.entry.app$control.yt$state;if(re.name=="restricted"&&re.reasonCode=="requesterRegion"){error="We're sorry, this video is not available in your region.";}}catch(err){}}
if(error){self.showVideoError(error);}}});},showVideoError:function(msg){$("#lt-player-box").html("<div class='error'>"+msg+"</div>");},restartVideo:function(){if(this.videoPlayer){var state=this.videoPlayer.getPlayerState();if(state!=-1&&state!=5){this.clearSeekLine();var st=(this.lyrics.start>0)?this.lyrics.start/1000:0;this.videoPlayer.seekTo(st,true);if(state!=1){this.videoPlayer.playVideo();}
this.resumeVideo();}}},playVideo:function(){if(this.videoPlayer){var state=this.videoPlayer.getPlayerState();if(state==0||this.videoOut){this.restartVideo();}else if(state==2&&!this.videoSuspended){this.videoPlayer.playVideo();}}},pauseVideo:function(){if(this.videoPlayer){var state=this.videoPlayer.getPlayerState();if(state==1||state==3){this.videoPlayer.pauseVideo();}}},stopVideo:function(){if(this.videoPlayer){var state=this.videoPlayer.getPlayerState();if(state==1||state==3){this.videoPlayer.stopVideo();}}},suspendVideo:function(){if(!this.videoSuspended){this.videoSuspended=true;this.volumeDown(this.POST_TIME);}},resumeVideo:function(){if(this.videoSuspended){this.videoSuspended=false;this.resetVolume();}},seekLine:function(line,play){var time=this.lyrics.getLineTime(line);this.seekLineIndex=line;this.seekLineTime((time-this.PRE_TIME)/1000);},seekLineTime:function(time,offset){var delay=0.1,incr=0.50,limit=3;if(typeof(offset)=="undefined"){if(this.seekTimer){clearTimeout(this.seekTimer);this.seekTimer=null;}
this.videoPlayer.pauseVideo();offset=0;}else{var videoTime=this.videoPlayer.getCurrentTime();if((videoTime-delay)>time&&offset<limit){offset+=incr;}else{this.resumeVideo();this.videoPlayer.playVideo();return;}}
var t=time-offset;if(t<0){t=0;offset=limit;}
this.videoPlayer.seekTo(t,true);setTimeout("game.seekLineTime("+time+", "+offset+");",delay*1000);},clearSeekLine:function(){if(this.seekTimer){clearTimeout(this.seekTimer);this.seekTimer=null;}
this.seekLineIndex=null;},lineUp:function(){if(this.lyrics&&this.playLine>0){this.seekLine(this.playLine-1);}},lineDown:function(){if(this.lyrics&&this.playLine<this.cursor.line&&(this.playLine+1)<this.lyrics.lines.length){this.seekLine(this.playLine+1);}},replayLine:function(){if(this.playLine!=-1){this.seekLine(this.playLine,true);}},rewindVideo:function(){this.seekTime-=this.ADV_TIME;if(this.seekTimeout){clearTimeout(this.seekTimeout);}
this.seekTimeout=setTimeout("game.seekVideoTime(true);",500);},forwardVideo:function(){this.seekTime+=this.ADV_TIME;if(this.seekTimeout){clearTimeout(this.seekTimeout);}
this.seekTimeout=setTimeout("game.seekVideoTime(true);",500);},seekVideoTime:function(play){var t=this.videoPlayer.getCurrentTime()+(this.seekTime/1000);if(t<0){t=0;}else{var d=this.videoPlayer.getDuration();if(t>d){t=d;}}
this.videoPlayer.seekTo(t,false);this.seekTime=0;this.seekTimeout=null;},getPlayDuration:function(){var d=this.videoPlayer.getDuration();if(this.lyrics.end>0){d=Math.min(this.lyrics.end/1000,d);}
if(this.lyrics.start>0){d-=this.lyrics.start/1000;}
if(d<0){d=0;}
return d;},setVolume:function(vol){if(this.videoPlayer&&!this.videoSuspended){this.videoPlayer.setVolume(vol);}else{this.volume=vol;}},volumeDown:function(time,v){if(this.videoPlayer){var t=100;var vol=this.videoPlayer.getVolume();if(typeof(v)=="undefined"){this.volume=vol;v=vol/time*t;}
if((vol-=v)<0){vol=0;}
this.videoPlayer.setVolume(vol);if(vol==0){this.videoPlayer.pauseVideo();this.volumeTimer=null;}else{this.volumeTimer=setTimeout("game.volumeDown("+time+", "+v+");",t);}}},resetVolume:function(){if(this.volumeTimer!=null){clearTimeout(this.volumeTimer);this.volumeTimer=null;}
if(this.volume!=-1&&this.videoPlayer){this.videoPlayer.setVolume(this.volume);}},resetCursor:function(){this.cursor.line=0;this.cursor.pos=-1;this.nextChar();},nextChar:function(skip){if(this.cursor.line>=this.lyrics.lines.length){return false;}
this.cursor.pos++;this.updateCursorLine();var line,char;while(this.cursor.line<this.lyrics.lines.length){line=this.lyrics.lines[this.cursor.line].text;while(this.cursor.pos<line.length){char=line.charAt(this.cursor.pos);if(skip){if(!isAlpha(char)){skip=false;}}else{if(isAlpha(char)){if(this.trackLines[this.cursor.line].charAt(this.cursor.pos)==game.MASK_CHAR){return;}}else{this.countWord();}}
this.cursor.pos++;this.updateCursorLine();}
this.nextLine();if(skip){skip=false;}else{this.countWord();}}},countWord:function(){if(this.wordChars.length>0){this.vocabulary+=this.wordChars.toLowerCase()+" ";this.wordChars="";this.wordCount++;this.updateGameScores();return true;}
return false;},skipWord:function(){this.wordChars="";if(this.nextChar(true)!=false){this.skipCount++;this.updateGameScores();return true;}
return false;},nextLine:function(){this.cursor.line++;this.cursor.pos=0;if(this.cursor.line<this.lyrics.lines.length){this.updateCursorLine();if(this.cursor.line<=this.playLine){this.scrollToLine(this.cursor.line);}
if(this.cursor.line==(this.playLine+1)){this.resumeVideo();if(this.videoPlayer.getPlayerState()!=1){this.seekLine(this.cursor.line,true);}}
return true;}else{this.lyricsComplete();return false;}},writeChar:function(k){if(this.started){var c=this.getCursorChar();if(c){c2=normalizeChar(c.toLowerCase());k=normalizeChar(k.toLowerCase());if(k==c2){this.wordChars+=c;this.nextChar();}}}},getCursorChar:function(){var line;if(this.cursor.line<this.lyrics.lines.length&&this.cursor.pos<(line=this.lyrics.lines[this.cursor.line].text).length){return line.charAt(this.cursor.pos);}
return null;},isLyricsCompleted:function(){return!(this.cursor.line<this.lyrics.lines.length);},updateTrackLines:function(){this.midlineTop=parseInt((game.TRACK_HEIGHT-game.LINE_HEIGHT)/2);var out="";for(var i=0;i<this.trackLines.length;i++){out+="<li id='lt-line"+i+"'>"+this.trackLines[i]+"</li>";}
out+="<div id='lt-play-line-light' style='display: none;'></div>";$("#lt-track-lines").html(out).css("top",this.midlineTop+"px");},updatePlayLine:function(line){if(this.playLine!=-1){var e=$("#lt-line"+this.playLine);e.removeClass("playing");$("#lt-play-line-light").hide();if(this.playLine<this.cursor.line){e.addClass("passed");}}
this.playLine=line;if(this.playLine!=-1){$("#lt-line"+this.playLine).addClass("playing");$("#lt-play-line-light").css("top",(this.playLine*game.LINE_HEIGHT)+"px").show();}
if(this.playLine<=this.cursor.line){this.scrollToLine(this.playLine);}
if(typeof(translateBar)!="undefined"&&translateBar.isActive()){translateBar.seekLine(line);}},updateCursorLine:function(){var out="";var text=this.lyrics.lines[this.cursor.line].text;if(this.cursor.pos>0){out+="<span>"+text.substring(0,this.cursor.pos)+"</span>";}
for(var i=this.cursor.pos;i<text.length;i++){if(i==this.cursor.pos){out+="<b id='lt-track-cursor' class='on'>";}
out+=this.trackLines[this.cursor.line][i];if(i==this.cursor.pos){out+="</b>";}}
$("#lt-line"+this.cursor.line).html(out);this.blinkCursor(true);},blinkCursor:function(reset){var cursor=$("#lt-track-cursor");if(reset){cursor.clearQueue();}
cursor.queue(function(){$(this).addClass("on");$(this).dequeue();}).delay(500).queue(function(){$(this).removeClass("on");$(this).dequeue();}).delay(250).queue(function(){game.blinkCursor();$(this).dequeue();});},scrollToLine:function(line){var track=$("#lt-track-lines");track.clearQueue();track.animate({top:(this.midlineTop-line*game.LINE_HEIGHT)},{duration:100,easing:"easeInQuad"});},updateVideoTime:function(){if(this.videoPlayer){var state=this.videoPlayer.getPlayerState();if(state==-1||state==5){$("#lt-player-time").html("00:00&nbsp;/&nbsp;00:00");$("#lt-player-bar-fg").css("width","0");$("lt-player-bar-bs").css({"left":"0","width":"0"});}else if(state==0||state==1||state==2||state==3){var d=this.getPlayDuration();var t=this.videoPlayer.getCurrentTime();t-=this.lyrics.start/1000;if(t<0){t=0;}else if(t>d){t=d;}
$("#lt-player-time").html(formatTime(t)+"&nbsp;/&nbsp;"+formatTime(d));$("#lt-player-timebar-fg").css("width",((d==0)?0:parseInt(t*100/d))+"%");var bl=this.videoPlayer.getVideoBytesLoaded();var bt=this.videoPlayer.getVideoBytesTotal();var w=parseInt(bl*100/bt);$("#lt-player-timebar-bs").css("width",w+"%");}}},updateVideoControl:function(state){if(state==0){this.bt_play.show();this.bt_play.setDisabled(false);this.bt_pause.hide();}else if(state==1){this.bt_pause.show();this.bt_pause.setDisabled(false);this.bt_play.hide();}else if(state==2){this.bt_play.show();this.bt_play.setDisabled(false);this.bt_pause.hide();}else if(state==3){this.bt_play.setDisabled(true);}else{this.bt_play.show();this.bt_play.setDisabled(true);this.bt_pause.hide();}},showGameScores:function(){this.updateGameScores();$("#lt-game-scores").show();},hideGameScores:function(){$("#lt-game-scores").hide();},updateGameScores:function(){$("#lt-score-words").html(this.wordCount+"/"+this.totalWordCount);$("#lt-score-skips").html(this.skipCount);},updatePlayTime:function(){$("#lt-score-time").html(formatTime(this.computePlayTime()/1000));},showGameOptions:function(){var ops=this.GAME_OPTIONS,out="";for(var k in ops){for(var i=0;i<arguments.length;i++){if(arguments[i].toLowerCase()==k){out+="<a id='lt-"+k+"-button'"+" onclick='"+ops[k].action+"'"+" class='"+ops[k].style+"'>"+
ops[k].label+"</a>";}}}
$("#lt-game-options").html(out);},hideGameOptions:function(){for(var i=0,k,e;i<arguments.length;i++){k=arguments[i].toLowerCase();if(this.GAME_OPTIONS[k]&&(e=$("#lt-"+k+"-button")).length>0){e.hide();}}},showScreen:function(name){$("#lt-"+name.toLowerCase()+"-screen").show();},hideScreen:function(name){$("#lt-"+name.toLowerCase()+"-screen").hide();},toggleScreen:function(name){$("#lt-"+name.toLowerCase()+"-screen").toggle();},hideAllScreens:function(){for(var i=0,e;i<this.GAME_SCREENS.length;i++){$("#lt-"+this.GAME_SCREENS[i]+"-screen").hide();}},onKeyDown:function(keyCode){if(!this.active){return true;}
switch(keyCode){case 36:this.restartVideo();return false;case 13:if(this.videoPlayer){var state=this.videoPlayer.getPlayerState();if(state==1){this.bt_pause.onMouseDown();}else if(state==2){this.bt_play.onMouseDown();}}
return false;case 8:this.replayLine();return false;case 33:case 38:this.lineUp();return false;case 34:case 40:this.lineDown();return false;case 37:this.rewindVideo();return false;case 39:this.forwardVideo();return false;case 9:this.skipWord();return false;case 27:case 35:case 45:case 46:return false;default:if(keyCode>=112&&keyCode<=123){return false;}}},onKeyUp:function(keyCode){if(!this.active){return true;}
switch(keyCode){case 13:if(this.videoPlayer){var state=this.videoPlayer.getPlayerState();if(state==1){this.bt_pause.onMouseOut();this.bt_pause.onClick();}else if(state==2){this.bt_play.onMouseOut();this.bt_play.onClick();}}
return false;}},onKeyPress:function(code){if(!this.active){return true;}
var c=String.fromCharCode(code);this.writeChar(c);return false;},getLevelWordPoints:function(level){if(level=="easy"){return 10;}else if(level=="medium"){return 25;}else if(level=="hard"){return 50;}}};var volumeControl={down:false,show:function(){$("#lt-volume-popup").show();},hide:function(){$("#lt-volume-popup").hide();},set:function(v,up){$("#lt-volume-speaker").css("width",(8+parseInt(8*v/100))+"px");$("#lt-volume-ctrl").css("left",(2+parseInt(50*v/100))+"px");if(up){game.setVolume(v);}},move:function(ev){var elem;ev=ev||window.event;elem=document.getElementById("lt-volume-popup");var p0=getElementPosition(elem);var p1=getMouseCoords(ev);var x=p1.x-p0.x-2;if(x<2){x=2;}else if(x>52){x=52;}
var v=Math.round((x-2)*100/50);this.set(v,true);},onClick:function(event){this.move(event);return false;},onMouseDown:function(event){this.down=true;return false;},onMouseMove:function(event){if(this.down){this.move(event);}
return false;},onMouseUp:function(event){this.down=false;return false;}};var computeScoreAnimation={reset:function(wc,wp,tp,callback){if(this.timer!=null){clearTimeout(this.timer);}
this.callback=callback;this.wc=wc;this.wp=wp;this.tp=tp;this.cp=0;$("#lt-score-wc").html("0").css("min-width",new String(wc).length*14+"px");$("#lt-score-wp").html("0");$("#lt-score-cp").html("0");$("#lt-score-tp").html("0%");this.setWP();},setWP:function(){$("#lt-score-wp").html(this.wp);this.timer=setTimeout(function(){computeScoreAnimation.setWC();},500);},setWC:function(){var self=this;var from={count:0},to={count:this.wc};var t=this.wc*50;if(t>2500){t=2500;}
$(from).animate(to,{duration:t,easing:"linear",step:function(now,fx){var c=parseInt(this.count);var p=c*self.wp;$("#lt-score-wc").html(c);$("#lt-score-cp").html(p);},complete:function(){self.cp=self.wc*self.wp;$("#lt-score-wc").html(self.wc);$("#lt-score-cp").html(self.cp);}});this.timer=setTimeout(function(){computeScoreAnimation.setTP();},t+500);},setTP:function(){var self=this;var from={count:0},to={count:this.tp};var t=this.tp*50;if(t>2500){t=2500;}
$(from).animate(to,{duration:t,easing:"linear",step:function(now,fx){var c=parseInt(this.count);var p=parseInt((100-c)*self.cp/100);$("#lt-score-tp").html((c==0)?"0%":"-"+c+"%");$("#lt-score-cp").html(p);},complete:function(){self.cp-=parseInt(self.cp*self.tp/100);$("#lt-score-tp").html((self.tp==0)?"0%":"-"+self.tp+"%");$("#lt-score-cp").html(self.cp);var fade=$("#lt-score-cp");for(var i=0;i<3;i++){fade.fadeOut(400).fadeIn(200);}
if(self.callback!=null){self.callback();}}});}};var trackAnimation={offs:[0,150,300],incs:[3,6,12],interval:null,start:function(){$("#lt-track-bg").html(this.render());this.interval=setInterval("trackAnimation.animate();",50);},stop:function(){clearInterval(this.interval);},animate:function(){for(var i=0;i<this.offs.length;i++){this.offs[i]+=this.incs[i];if(this.offs[i]>=900){this.offs[i]=this.offs[i]-900;}
$("#lt-track-bg-line"+i).css("backgroundPosition","-"+this.offs[i]+"px -"+((2-i)*75)+"px");}},render:function(){var out="<div id='lt-track-bg-line0' class='lt-track-bg-line' style='background-position: "+this.offs[0]+" 0 -150px; '></div>"+"<div id='lt-track-bg-line1' class='lt-track-bg-line' style='background-position: -"+this.offs[1]+"px -75px; '></div>"+"<div id='lt-track-bg-line2' class='lt-track-bg-line' style='background-position: -"+this.offs[2]+"px 0; '></div>";return out;}};document.onkeydown=function(event){return game.onKeyDown(getKeyCode(event));};document.onkeyup=function(event){return game.onKeyUp(getKeyCode(event));};document.onkeypress=function(event){return game.onKeyPress(getCharCode(event));};document.onclick=function(ev){if(!game.over&&game.active){game.pause();}};var _imgs=[];(_imgs[_imgs.length]=new Image()).src="/images/play_line_bg.png";(_imgs[_imgs.length]=new Image()).src="/images/play_line_fg.png";(_imgs[_imgs.length]=new Image()).src="/images/cursor_bg.png";(_imgs[_imgs.length]=new Image()).src="/images/resume.png";(_imgs[_imgs.length]=new Image()).src="/images/game_popup_bg.png";(_imgs[_imgs.length]=new Image()).src="/images/score_box_bg.png";(_imgs[_imgs.length]=new Image()).src="/images/score_tp_bg.png";(_imgs[_imgs.length]=new Image()).src="/images/hscores_line_bg.png";function Lyrics(){this.id=null;this.title=null;this.artist=null;this.album=null;this.genre=null;this.lang=null;this.level=null;this.hits=0;this.status=null;this.user=null;this.start=0;this.end=0;this.offset=0;this.yt_video_id=null;this.update_date=null;this.create_date=null;this.lines=[];}
Lyrics.prototype={LINE_EXP:/\[(.*)\](.*)/,ATTR_EXP:/(.*):(.*)/,TIME_EXP:/(\d{1,2}):(\d{1,2})(\.(\d{1,2}))?/,addLine:function(line){var i=this.lines.length;while(i>0){if(line.time>this.lines[i-1].time){break;}
this.lines[i]=this.lines[i-1];i--;}
this.lines[i]=line;},addLineText:function(text,incr){if(!incr){incr=2500;}
var time=(this.lines.length>0)?(this.lines[this.lines.length-1].time+incr):0;this.addLine(new LyricsLine(time,text));},findLineByTime:function(time){var index=-1;while((index+1)<this.lines.length&&time>=this.getLineTime(index+1)){index++;}
return index;},getLineTime:function(index){if(index<this.lines.length){return(this.offset|0)+this.lines[index].time;}
return-1;},clearLines:function(){this.lines=[];},parse:function(source,temp){this.clearLines();var offset=0,li=0;while(offset<source.length){var line;var lf=source.indexOf("\n",offset);if(lf==-1){line=source.substring(offset);offset=source.length;}else{line=source.substring(offset,lf);offset=lf+1;}
line=line.trim();if(line.length>0){var result=Lyrics.prototype.LINE_EXP.exec(line);if(result){var left=result[1].trim();var text=result[2].trim();var times=left.split("][");for(var i=times.length-1;i>=0;i--){result=Lyrics.prototype.TIME_EXP.exec(times[i].trim());if(result){var time=result[1]*60*1000+result[2]*1000;if(result.length>3&&typeof(result[4])!="undefined"){time+=result[4]*10;}
this.addLine(new LyricsLine(time,text));}else{result=Lyrics.prototype.ATTR_EXP.exec(times[i].trim());if(result){var key=result[1];if(key=="ti"){key="title";}else if(key=="ar"){key="artist";}else if(key=="al"){key="album";}else if(key=="by"){key="user";}
this[key]=result[2];}}}}else if(temp){this.addLineText(line);}}
li++;}
return this;},importCaptions:function(data){var QUIET_TIME=1000;this.clearLines();var self=this;var lines=$(data).find("text"),end=0;lines.each(function(index){var node=$(this);var start=parseFloat(node.attr("start"))*1000;var dur=parseFloat(node.attr("dur"))*1000;if(end>0&&(start-end)>QUIET_TIME){self.addLine(new LyricsLine(end,""));}
var text=node.text();text=text.replace("\n"," ");self.addLine(new LyricsLine(start,text));end=start+dur;if(index==lines.length-1){self.addLine(new LyricsLine(end,""));}});return this;},toString:function(){var str="[id:"+this.id+"]\n"+"[ti:"+this.title+"]\n"+"[ar:"+this.artist+"]\n"+"[al:"+this.album+"]\n"+"[genre:"+this.genre+"]\n"+"[lang:"+this.lang+"]\n"+"[level:"+this.level+"]\n"+"[hits:"+this.hits+"]\n"+"[status:"+this.status+"]\n"+"[user:"+this.user+"]\n"+"[start:"+this.start+"]\n"+"[end:"+this.end+"]\n"+"[offset:"+this.offset+"]\n"+"[yt_video_id:"+this.yt_video_id+"]\n"+"[update_date:"+this.update_date+"]\n"+"[create_date:"+this.create_date+"]\n"+"[re:"+"LyricsTraining"+"]\n"+"[ve:"+"1.0"+"]\n"+
this.writeLines();return str;},toHTMLString:function(){var str="";for(var i=0;i<this.lines.length;i++){str+=this.lines[i].text+"<br />";}
return str;},writeLines:function(){var str="";for(var i=0;i<this.lines.length;i++){str+="["+formatTimeLine(this.lines[i].time)+"]"+this.lines[i].text+"\n";}
return str;}};function LyricsLine(time,text){this.time=time||0;this.text=text||"";}
LyricsLine.prototype={};function WordIndex(lyrics){this.lineEntries=[];this.wordCount=0;this.cursor=null;if(lyrics){this.scan(lyrics);}}
WordIndex.prototype={scan:function(lyrics){this.clear();for(var li=0,wc,bc=0,line,word;li<lyrics.lines.length;li++){line=lyrics.lines[li].text;word="";wc=0;for(var ci=0,c;ci<line.length;ci++){c=line.charAt(ci);if(isAlpha(c)){if(bc==0){word+=c;}}else{if(word.length>0){this.put(li,wc,word);wc++;word="";}
if(c=="("){bc++;}else if(c==")"&&bc>0){bc--;}}}
if(word.length>0){this.put(li,wc,word);}}},put:function(li,wi,word){var lei=0,le=null;while(lei<this.lineEntries.length){if(this.lineEntries[lei].index==li){le=this.lineEntries[lei];break;}else if(this.lineEntries[lei].index>li){break;}
lei++;}
if(le==null){this.lineEntries.splice(lei,0,le={index:li,wordEntries:[]});}
var wei=0,we=null;while(wei<le.wordEntries.length){if(le.wordEntries[wei].index==wi){we=le.wordEntries[wei];break;}else if(le.wordEntries[wei].index>wi){break;}
wei++;}
if(we==null){le.wordEntries.splice(wei,0,we={index:wi,word:word});this.wordCount++;}else{we.word=word;}},remove:function(lei,wei){if(this.lineEntries[lei]){if(typeof(wei)!="undefined"){if(this.lineEntries[lei].wordEntries[wei]){var we=this.lineEntries[lei].wordEntries.splice(wei,1)[0];this.wordCount--;if(this.lineEntries[lei].wordEntries.length==0){this.lineEntries.splice(lei,1);}
return we;}else{return null;}}else{var le=this.lineEntries.splice(lei,1)[0];this.wordCount-=le.wordEntries.length;return le;}}
return null;},getLineIndex:function(lei){return(this.lineEntries[lei])?this.lineEntries[lei].index:-1;},getWordIndex:function(lei,wei){if(this.lineEntries[lei]){return(this.lineEntries[lei].wordEntries[wei])?this.lineEntries[lei].wordEntries[wei].index:-1;}else{return-1;}},getWord:function(lei,wei){if(this.lineEntries[lei]){return(this.lineEntries[lei].wordEntries[wei])?this.lineEntries[lei].wordEntries[wei].word:null;}else{return null;}},getWordCount:function(lei){if(typeof(lei)!="undefined"){return(this.lineEntries[lei])?this.lineEntries[lei].wordEntries.length:0;}else{return this.wordCount;}},getLineCount:function(){return this.lineEntries.length;},resetPos:function(){this.cursor=null;},checkPos:function(li,wi){if(this.cursor==null){this.cursor={lei:0,wei:0};}
if(this.cursor.lei<this.lineEntries.length&&this.cursor.wei<this.lineEntries[this.cursor.lei].wordEntries.length){if(this.lineEntries[this.cursor.lei].index==li&&this.lineEntries[this.cursor.lei].wordEntries[this.cursor.wei].index==wi){this.cursor.wei++;do{if(this.cursor.wei<this.lineEntries[this.cursor.lei].wordEntries.length){break;}else{this.cursor.lei++;this.cursor.wei=0;}}while(this.cursor.lei<this.lineEntries.length);return true;}}
return false;},merge:function(index){for(var i=0;i<index.lineEntries.length;i++){this.addLineEntry(index.lineEntries[i]);}},extractLine:function(lei,toIndex){var le=this.remove(lei);if(le&&toIndex){toIndex.addLineEntry(le);}},extractWord:function(word,toIndex){word=word.toLowerCase();for(var lei=this.lineEntries.length-1,le,we;lei>=0;lei--){le=this.lineEntries[lei];for(var wei=le.wordEntries.length-1;wei>=0;wei--){we=le.wordEntries[wei];if(we.word.toLowerCase()==word){this.remove(lei,wei);if(toIndex){toIndex.put(le.index,we.index,we.word);}}}}},addLineEntry:function(le){for(var wei=0;wei<le.wordEntries.length;wei++){this.put(le.index,le.wordEntries[wei].index,le.wordEntries[wei].word);}},isEmpty:function(){return(this.lineEntries.length==0);},clear:function(){this.lineEntries.length=0;this.wordCount=0;}};var YT_THUMBNAILS_URL="http://img.youtube.com/vi/";var LANGUAGES={"en":"English","en-au":"English/Australia","en-ca":"English/Canada","en-ie":"English/Ireland","en-nz":"English/New Zealand","en-uk":"English/United Kingdom","en-us":"English/United States","es":"Spanish","es-ar":"Spanish/Argentina","es-cl":"Spanish/Chile","es-co":"Spanish/Colombia","es-cu":"Spanish/Cuba","es-ec":"Spanish/Ecuador","es-mx":"Spanish/Mexico","es-pe":"Spanish/Peru","es-pr":"Spanish/Puerto Rico","es-es":"Spanish/Spain","es-uy":"Spanish/Uruguay","es-ve":"Spanish/Venezuela","pt":"Portuguese","pt-br":"Portuguese/Brazil","pt-pt":"Portuguese/Portugal","fr":"French","it":"Italian","de":"German","nl":"Dutch",};var COUNTRY_LIST={"af":"Afghanistan","ax":"Aland Islands","al":"Albania","dz":"Algeria","as":"American Samoa","ad":"Andorra","ao":"Angola","ai":"Anguilla","aq":"Antarctica","ag":"Antigua and Barbuda","ar":"Argentina","am":"Armenia","aw":"Aruba","au":"Australia","at":"Austria","az":"Azerbaijan","bs":"Bahamas","bh":"Bahrain","bd":"Bangladesh","bb":"Barbados","by":"Belarus","be":"Belgium","bz":"Belize","bj":"Benin","bm":"Bermuda","bt":"Bhutan","bo":"Bolivia","ba":"Bosnia and Herzegovina","bw":"Botswana","bv":"Bouvet Island","br":"Brazil","io":"British Indian Ocean Territory","vg":"British Virgin Islands","bn":"Brunei","bg":"Bulgaria","bf":"Burkina Faso","bi":"Burundi","kh":"Cambodia","cm":"Cameroon","ca":"Canada","cv":"Cape Verde","ky":"Cayman Islands","cf":"Central African Republic","td":"Chad","cl":"Chile","cn":"China","cx":"Christmas Island","cc":"Cocos (Keeling) Islands","co":"Colombia","km":"Comoros","cg":"Congo","ck":"Cook Islands","cr":"Costa Rica","hr":"Croatia","cu":"Cuba","cy":"Cyprus","cz":"Czech Republic","cd":"Democratic Republic of Congo","dk":"Denmark","xx":"Disputed Territory","dj":"Djibouti","dm":"Dominica","do":"Dominican Republic","tl":"East Timor","ec":"Ecuador","eg":"Egypt","sv":"El Salvador","gq":"Equatorial Guinea","er":"Eritrea","ee":"Estonia","et":"Ethiopia","fk":"Falkland Islands","fo":"Faroe Islands","fm":"Federated States of Micronesia","fj":"Fiji","fi":"Finland","fr":"France","gf":"French Guyana","pf":"French Polynesia","tf":"French Southern Territories","ga":"Gabon","gm":"Gambia","ge":"Georgia","de":"Germany","gh":"Ghana","gi":"Gibraltar","gr":"Greece","gl":"Greenland","gd":"Grenada","gp":"Guadeloupe","gu":"Guam","gt":"Guatemala","gn":"Guinea","gw":"Guinea-Bissau","gy":"Guyana","ht":"Haiti","hm":"Heard Island and Mcdonald Islands","hn":"Honduras","hk":"Hong Kong","hu":"Hungary","is":"Iceland","in":"India","id":"Indonesia","ir":"Iran","iq":"Iraq","xe":"Iraq-Saudi Arabia Neutral Zone","ie":"Ireland","il":"Israel","it":"Italy","ci":"Ivory Coast","jm":"Jamaica","jp":"Japan","jo":"Jordan","kz":"Kazakhstan","ke":"Kenya","ki":"Kiribati","kw":"Kuwait","kg":"Kyrgyzstan","la":"Laos","lv":"Latvia","lb":"Lebanon","ls":"Lesotho","lr":"Liberia","ly":"Libya","li":"Liechtenstein","lt":"Lithuania","lu":"Luxembourg","mo":"Macau","mk":"Macedonia","mg":"Madagascar","mw":"Malawi","my":"Malaysia","mv":"Maldives","ml":"Mali","mt":"Malta","mh":"Marshall Islands","mq":"Martinique","mr":"Mauritania","mu":"Mauritius","yt":"Mayotte","mx":"Mexico","md":"Moldova","mc":"Monaco","mn":"Mongolia","me":"Montenegro","ms":"Montserrat","ma":"Morocco","mz":"Mozambique","mm":"Myanmar","na":"Namibia","nr":"Nauru","np":"Nepal","an":"Netherlands Antilles","nl":"Netherlands","nc":"New Caledonia","nz":"New Zealand","ni":"Nicaragua","ne":"Niger","ng":"Nigeria","nu":"Niue","nf":"Norfolk Island","kp":"North Korea","mp":"Northern Mariana Islands","no":"Norway","om":"Oman","pk":"Pakistan","pw":"Palau","ps":"Palestinian Occupied Territories","pa":"Panama","pg":"Papua New Guinea","py":"Paraguay","pe":"Peru","ph":"Philippines","pn":"Pitcairn Islands","pl":"Poland","pt":"Portugal","pr":"Puerto Rico","qa":"Qatar","re":"Reunion","ro":"Romania","ru":"Russia","rw":"Rwanda","sh":"Saint Helena and Dependencies","kn":"Saint Kitts and Nevis","lc":"Saint Lucia","pm":"Saint Pierre and Miquelon","vc":"Saint Vincent and the Grenadines","ws":"Samoa","sm":"San Marino","st":"Sao Tome and Principe","sa":"Saudi Arabia","sn":"Senegal","rs":"Serbia","sc":"Seychelles","sl":"Sierra Leone","sg":"Singapore","sk":"Slovakia","si":"Slovenia","sb":"Solomon Islands","so":"Somalia","za":"South Africa","gs":"South Georgia and South Sandwich Islands","kr":"South Korea","es":"Spain","pi":"Spratly Islands","lk":"Sri Lanka","sd":"Sudan","sr":"Suriname","sj":"Svalbard and Jan Mayen","sz":"Swaziland","se":"Sweden","ch":"Switzerland","sy":"Syria","tw":"Taiwan","tj":"Tajikistan","tz":"Tanzania","th":"Thailand","tg":"Togo","tk":"Tokelau","to":"Tonga","tt":"Trinidad and Tobago","tn":"Tunisia","tr":"Turkey","tm":"Turkmenistan","tc":"Turks And Caicos Islands","tv":"Tuvalu","vi":"US Virgin Islands","ug":"Uganda","ua":"Ukraine","ae":"United Arab Emirates","uk":"United Kingdom","xd":"United Nations Neutral Zone","um":"United States Minor Outlying Islands","us":"United States","uy":"Uruguay","uz":"Uzbekistan","vu":"Vanuatu","va":"Vatican City","ve":"Venezuela","vn":"Vietnam","wf":"Wallis and Futuna","eh":"Western Sahara","ye":"Yemen","zm":"Zambia","zw":"Zimbabwe",};var LATIN_ALPHABET_EX="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþẞÿŸĀāĊċĒēĠġĪīŌōŐőŒœŠšŪūŰűŴŵŶŷŽžḂḃḊḋḞḟṀṁṠṡṪṫ";var NORMALIZE_CHARSET=["ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿŸĀāĊċĒēĠġĪīŌōŐőŠšŪūŰűŴŵŶŷŽžḂḃḊḋḞḟṀṁṠṡṪṫ","AAAAAACEEEEIIIIDNOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyyYAaCcEeGgIiOoOoSsUuUuWwYyZzBbDdFfMmSsTt"];function isAlpha(c){return(LATIN_ALPHABET_EX.indexOf(c)!=-1);}
function normalizeChar(c){var i=NORMALIZE_CHARSET[0].indexOf(c);return(i!=-1)?NORMALIZE_CHARSET[1][i]:c;}
function formatLang(code,short){var str="";if(LANGUAGES[code]){var name=LANGUAGES[code];var names=name.split("/");str+=names[0];if(!short&&names.length>1){str+="/"+names[1];}
var codes=code.split("-");str+="<img class=\"flag\" src=\"/images/flags/"+((codes.length>1)?codes[1]:codes[0])+".png\" />";}
return str;}
var LEVELS=["all","easy","medium","hard"];LEVEL_IMG_PRE="/images/level_";LEVEL_IMG_EXT=".png";function parseLevelImageURL(src){var level=null;var i0,i1;if((i0=src.indexOf(LEVEL_IMG_PRE))!=-1&&(i1=src.indexOf(LEVEL_IMG_EXT,(i0=i0+LEVEL_IMG_PRE.length)))!=-1){level=src.substring(i0,i1);}
return level;}
function formatLevelImageURL(level){return(LEVEL_IMG_PRE+(level?level:"all")+LEVEL_IMG_EXT);}
var STATES={"draft":"Draft","pending_review":"Pending Review","published":"Published","rejected":"Rejected","video_removed":"Video Removed","deleted":"Deleted",};var GENRES={"pop":"Pop","rock":"Rock","hard_rock":"Hard Rock","heavy_metal":"Heavy Metal","punk":"Punk","electronica":"Electronica","dance":"Dance","disco":"Disco","house":"House","techno":"Techno","blues":"Blues","r&b":"Rhythm & Blues","rap":"Hip Hop/Rap","funk":"Funk","soul":"Soul","jazz":"Jazz","folk":"Folk","country":"Country","reggae":"Reggae","latin":"Latin","indie":"Indie","newage":"New Age","classic":"Classical","opera":"Opera","children":"Children's Music","tv_show":"TV Show","movie_scene":"Movie Scene","soundtrack":"Soundtrack","other":"Other",};var GAME_MODES={"blanks1":"Beginner","blanks2":"Intermediate","full":"Expert","karaoke":"Karaoke",};var GAME_MODES_TEXT={"blanks1":"Beginner Mode","blanks2":"Intermediate Mode","full":"Expert Mode","karaoke":"Karaoke Mode",};function getXMLHttpRequest(){return(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");}
function bindObject(obj){if(!window.__next_obj_id_){window.__next_obj_id_=1;}
var idx="__obj"+(window.__next_obj_id_++)+"_";window[idx]=obj;obj.idx=idx;return idx;}
function addEventHandler(element,type,listener,useCapture){if(element.addEventListener){element.addEventListener(type,listener,useCapture);return true;}else if(element.attachEvent){return element.attachEvent("on"+type,listener);}else{element["on"+type]=listener;}}
function getMouseX(event){if(event.pageX){return event.pageX;}else if(event.clientX){return event.clientX
+(document.documentElement.scrollLeft||document.body.scrollLeft)
-document.documentElement.clientLeft;}
return null;}
function getMouseY(event){if(event.pageY){return event.pageY;}else if(event.clientY){return event.clientY
+(document.documentElement.scrollTop||document.body.scrollTop)
-document.documentElement.clientTop;}
return null;}
function createCookie(name,value,days){var expires;if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString();}else{expires="";}
document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(";");for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==" "){c=c.substring(1,c.length);}
if(c.indexOf(nameEQ)==0){return c.substring(nameEQ.length,c.length);}}
return null;}
function eraseCookie(name){createCookie(name,"",-1);}
function showDialog(props){var overlay;if(overlay=document.getElementById("lt-dialog-overlay")){closeDialog();}
var BW=10*2;var width=(props.width||640);var height=(props.height||480);var closable=(typeof(props.closable)=="undefined")?true:props.closable;var out="<table class='dialog-table' cellpadding='0' cellspacing='0' "+"style='margin-top: -"+(parseInt((height+BW)/2))+"px; margin-left: -"+(parseInt((width+BW)/2))+"px;'>"+"<tr>"+"<td class='tl'></td>"+"<td class='mb'></td>"+"<td class='tr'></td>"+"</tr>"+"<tr>"+"<td class='mb'></td>"+"<td class='center' style='width: "+width+"px; height: "+height+"px;'>";if(props.title){out+="<div class='header'>"+props.title;if(closable){out+="<div class='bt-close' onclick='closeDialog();'></div>";}
out+="</div>";}
out+="<div id='lt-dialog-content' class='content'";if(props.contentStyle){out+=" style='"+props.contentStyle+"'";}
out+=">";if(props.contentHTML){out+=props.contentHTML;}else if(props.contentURL){}
out+="</div>"+"</td>"+"<td class='mb'></td>"+"</tr>"+"<tr>"+"<td class='bl'></td>"+"<td class='mb'></td>"+"<td class='br'></td>"+"</tr>"+"</table>"+"</div>";var overlay=document.createElement("div");overlay.id="lt-dialog-overlay";overlay.className="dialog-overlay";overlay.innerHTML=out;var parent=document.body;if(props.parentElementId){parent=document.getElementById(props.parentElementId);if(!parent){parent=document.body;}}
parent.appendChild(overlay);if(props.contentElementId){var content=document.getElementById(props.contentElementId);var contentParent=document.getElementById("lt-dialog-content");content.__parentNode_=content.parentNode;contentParent.appendChild(content);content.style.display="block";}}
function closeDialog(){var contentParent=document.getElementById("lt-dialog-content");if(contentParent){var content=contentParent.lastChild;if(content.__parentNode_){content.__parentNode_.appendChild(content);content.style.display="none";}
var overlay=document.getElementById("lt-dialog-overlay");overlay.parentNode.removeChild(overlay);}}
function LTButton(id,actions,disabled,style){this.id=id;this.actions=actions;this.disabled=disabled||false;this.style=style;this.over=false;bindObject(this);}
LTButton.prototype={setDisabled:function(disabled){this.disabled=disabled;var elem=document.getElementById(this.id);if(elem){elem.className=(this.disabled)?"disabled":"";}},onMouseOver:function(){if(this.disabled){return;}
this.over=true;var elem=document.getElementById(this.id);if(elem){elem.className="over";}},onMouseOut:function(){if(this.disabled){return;}
this.over=false;var elem=document.getElementById(this.id);if(elem){elem.className="";}},onMouseDown:function(){if(this.disabled){return;}
var elem=document.getElementById(this.id);if(elem){elem.className="down";}},onMouseUp:function(){if(this.disabled){return;}
var elem=document.getElementById(this.id);if(elem){elem.className=(this.over)?"over":"";}},onClick:function(){if(this.disabled){return;}
eval(this.actions);},show:function(){var elem=document.getElementById(this.id);if(elem){elem.style.display="block";}},hide:function(){var elem=document.getElementById(this.id);if(elem){elem.style.display="none";}},isVisible:function(){var elem=document.getElementById(this.id);if(elem){return(elem.style.display=="block");}
return false;},press:function(t){var elem=document.getElementById(this.id);if(elem){elem.className="down";setTimeout(this.idx+".onClick();"+this.idx+".onMouseOut();",t);}},render:function(){var out="<"+"div id='"+this.id+"'";if(this.disabled){out+=" class='disabled'";}
if(this.style){out+=" style='"+this.style+"'";}
out+="onMouseOver='"+this.idx+".onMouseOver();'";out+="onMouseOut='"+this.idx+".onMouseOut();'";out+="onMouseDown='"+this.idx+".onMouseDown();'";out+="onMouseUp='"+this.idx+".onMouseUp();'";out+="onClick='"+this.idx+".onClick();'";out+="><"+"/div>";return out;},include:function(){document.write(this.render());}};function formatTime(t){var m,s;return(((m=parseInt(t/60))<10?("0"+m):m)+":"+((s=parseInt(t%60))<10?("0"+s):s));}
function formatTimeLine(t){if(t<0)t=0;var min=parseInt(t/60000);var sec=parseInt(t%60000/1000);var cen=parseInt(t%60000%1000/10);return((min<10)?("0"+min):min)
+":"+((sec<10)?("0"+sec):sec)
+"."+((cen<10)?("0"+cen):cen);}
function getVideoIdFromURL(url){var id;var i0=url.indexOf("?v="),i1;if(i0>0){i0+=3;i1=url.indexOf("&",i0);id=url.substring(i0,i1);}
return id;}
function sleep(time){var start=new Date().getTime();while(((new Date().getTime())-start)<time);}
function getMouseCoords(event){if(event.pageX||event.pageY){return{x:event.pageX,y:event.pageY};}
return{x:(event.clientX+document.body.scrollLeft-document.body.clientLeft),y:(event.clientY+document.body.scrollTop-document.body.clientTop)};}
function getElementPosition(elem){var left=0,top=0;while(elem.offsetParent){left+=elem.offsetLeft;top+=elem.offsetTop;elem=elem.offsetParent;}
left+=elem.offsetLeft;top+=elem.offsetTop;return{x:left,y:top};}
String.prototype.endsWith=function(str){return(this.match(str+"$")==str);};String.prototype.startsWith=function(str){return(this.match("^"+str)==str);};String.prototype.trim=function(){return(this.replace(/^\s\s*/,'').replace(/\s\s*$/,''));};String.prototype.format=function(){var str=this;for(var i=0;i<arguments.length;i++){str=str.replace("{"+i+"}",arguments[i]);}
return str;};function capFirst(str){return str.replace(/^(.)/g,function(m,p1){return p1.toUpperCase();});}
function capWords(str){return str.replace(/(^|\s)(.)/g,function(m,p1,p2){return(p1+p2.toUpperCase());});}
if(!Array.prototype.indexOf){Array.prototype.indexOf=function(v){for(var i=0;i<this.length;i++){if(this[i]==v){return i;}}
return-1;}}
function getKeyCode(event){return(event||window.event).keyCode;}
function getCharCode(event){if(!event)event=window.event;return(event.charCode||event.keyCode);}
function stopBubbling(event){if(!event){event=window.event;}
event.cancelBubble=true;if(event.stopPropagation){event.stopPropagation();}}
if(!Array.indexOf){Array.prototype.indexOf=function(obj){for(var i=0;i<this.length;i++){if(this[i]==obj){return i;}}
return-1;};}
function trace(msg){var out=document.getElementById("logger-out");if(out){out.innerHTML+=msg+"<br/>";out.scrollTop=out.scrollHeight;}}
function includeLogger(){document.write("<div id='logger-out' style='position: absolute; width: 400px; height: 100%; top: 0px; right: 0px; background-color: #E0E0E0; overflow: auto;'></div>");}
