KaraokePlay.CommentForm=Class.create({initialize:function(){this.form=$("commentForm");this.textArea=$("commentFormArea");(this.addProfileButton=$("profileButton"))&&this.addProfileButton.observe("click",this.onAddMyProfileClick.bind(this));document.observe("dom:loaded",function(){this.smileyController=new KaraokePlay.SmileyController(this);this.recordingController=new KaraokePlay.RecordingController(this)}.bind(this));$("recordingComments").observe("click",this.onCommentListClick.bind(this))},onCommentListClick:function(a){var b=
a.findElement("a.quote");if(b){a.stop();a=b.getAttribute("rel");if(b=$(b.getAttribute("id").replace("quote_","")+"_content")){b=b.innerHTML.replace(/(<([^>]+)>)/ig,"");this.textArea.value+="[QUOTE:"+a+"]"+b+"[/QUOTE]"}}},onAddMyProfileClick:function(a){a.stop();$("recordingWindow").hide();$("smileyWindow").hide();this.textArea.value+=" [PROFILE] "},_eoo:true});
KaraokePlay.Pagination=Class.create({initialize:function(a,b){this.currentPage=1;this.element=a;this.data=b;b=new Element("div",{id:"pagination"});var c=(new Element("div")).addClassName("d_pagination");b.insert(c);this.pagination=(new Element("div")).addClassName("pagination");this.createPagination();c.insert(this.pagination);a.insert(b);this.pagination.observe("click",this.onClickElement.bind(this))},createPagination:function(){this.pagination.childElements().invoke("remove");for(var a,b=1;b<Math.ceil(this.data.length/
5)+1;b++){a=b===this.currentPage?(new Element("span")).addClassName("current").update(this.currentPage):(new Element("a",{href:"javascript://",rel:b})).update(b);this.pagination.insert(a)}},onClickElement:function(a){a.stop();if(a=a.findElement("a")){this.currentPage=parseInt(a.getAttribute("rel"),10);this.element.select("ul").each(function(b){b[b.hasClassName("pagination_"+(this.currentPage-1))?"show":"hide"]()},this);this.createPagination()}},_eoo:true});
KaraokePlay.RecordingController=Class.create({initialize:function(a){this.window=$("recordingWindow");this.button=$("recordingButton");this.recordingsLoaded=false;this.commentForm=a;this.button.observe("click",this.onRecordingToggle.bind(this))},onRecordingToggle:function(a){a.stop();this.window.toggle();$("smileyWindow").hide();this.window.visible()&&this.recordingsLoaded===false&&this.loadMyRecordings()},loadMyRecordings:function(){new Ajax.Request("/recordings/mine",{method:"GET",onSuccess:this.onMyRecordingsReceived.bind(this)})},
onMyRecordingsReceived:function(a){this.window.down("img.loading").hide();this.recordingsLoaded=true;if(a=a.responseJSON){var b,c,d;a.eachSlice(5,function(e,g){var f=(new Element("ul")).addClassName("pagination_"+g);f[g===0?"show":"hide"]();var h=document.createDocumentFragment();this.window.insert(f);e.each(function(i){b=new Element("li");c=i.recording;d=(new Element("a",{href:"javascript://",rel:c.id})).update(c.name+" - "+c.title);b.appendChild(d);h.appendChild(b)});f.appendChild(h);f.observe("click",
this.onRecordingClick.bind(this))},this);new KaraokePlay.Pagination(this.window,a)}},onRecordingClick:function(a){a.stop();a=a.findElement("a");this.commentForm.textArea.value+=" [RECORDING:"+a.getAttribute("rel")+"] ";this.window.hide()},_eoo:true});
KaraokePlay.SmileyController=Class.create({initialize:function(a){this.smileyButton=$("smileyButton");this.smileyWindow=$("smileyWindow");this.smiliesLoaded=false;this.commentForm=a;this.smileys=["bad","dancingbanana","happy","party","shake","worship","badmusic","evil","headbanger","partybanana","shining","clap","eyebrow","jawdrop","partyblow","singing","cool","flashing","love","partyhat","sleep","cursing","funky","listening","pompoms","smile","dancing","good","mad","sad","verymad"];this.smileyExceptions=
{dancingbanana:"dancing",happy:")",partybanana:"banana",love:"(l)",smile:"D",dancing:"dance",good:"y",sad:"("};this.startObserving()},startObserving:function(){this.smileyButton.observe("click",this.handleSmileyLoad.bind(this))},handleSmileyLoad:function(a){a.stop();$("recordingWindow").hide();if(this.smiliesLoaded===false){var b,c,d,e,g=document.createDocumentFragment();a=new Element("ul");this.smileyWindow.insert(a);this.smileyWindow.insert(new Element("br",{style:"clear: both"}));this.smileys.each(function(f){b=
f;if(this.smileyExceptions[f])b=this.smileyExceptions[f];b=":"+b;c=new Element("li");d=new Element("a",{title:b,href:"javascript://"});e=new Element("img",{src:"/images/smilies/"+f+".gif",alt:b.replace(":","")});d.appendChild(e);c.appendChild(d);g.appendChild(c)},this);a.appendChild(g);a.observe("click",this.onSmileyClick.bind(this));this.smiliesLoaded=true}this.smileyWindow.toggle();this.smileyButton[this.smileyWindow.visible()===true?"addClassName":"removeClassName"]("selected")},onSmileyClick:function(a){a.stop();
a=a.findElement("a").getAttribute("title");this.commentForm.textArea.value+=a;this.smileyWindow.hide();this.smileyButton.removeClassName("selected")},_eoo:true});var commentForm=new KaraokePlay.CommentForm;
if(typeof KaraokePlay==="undefined")KaraokePlay={};
KaraokePlay.RecordController=Class.create({initialize:function(){this.isRecording=false;window.onbeforeunload=this.onBeforeUnload.bind(this)},startRecording:function(){this.isRecording=true},stopRecording:function(){this.isRecording=false},onBeforeUnload:function(){if(this.isRecording===true){var a="ATTENTION!!\nAre you sure you want to leave this page? Your recording will be deleted if you leave this page without first saving your recording.\n\nIf you click ok your recording will be LOST! Please click CANCEL and save your recording.",b=
b||window.event;if(b)b.returnValue=a;return a}},_eoo:true});var controller=new KaraokePlay.RecordController;function startRecording(){controller.startRecording()}function stopRecording(){controller.stopRecording()};
