text: (function(){!function(t){var e;return e=e=function(){function e(t,e){t&&this.init(t,e)}return e.prototype.jqueryInstanceMethodName="competitiveList",e.prototype.defaults={},e.prototype.id=null,e.prototype.competitors=[],e.prototype.competitorsOfCompetitor={},e.prototype.defeatedCompetitorsByCompetitor={},e.prototype.outmatchedCompetitorsByCompetitor={},e.prototype.matches=[],e.prototype.matchesLeft=0,e.prototype.currentMatch=null,e.prototype.currentMatchIndex=0,e.prototype.currentAutoWinnerMatches=[],e.prototype.movingCompetitorToPosition=!1,e.prototype.init=function(e,n){return this.options=t.extend({},this.defaults,n),this.$el=t(e),this.id=this.$el.attr("id"),t.data(e,this.constructor.prototype.jqueryInstanceMethodName,this),this.$el.find(".competitive_list_start_link").on("click",function(t){return function(e){return e.preventDefault(),t.start()}}(this)),this.$el.find(".save_match_results_link").on("click",function(t){return function(e){return e.preventDefault(),t.sortByMostWins(),t.$el.find(".save_match_results_link").hide()}}(this)),t(document.body).on("click","#bootstrap_modal .cancel_tournament_button",function(t){return function(e){return e.preventDefault(),t.cancelTournament()}}(this)),t(document.body).on("click","#bootstrap_modal .select_winner_button",function(t){return function(e){return e.preventDefault(),t.appointWinnerOfMatchByInput()}}(this))},e.prototype.start=function(){var e,n;return e=!1,this.matches||(this.matches=[]),this.matches.length>0&&(e=!0),this.setCompetitors(),this.competitorsOfCompetitor={},this.defeatedCompetitorsByCompetitor={},this.outmatchedCompetitorsByCompetitor={},e&&(confirm("Remove previous results and start over?")?this.matches=[]:this.removeMatchesOfNonExistingCompetitors()),this.generateMatches(),n=jQuery.map(this.matches,function(t){return void 0===t.winner?t:void 0}),this.matchesLeft=n.length,this.nextMatch(!0)?t("#bootstrap_modal").modal("show"):void 0},e.prototype.setCompetitors=function(){return this.competitors=jQuery.map(this.$el.find(".competitive_list li"),function(e){return t(e).data("id")})},e.prototype.removeMatchesOfNonExistingCompetitors=function(){return t.each(this.matches,function(e){return function(n,o){var i,r,s,a,c,p;return p=jQuery.map(o.competitors,function(n){return-1===t.inArray(n,e.competitors)?n:void 0}),p.length>0?e.matches=e.removeItemFromArray(e.matches,o):((i=e.competitorsOfCompetitor)[a=o.competitors[0]]||(i[a]=[]),e.competitorsOfCompetitor[o.competitors[0]].push(o.competitors[1]),(r=e.competitorsOfCompetitor)[c=o.competitors[1]]||(r[c]=[]),e.competitorsOfCompetitor[o.competitors[1]].push(o.competitors[0]),void 0!==o.winner?(s=e.otherCompetitorOfMatch(o,o.winner),e.updateDefeatedAndOutmatchedCompetitorsByCompetitor(o.winner,s)):void 0)}}(this))},e.prototype.removeItemFromArray=function(t,e){var n;return n=[],jQuery.each(t,function(t,o){return JSON.stringify(o)!==JSON.stringify(e)?n.push(o):void 0}),n},e.prototype.generateMatches=function(){return t.each(this.competitors,function(e){return function(n,o){var i;return(i=e.competitorsOfCompetitor)[o]||(i[o]=[]),t.each(e.competitors,function(n,i){var r;return(r=e.competitorsOfCompetitor)[i]||(r[i]=[]),o!==i&&-1===t.inArray(i,e.competitorsOfCompetitor[o])?(e.matches.push({competitors:[o,i]}),e.competitorsOfCompetitor[o].push(i),e.competitorsOfCompetitor[i].push(o)):void 0})}}(this))},e.prototype.nextMatch=function(e){var n,o,i,r,s,a,c,p,h;return n="",this.currentAutoWinnerMatches.length>0&&(this.currentMatch=this.matches[this.currentMatchIndex],h="",t.each(this.currentAutoWinnerMatches,function(t){return function(e,n){var o,i;return o="",o=e%2===0?"even":"odd",i="",n.manual_winner_changed===!0&&(i='<a class="bootstrap_tooltip" href="#" data-toggle="tooltip" title="The winner you once have set has been changed automatically!">\n  <i class=\'icon-warning-sign\'/>\n</a>'),h+='<tr class="'+o+'">\n  <td>\n    '+i+'\n  </td>\n  <td style="width:200px">'+t.nameOfCompetitor(n.winner,!1)+'</td>\n  <td><input type="radio" checked="checked" disabled="disabled"/></td>\n  <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n  <td><input type="radio" disabled="disabled"/></td>\n  <td>&nbsp;&nbsp;&nbsp;</td>\n  <td style="width:200px">'+t.nameOfCompetitor(t.otherCompetitorOfMatch(n,n.winner),!1)+'</td>\n  <td style="text-align:center">\n    <a class="bootstrap_tooltip" href="#" data-toggle="tooltip" data-html="true" title="'+n.auto_winner_reason+'">\n      <i class="icon-question-sign"/>\n    </a>\n  </td>\n  <td style="width:200px">'+t.nameOfCompetitor(n.foot_note_competitor,!1)+"</td>\n</tr>        "}}(this)),n="<h4>Auto Winners due to Result of last Match</h4>\n<table>\n  <tr>\n    <td><strong>Last Match was:&nbsp;&nbsp;</strong></td>\n    <td>"+this.nameOfCompetitor(this.currentMatch.winner,!1)+'</td>\n    <td>&nbsp;&nbsp;<input type="radio" checked="checked" disabled="disabled"/></td>\n    <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n    <td><input type="radio" disabled="disabled"/></td>\n    <td>&nbsp;&nbsp;&nbsp;</td>\n    <td>'+this.nameOfCompetitor(this.otherCompetitorOfMatch(this.currentMatch,this.currentMatch.winner),!1)+'</td>\n  </tr>\n</table>\n<table class="table table-striped">\n  <thead>\n    <tr class="odd">\n      <th></th>\n      <th>Winner</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th>Loser</th>\n      <th>Reason</th>\n      <th>[1]</th>\n    </tr>\n  </thead>\n  <tbody>\n    '+h+"\n  </tbody>\n</table>   "),this.currentMatch=null,t.each(this.matches,function(t){return function(e,n){return void 0===n.winner?(t.currentMatch=n,t.currentMatchIndex=e,!1):void 0}}(this)),e===!0&&null===this.currentMatch?(alert("No matches to rate left."),!1):(this.$el.find(".save_match_results_link").show(),s="",c="",a="",null===this.currentMatch?(c="No matches to rate left.",a='<p>\n  <button type="button" class="cancel_tournament_button btn btn-default">Save match results and close window</button>\n</p>      '):(c="Appoint Winner ("+this.matchesLeft+" matches left)",p=[],o=[],r=0,t.each(this.currentMatch.competitors,function(t){return function(e,n){var i;return i=' checked="checked"',1===r&&(i=""),p.push('<input type="radio" '+i+' name="winner" value="'+n+'" style="position:relative; top:-5px "/>'),o.push(t.nameOfCompetitor(n,!0)),r+=1}}(this)),s+='<div class="controls" style="margin-left:50px">\n  <table>\n    <tr>      \n      <td style="width:325px; text-align:right;">\n        '+o[0]+"\n      </td>\n      <td>&nbsp;&nbsp;&nbsp;</td>\n      <td>"+p[0]+"</td>\n      <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n      <td>"+p[1]+'</td>\n      <td>\n        &nbsp;&nbsp;&nbsp;\n      </td>\n      <td style="width:325px">\n        '+o[1]+"\n      </td>\n    </tr>\n  </table>\n</div>     ",a='<p>\n  <button type="button" class="cancel_tournament_button btn btn-default">Save match results and close window</button> &nbsp;&nbsp;&nbsp;&nbsp;\n  <button type="button" class="select_winner_button btn btn-primary">Submit</button>\n</p>'),s+=n,i='<div class="modal-dialog">\n  <div class="modal-content">    \n    <form class="form-inline" style="margin:0px;">\n      <div class="modal-header">\n        <button type="button" id="close_bootstrap_modal_button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\n        <h3>'+c+'</h3>\n      </div>\n      <div class="modal-body" style="overflow-y:auto;">\n        '+s+'\n      </div>\n      <div class="modal-footer" style="text-align:left;">\n        '+a+"\n      </div>\n    </form>\n  </div>\n</div>",t("#bootstrap_modal").html(i),t(".bootstrap_tooltip").tooltip(),this.currentAutoWinnerMatches=[],!0)},e.prototype.otherCompetitorOfMatch=function(t,e){var n;return n=jQuery.map(t.competitors,function(t){return t!==e?t:void 0}),n[0]},e.prototype.nameOfCompetitor=function(e,n){var o;return o=t("#competitor_"+e),n===!1||void 0===this.options.competitor_name_proc||void 0===t(o).find(".competitor_name").data("proc-argument")?t(o).find(".competitor_name").html():this.options.competitor_name_proc(t(o).find(".competitor_name").data("proc-argument"))},e.prototype.cancelTournament=function(){return this.sortByMostWins(),this.$el.find(".save_match_results_link").hide(),t("#bootstrap_modal").modal("hide")},e.prototype.appointWinnerOfMatchByInput=function(){var e,n;return n=parseInt(t("input[name='winner']:checked").val()),e=this.otherCompetitorOfMatch(this.currentMatch,n),this.appointWinnerOfMatch(this.currentMatchIndex,n,e,!0),this.nextMatch(!1)},e.prototype.appointWinnerOfMatch=function(t,e,n,o){return this.movingCompetitorToPosition===!0&&(delete this.matches[t].manual_winner_changed,delete this.matches[t].auto_winner,delete this.matches[t].foot_note_competitor,delete this.matches[t].auto_winner_type,delete this.matches[t].auto_winner_recursion,delete this.matches[t].auto_winner_reason),this.matches[t].winner=e,o&&(this.matchesLeft=this.matchesLeft-1),this.updateDefeatedAndOutmatchedCompetitorsByCompetitor(e,n),this.letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser(e,n),this.letOutMatchedCompetitorsOfWinnerWinAgainstLoser(e,n)},e.prototype.updateDefeatedAndOutmatchedCompetitorsByCompetitor=function(t,e){var n,o;return(n=this.defeatedCompetitorsByCompetitor)[t]||(n[t]=[]),this.defeatedCompetitorsByCompetitor[t].push(e),(o=this.outmatchedCompetitorsByCompetitor)[e]||(o[e]=[]),this.outmatchedCompetitorsByCompetitor[e].push(t)},e.prototype.letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser=function(e,n){var o;return(o=this.defeatedCompetitorsByCompetitor)[n]||(o[n]=[]),t.each(this.matches,function(o){return function(i,r){var s,a,c;return r.winner===e||-1===t.inArray(e,r.competitors)?!0:(a=jQuery.map(r.competitors,function(e){return t.inArray(e,o.defeatedCompetitorsByCompetitor[n])>-1?e:void 0}),0===a.length?!0:(c=o.otherCompetitorOfMatch(r,e),s=!1,void 0!==r.winner&&(o.removeCompetitorsComparisonResult(e,c),o.movingCompetitorToPosition!==!0&&r.auto_winner!==!0&&(s=!0)),o.appointWinnerOfMatch(i,e,c,void 0===r.winner),o.movingCompetitorToPosition===!0?!0:(o.matches[i].manual_winner_changed=s,o.matches[i].auto_winner=!0,o.matches[i].foot_note_competitor=n,o.matches[i].auto_winner_type=0,e===o.currentMatch.winner&&n===o.otherCompetitorOfMatch(o.currentMatch,o.currentMatch.winner)?(o.matches[i].auto_winner_recursion=!1,o.matches[i].auto_winner_reason="loser has been defeated because he loses against the loser <sup>[1]</sup> of last match"):(o.matches[i].auto_winner_recursion=!0,o.matches[i].auto_winner_reason="loser has been defeated because he loses against the loser <sup>[1]</sup> of last auto winner match"),o.currentAutoWinnerMatches.push(o.matches[i]))))}}(this))},e.prototype.removeCompetitorsComparisonResult=function(t,e){var n;return(n=this.outmatchedCompetitorsByCompetitor)[t]||(n[t]=[]),this.outmatchedCompetitorsByCompetitor[t]=this.removeItemFromArray(this.outmatchedCompetitorsByCompetitor[t],e),this.defeatedCompetitorsByCompetitor[e]=this.removeItemFromArray(this.defeatedCompetitorsByCompetitor[e],t)},e.prototype.letOutMatchedCompetitorsOfWinnerWinAgainstLoser=function(e,n){var o;return(o=this.outmatchedCompetitorsByCompetitor)[e]||(o[e]=[]),t.each(this.outmatchedCompetitorsByCompetitor[e],function(o){return function(i,r){return t.each(o.matches,function(i,s){var a;return t.inArray(r,s.competitors)>-1&&t.inArray(n,s.competitors)>-1&&s.winner!==r?(a=!1,void 0!==s.winner&&(o.removeCompetitorsComparisonResult(r,n),o.movingCompetitorToPosition!==!0&&s.auto_winner!==!0&&(a=!0)),o.appointWinnerOfMatch(i,r,n,void 0===s.winner),o.movingCompetitorToPosition===!0?!0:(o.matches[i].manual_winner_changed=a,o.matches[i].auto_winner=!0,o.matches[i].auto_winner_type=1,o.matches[i].foot_note_competitor=e,e===o.currentMatch.winner&&n===o.otherCompetitorOfMatch(o.currentMatch,o.currentMatch.winner)?(o.matches[i].auto_winner_recursion=!1,o.matches[i].auto_winner_reason="loser of last match has been defeated by outmatched competitor of<br/>winner <sup>[1]</sup>"):(o.matches[i].auto_winner_recursion=!0,o.matches[i].auto_winner_reason="loser of last auto winner match has been defeated by outmatched competitor of winner <sup>[1]</sup>"),o.currentAutoWinnerMatches.push(s),!1)):void 0})}}(this))},e.prototype.moveCompetitorToPosition=function(e,n,o){var i,r,s,a;return null==o&&(o=null),this.movingCompetitorToPosition=!0,this.setCompetitors(),this.competitorsOfCompetitor={},this.removeMatchesOfNonExistingCompetitors(),this.generateMatches(),a=this.getPositions(),r=null,i=null,s=a[n]===e?n+1:n,n>Object.keys(a).length?(alert("This position is not available!"),null!==o&&o(),void(this.movingCompetitorToPosition=!1)):(1===n||n-1>Object.keys(a).length||(r=a[n-1]),s>Object.keys(a).length||(i=a[s]),t.each(this.matches,function(n){return function(o,s){var a,c,p;return-1===t.inArray(e,s.competitors)?!0:(p=null,a=null,c=n.otherCompetitorOfMatch(s,e),c===r&&s.winner!==c?(p=c,a=e,r=null):c===i&&s.winner!==e&&(p=e,a=c,i=null),null===p?!0:(void 0!==s.winner&&n.removeCompetitorsComparisonResult(p,a),n.currentMatch=s,n.currentMatchIndex=o,n.appointWinnerOfMatch(o,p,a,!1),null===r&&null===i?!1:void 0))}}(this)),this.sortByMostWins(o),this.movingCompetitorToPosition=!1)},e.prototype.sortByMostWins=function(e){var n,o,i,r;return null==e&&(e=null),r={},t.each(this.competitors,function(){return function(t,e){return r[e]=0}}(this)),t.each(this.matches,function(t){return function(e,n){return delete t.matches[e].auto_winner_reason,r[n.winner]+=1}}(this)),t.each(Object.keys(r),function(e,n){return t("#competitor_"+n).data("wins",r[n])}),n=this.$el.find(".competitive_list"),n.find("li").sort(function(e,n){return+parseInt(t(n).data("wins"))-+parseInt(t(e).data("wins"))}).appendTo(n),i=this.getPositions(),void 0!==n.data("update-all-positions-path")?(o={_method:"put",positions:i,matches:JSON.stringify(this.matches)},t.post(n.data("update-all-positions-path"),o).always(function(){return function(){return null!==e?e():void 0}}(this))):void 0},e.prototype.getPositions=function(){var e,n;return n={},e=1,t.each(this.$el.find(".competitive_list li"),function(o,i){return n[e]=t(i).data("id"),t(i).data("position",e),t(i).find(".competitor_position").html(e),e+=1}),n},e}(),t.pluginFactory=function(e){return t.fn[e.prototype.jqueryInstanceMethodName]=function(n){var o,i;return i=t.makeArray(arguments),o=i.slice(1),this.each(function(){var r;return r=t.data(this,e.prototype.jqueryInstanceMethodName),r?"string"==typeof n?r[n].apply(r,o):r.update?r.update.apply(r,i):void 0:new e(this,n)})}},t.pluginFactory(e)}(window.jQuery,window)}).call(this);