<div class="wide box">
  <h1>
    <%= namelink @round.server %> : <%= longtime @round.start %>
  </h1>
</div>

<div class="wide box">
  <h2 class="center">
    General Info and Statistics
  </h2>

  <div class="wide center">
    <%= cascade @round, ["winner_s", "length", "commander", "map_name"] %>
  </div>

  <div class="equal left center">
    <% @round.logs.stats.each do |s| %>
      <% next unless @round.marine_stats.include? s.details %>
      <b><%= @round.marine_stats[s.details] %></b>: <%= s.num %> <br />
    <% end %>
  </div>
  <div class="equal left center">
    <% @round.logs.stats.each do |s| %>
      <% next unless @round.alien_stats.include? s.details %>
      <b><%= @round.alien_stats[s.details] %></b>: <%= s.num %> <br />
    <% end %>
  </div>
</div>

<% {Log::TEAM_MARINES => "Marines", Log::TEAM_ALIENS => "Aliens"}.each do |team, name| %>
  <div class="wide box">
    <h2 class="center">
      <%= name %>
    </h2>

    <table class="data">
      <tr>
        <th width="30%">Name</th>
        <th width="15%">ENSL</th>
        <th width="15%">Team</th>
        <th width="45">Roles</th>
        <th width="5%">Kills</th>
        <th width="5%">Deaths</th>
      </tr>
      <% @round.rounders.team(team).ordered.each do |rounder| %>
        <tr>
          <td><%= h rounder.name %></td>
          <td><%= namelink rounder.user if rounder.user %></td>
          <td><%= namelink rounder.ensl_team if rounder.ensl_team %></td>
          <td><%= h rounder.roles %></td>
          <td><%= rounder.kills %></td>
          <td><%= rounder.deaths %></td>
        </tr>
      <% end %>
    </table>
  </div>
<% end %>

<div class="wide box">
  <h2 class="center">
    Round Timeline
  </h2>

  <div id="roundEvents">
    <div id="roundAliens">
      <h4 class="center">
        Aliens
      </h4>

      <% alien_total = 0 %>
      <% consecutives = 0 %>
      <% @round.logs.each do |log| %>
        <% next unless e = Round.alien_event(log.details) %>
        <% next if log.details == "kill" and (m = log.frag)[2] != "alien" %> 
        <% add = log.since*8 - alien_total %>
        <% consecutives = add < 0 ? (consecutives + 1) : 0 %>
        <% left = 145 - (add < 0 ? 105*consecutives : 0) %>

        <% if log.details == "kill" %>
          <div class="roundEvent roundFrag" style="margin-top: <%= add %>px; margin-left: <%= left %>px" title="<%= log.time %>">
            <span>
              <%= Verification.uncrap(m[1])[0, 7] %>
            </span>
            <%= image_tag 'weapons/' + m[5]  + '.gif', :width => 22, :height => 14 %>
            <span>
              <%= Verification.uncrap(m[3])[0, 7] %>
            </span>
          </div>
        <% else %>
          <div class="roundEvent" style="margin-top: <%= add %>px; margin-left: <%= left %>px" title="<%= log.time %>">
            <% if ["onos", "fade", "lerk", "gorge"].include? log.details %>
              <%= Verification.uncrap(log.role[1])[0, 7] %> <%= log.role[2] %>s
            <% else %>
              <%= h e %> 
            <% end %>
          </div>
        <% end %>

        <% add = add + 15 %>
        <% alien_total = alien_total + (add > 0 ? add : 0) %>
      <% end %>
    </div>

    <div id="roundTimeline" style="height: <%= alien_total %>px"></div>

    <div id="roundMarines">
      <h4 class="center">
        Marines
      </h4>

      <% marine_total = 0 %>
      <% consecutives = 0 %>
      <% @round.logs.each do |log| %>
        <% next unless e = Round.marine_event(log.details) %>
        <% next if log.details == "kill" and (m = log.frag)[2] != "marine" %> 
        <% add = log.since*8 - marine_total %>
        <% consecutives = add < 0 ? (consecutives + 1) : 0 %>
        <% left = 3 + (add < 0 ? 105*consecutives : 0) %>

        <% if log.details == "kill" %>
          <div class="roundEvent roundFrag" style="margin-top: <%= add %>px; margin-left: <%= left %>px" title="<%= log.time %>">
            <span>
              <%= Verification.uncrap(m[1])[0, 7] %>
            </span>
            <%= image_tag 'weapons/' + m[5]  + '.gif', :width => 30, :height => 14 %>
            <span>
              <%= Verification.uncrap(m[3])[0, 7] %>
            </span>
          </div>
        <% else %>
          <div class="roundEvent" style="margin-top: <%= add %>px; margin-left: <%= left %>px" title="<%= log.time %>">
            <%= h e %>
          </div>
        <% end %>

        <% add = add + 15 %>
        <% marine_total = marine_total + (add > 0 ? add : 0) %>
      <% end %>
    </div>

    <% total = marine_total > alien_total ? marine_total : alien_total %>
    <script type="application/javascript">
      $('roundAliens').style.height = "<%= total + 20 %>px";
      $('roundTimeline').style.height = "<%= total + 20 %>px"
      $('roundMarines').style.height = "<%= total + 20 %>px"
      </script>
    </div>
  </div>

  <br class="clear">
