       competitorStrings = []
       i = 0
       
-      $.each window.currentMatch['competitors'], (index, competitorId) ->
+      $.each @currentMatch['competitors'], (index, competitorId) =>
         competitorDomElement = $('#competitor_' + competitorId)
         checked = ' checked="checked"'
         checked = '' if i == 1
         radioButtons.push ('<input type="radio" ' + checked + ' name="winner" value="' + competitorId + '" style="position:relative; top:-5px "/>')
         
-        if window.competitiveListOptions['competitor_name_proc'] == undefined || $(competitorDomElement).find('.competitor_name').data('proc-argument') == undefined
+        if @competitiveListOptions['competitor_name_proc'] == undefined || $(competitorDomElement).find('.competitor_name').data('proc-argument') == undefined
           competitorStrings.push $(competitorDomElement).find('.competitor_name').html()  
         else
-          competitorStrings.push window.competitiveListOptions['competitor_name_proc']($(competitorDomElement).find('.competitor_name').data('proc-argument'))
+          competitorStrings.push @competitiveListOptions['competitor_name_proc']($(competitorDomElement).find('.competitor_name').data('proc-argument'))
           
         i += 1
         

<form class="form-inline" style="margin:0px;">
  <div class="modal-header">
    <button type="button" id="close_bootstrap_modal_button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Appoint Winner (#{window.matchesLeft} matches left)</h3>
  </div>
  <div class="modal-body" style="overflow-y:none;">
    <div class="controls" style="margin-left:50px">


      return true
    
  letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser: (winnerId, loserId) ->
    @defeatedCompetitorsByCompetitor[loserId] ||= []
    
    $.each window.matches, (index, match) =>  
      return true if match['winner_competitor'] == winnerId || $.inArray(winnerId, match['competitors']) == -1
      
      matchCompetitorsWhichIncludeLoser = jQuery.map(match['competitors'], (c) =>
        if $.inArray(c, @defeatedCompetitorsByCompetitor[loserId]) > -1
          return c
      )
        
      return true if matchCompetitorsWhichIncludeLoser.length == 0
        
      otherLoserId = @otherCompetitorOfMatch(match, winnerId)
      
      @changeCompetitorsComparisonResult(winnerId, otherLoserId) unless match['winner_competitor'] == undefined
        
      @appointWinnerOfMatch(index, winnerId, otherLoserId, match['winner_competitor'] == undefined)
      window.matches[index]['winner_competitor'] = winnerId
      window.matches[index]['auto_winner'] = true
      
  changeCompetitorsComparisonResult: (winnerId, loserId) ->
    @outmatchedCompetitorsByCompetitor[winnerId] ||= []
    @outmatchedCompetitorsByCompetitor[winnerId] = @removeItemFromArray(@outmatchedCompetitorsByCompetitor[winnerId], loserId)
    @defeatedCompetitorsByCompetitor[loserId] = @removeItemFromArray(@outmatchedCompetitorsByCompetitor[loserId], winnerId)
    
  getDefeatedCompetitorsByCompetitor: (competitorId) ->
    @defeatedCompetitorsByCompetitor[competitorId] ||= []
      
    return @defeatedCompetitorsByCompetitor[competitorId]

  otherCompetitorOfMatch: (match, competitorId) ->
    otherCompetitors = jQuery.map(match['competitors'], (c) ->
      if c != competitorId
        return c
    )
    return otherCompetitors[0]

  appointWinnerOfMatchByInput: () ->
    winnerId = parseInt($("input[name='winner']:checked").val())
    loserId = @otherCompetitorOfMatch(@currentMatch, winnerId)
    
    @appointWinnerOfMatch(@currentMatchIndex, winnerId, loserId, true)
    
    unless @nextMatch()
      @sortByMostWins()
      $('#bootstrap_modal').modal('hide')
      
  appointWinnerOfMatch: (matchIndex, winnerId, loserId, decrementMatchesLeft) ->
    window.matches[matchIndex]['winner_competitor'] = winnerId
    @matchesLeft = @matchesLeft - 1 if decrementMatchesLeft
    
    @updateDefeatedAndOutmatchedCompetitorsByCompetitor(winnerId, loserId)
    @letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser(winnerId, loserId)
    @letOutMatchedCompetitorsOfWinnerWinAgainstLoser(winnerId, loserId)
    
  letOutMatchedCompetitorsOfWinnerWinAgainstLoser: (winnerId, loserId) ->
    @outmatchedCompetitorsByCompetitor[winnerId] ||= []
    
    $.each @outmatchedCompetitorsByCompetitor[winnerId], (index, competitorId) =>
      @letCompetitorWinMatchAgainstOtherCompetitor(competitorId, loserId)
      
    return @outmatchedCompetitorsByCompetitor[competitorId]

  letCompetitorWinMatchAgainstOtherCompetitor: (winnerId, loserId) ->
    $.each window.matches, (index, match) =>
      if $.inArray(winnerId, match['competitors']) > -1 && $.inArray(loserId, match['competitors']) > -1 && match['winner_competitor'] != winnerId
        window.matches[index]['auto_winner'] = true
        @changeCompetitorsComparisonResult(winnerId, loserId) unless match['winner_competitor']  == undefined
        @appointWinnerOfMatch(index, winnerId, loserId, match['winner_competitor']  == undefined)
        
        return false

  updateDefeatedAndOutmatchedCompetitorsByCompetitor: (winnerId, loserId) ->
    @defeatedCompetitorsByCompetitor[winnerId] ||= []
    @defeatedCompetitorsByCompetitor[winnerId].push loserId  
     
    @outmatchedCompetitorsByCompetitor[loserId] ||= []
    @outmatchedCompetitorsByCompetitor[loserId].push winnerId
     
  cancelTournament: ->
    @sortByMostWins()
    $('#bootstrap_modal').modal('hide')
      
  sortByMostWins: ->
    winsByCompetitor = {}
    
    $.each @competitors, (index, competitorId) =>
      winsByCompetitor[competitorId] = 0

    $.each window.matches, (index, match) ->
      winsByCompetitor[match['winner_competitor']] += 1
    
    $.each Object.keys(winsByCompetitor), (index, competitorId) ->
      $('#competitor_' + competitorId).data 'wins', winsByCompetitor[competitorId]
      
    $wrapper = $('.competitive_list')
    
