function TotObject(){var a,c,f,e,b,g,h,d,i,j;this.populate=function(k,m,p,o,l,q,r,t,n,s){this.id=k;this.leftId=m;this.rightId=p;this.question=o;this.leftHeader=l;this.rightHeader=q;this.shortUrl=r;this.tags=t;this.image=n;this.loginNeeded=s},this.setVotedVoteableItemId=function(k){this.voteableItemId=k},this.getVotedVoteableItemId=function(){return this.voteableItemId},this.imgError=function(k){setTimeout('$("#'+k.id+'").attr("src","'+k.src+'");',5000)},this.fetchOtherId=function(k){if(k==this.leftId){return this.rightId}if(k==this.rightId){return this.leftId}return null}}var tot=new TotObject();var vote={clickedVoteCount:0,reasonNotAllowed:"",postUrl:"/ajx/vote",voteTask:[],addVoteTask:function(a){this.voteTask[this.voteTask.length]=a},fireVoteTasks:function(){for(var a=0;a<this.voteTask.length;a++){this.voteTask[a]()}},incrementCount:function(){var b=$("#totalVotes").attr("data-voted");if(!b){var a=new Number($("#totalVotes").text())+1;$("#totalVotes").text(a);$("#totalVotes").attr("data-voted","true")}},allow:false,vote:function(c,a){var d=$(c).parents("div[data-voteable-item-id]").attr("data-voteable-item-id");tot.setVotedVoteableItemId(d);vote.clickedVoteCount++;$("#inSupportOf option[value="+d+"]").attr("selected","selected");var b={position:(a=="this")?"LEFT":"RIGHT",action:"vote",totId:tot.id,cacheBust:(new Date()).getTime(),voteableItemId:d};$.getJSON(vote.postUrl,b,function(e){vote.viewResults(d)})},preCheckVoteableItem:function(d){var a=$("div[data-voteable-item-id]");$("div[data-voteable-item-id="+d+"] div.check img").attr("src",core.webProxy+"/assets/0.014/images/icons/checkbox-voted.png");for(var b=0;b<a.length;b++){var c=$(a[b]);if(c.attr("data-voteable-item-id")!=d){c.children("img").animate({opacity:0.4},300)}}},highlightNext:function(){var a=$(".next-match");a.delay(2000).animate({backgroundColor:"#FFF"},1000).delay(100).animate({backgroundColor:"#C5DBE6"},1000);var a=$(".next-match img");a.delay(2000).animate({opacity:0.2},1000).delay(100).animate({opacity:1},1000)},viewResults:function(c){var d=$(".results").hasClass("on");if(d){var a=$("div[data-voteable-item-id="+c+"] .results");if(a){var b=$(a).hasClass("on");vote.requestResults();return}vote.hideResults()}else{vote.requestResults()}},hideResults:function(a){$(".results").hide(200,function(){$(this).toggleClass("on")})},requestResults:function(){$(".results").show(200,function(){$(this).toggleClass("on")});var a={totId:tot.id,cacheBust:(new Date()).getTime(),action:"viewResults"};$.getJSON(vote.postUrl,a,function(b){vote.populateVoteResults(b.voteableItemIdA,b.voteableItemIdB,b.percentageA,b.countA);vote.populateVoteResults(b.voteableItemIdB,b.voteableItemIdA,b.percentageB,b.countB)})},populateVoteResults:function(d,a,b,c){if(d){$("div[data-voteable-item-id="+d+"] .results").html(b)}else{if(a){$("div[data-voteable-item-id="+tot.fetchOtherId(a)+"] .results").html("0%")}else{$("div[data-voteable-item-id="+tot.leftId+"] .results").html("0%");$("div[data-voteable-item-id="+tot.rightId+"] .results").html("0%")}}},clickVoteBox:function(b,c){var a,d;if(c=="this"){a="this";d="that";$("img.that").animate({opacity:0.4},300);$("img.this").animate({opacity:1},300)}else{a="that";d="this";$("img.this").animate({opacity:0.4},300);$("img.that").animate({opacity:1},300)}if(!$(b).hasClass("on")){vote.vote(b,c);vote.incrementCount()}vote.toggleVoteState(b);vote.highlightNext();vote.fireVoteTasks()},toggleVoteState:function(a){var b=$(a).parents("div[data-voteable-item-id]");$(b).find("div.check img").attr("src",core.webProxy+"/assets/0.014/images/icons/checkbox-voted.png");$(b).siblings("div[data-voteable-item-id]").find("div.check img").attr("src",core.webProxy+"/assets/0.014/images/icons/checkbox-off.png")},conditionToVote:function(){if(tot.loginNeeded&&!user.id){login.display(vote.overrideLoginCopy);return false}return true},overrideLoginCopy:""};var subscriptions={subscribed:null,subscribeToRounds:function(b){var a={action:"subscribeToRounds",tournamentId:tournament.id,subscribe:b};$.getJSON("/cmd/subscriptions",a,function(){})}};fire.onLoad(function(){$(".this, #voteButtonLeft").click(function(b){b.preventDefault();if(!vote.allow){core.error($("#voteButtonLeft .button"),vote.reasonNotAllowed,true);return false}var a=$(this);if(vote.conditionToVote()){vote.clickVoteBox(a,"this")}});$(".that, #voteButtonRight").click(function(b){b.preventDefault();if(!vote.allow){core.error($("#voteButtonRight .button"),vote.reasonNotAllowed,true);return false}var a=$(this);if(vote.conditionToVote()){vote.clickVoteBox(a,"that")}});$(".view-results").click(function(a){vote.viewResults(a)});$(".LIKE, .DISLIKE").click(function(){var a=$(this);comment.thumb(a)});$(".reply").click(function(){if(user.isLoggedIn()){$("#quoteSection").show();var a=$(this).attr("commentId");var b=$(".commentCopy[commentId="+a+"]").text();$("#quote").val(b);$("#quote").attr("commentId",a);window.location.hash="SHARE"}else{login.display()}});$("div[data-voteable-item-id]").hover(function(a){if(!$(this).find("div.check img").attr("src").contains("vote")){$(this).find("div.check img").attr("src",core.webProxy+"/assets/0.014/images/icons/checkbox-on.png")}},function(a){if(!$(this).find("div.check img").attr("src").contains("vote")){$(this).find("div.check img").attr("src",core.webProxy+"/assets/0.014/images/icons/checkbox-off.png")}})});
