Tweet=function(a){this.id=a.id;this.message=a.getElementsByTagName("h3")[0];this.imageLink=a.getElementsByTagName("img")[0];this.imageInfo=$("mouseover-"+this.id);this.reply=a.getElement(".reply").getElement("a");this.replyForm=a.getElement(".reply_form");this.replyBox=this.replyForm.getElement(".reply_box");this.cancel=a.getElement(".cancel");this.submit=a.getElement(".submit");this.vote=a.getElement(".vote").getElement("a");this.voteDisplay=a.getElement(".votes");var b=this;this.replyForm.addEvent("submit",function(c){b.sendReply(c)});this.vote.addEvent("click",function(){b.sendVote()});this.reply.addEvent("click",function(){b.toggleReplyForm()});this.cancel.addEvent("click",function(){b.toggleReplyForm()});this.imageLink.addEvent("mouseenter",function(){b.showInfo()})};Tweet.prototype.sendReply=function(a){a.stop();var b=this;this.replyForm.set("send",{onSuccess:function(c){onReplySuccess(b)},onFailure:function(c){onReplyFailure(b,c)}});this.replyForm.send()};var onReplySuccess=function(a){a.submit.setProperty("disabled",true);a.submit.setProperty("value","Submitted");a.replyForm.setStyle("display","none");a.showMessage("Reply posted.","success")};var onReplyFailure=function(tweet,xhr){var error=eval("("+xhr.responseText+")");tweet.showMessage(error.error?error.error:"Error","error")};Tweet.prototype.sendVote=function(){if(!is_authenticated){showLogin(this,false);return}var b=this;var a=new Request({method:"get",url:"/ajax/vote/"+this.id+"/",onSuccess:function(c){onVoteSuccess(b,c)},onFailure:function(c){onVoteFailure(b,c)}}).send()};var onVoteSuccess=function(tweet,response){var voteCount=eval(tweet.voteDisplay.innerHTML.split(" ")[0])+1;tweet.voteDisplay.innerHTML=voteCount+(voteCount==1?" vote":" votes")};var onVoteFailure=function(c,b){var a="Error.";if(b.status==404){a="You are not logged in."}else{if(b.status==409){a="You already voted."}}c.showMessage(a,"error")};Tweet.prototype.isReplyFormShowing=function(){return this.replyForm.getStyle("display")!="none"};Tweet.prototype.toggleReplyForm=function(){if(!is_authenticated){showLogin(this,true);return}if(this.isReplyFormShowing()){this.message.setStyle("display","none");this.replyForm.setStyle("display","none")}else{this.replyForm.focus();this.replyForm.setStyle("display","block");this.hideAllOtherReplies()}};Tweet.prototype.hideAllOtherReplies=function(){for(var a=0;a<tweets.length;a++){if(tweets[a]!=this&&tweets[a].isReplyFormShowing()){tweets[a].toggleReplyForm()}}};Tweet.prototype.showMessage=function(b,a){this.message.innerHTML=b;this.message.className=a;this.message.setStyle("display","block")};Tweet.prototype.showInfo=function(){console.log("test");this.imageInfo.setStyle("visibility","show")};var hideLogin=function(){login.setStyle("display","none");blockScreen.setStyle("display","none")};var showLogin=function(c,a){clearLoginMessage();var b;if(window.pageYOffset){b=window.pageYOffset}else{b=document.body.scrollTop}b=b+40+"px";login.setStyle("top",b);login.setStyle("display","block");blockScreen.setStyle("display","block");login.removeEvents("submit");login.addEvent("submit",function(d){d.stop();this.set("send",{onRequest:clearLoginMessage,onSuccess:function(e){onLoginSuccess(e,c,a)},onFailure:onLoginFailure});this.send()})};var onLoginSuccess=function(a,c,b){hideLogin();clearLoginMessage();is_authenticated=true;if(b){c.toggleReplyForm()}else{c.sendVote()}};var clearLoginMessage=function(){login.getElementById("login_error").innerHTML=""};var onLoginFailure=function(a){login.getElementById("login_error").innerHTML="Couldn't authenticate you."};var read_cookie=function(b){var f=b+"=";var a=document.cookie.split(";");for(var d=0;d<a.length;d++){var e=a[d];while(e.charAt(0)==" "){e=e.substring(1,e.length)}if(e.indexOf(f)==0){return e.substring(f.length,e.length)}}return null};var tweets=[];var login;var blockScreen;var is_authenticated=!!(read_cookie("sessionid"));window.addEvent("domready",function(){if(!$("tweets")){return}var c=$("tweets").getElements("li");for(var a=0;a<c.length;a++){var d=new Tweet(c[a]);tweets.push(d)}login=$("login");blockScreen=$("blockScreen");var b=login.getElement(".cancel");b.addEvent("click",hideLogin);blockScreen.addEvent("click",hideLogin)});function getPosition(b){var a=0,c=0;do{a+=b.offsetLeft;c+=b.offsetTop}while(b=b.offsetParent);return[a,c]}var hiding=false;function hideHover(){var a=document.getElementById("hover");hiding=true;setTimeout(function(){if(hiding){a.style.display="none"}},300)}function showAthleteInfo(d){var c=d.parentNode.parentNode.getElementsByTagName("div")[0];var b=document.getElementById("hover");hiding=false;b.style.display="block";var a=getPosition(d);b.style.left=a[0]+"px";b.style.top=a[1]+50+"px";b.innerHTML=c.innerHTML}function showHover(){hiding=false};