<h3><%= t('.title_html', :name => link_to(@pool.pretty_name, :action => :show, :id => @pool.id)) %></h3>
<p><%= t('.info') %></p>

<script type="text/javascript">
  function orderAutoFill() {
    var i = 0
    var step = parseInt(prompt('<%= t('.interval') %>'))

    $$(".pp").each(function(x) {
      x.value = i
      i += step
    })
  }

  function orderReverse() {
    var orders = []
    $$(".pp").each(function(x) {
      orders.push(x.value)
    })
    var i = orders.size() - 1
    $$(".pp").each(function(x) {
      x.value = orders[i]
      i -= 1
    })
  }

  function orderShift(start, offset) {
    var found = false;
    $$(".pp").each(function(x) {
      if(x.id == "pool_post_sequence_" + start)
        found = true;
      if(!found)
        return;
      x.value = Number(x.value) + offset;
    });
  }
</script>

<%= form_tag(:action => "order") do %>
  <%= hidden_field_tag "id", @pool.id %>
  <table>
    <thead>
      <tr>
        <th></th>
        <th><%= t('.order') %></th>
      </tr>
    </thead>
    <tbody>
      <% @pool_posts.each do |pp| %>
        <tr>
          <td>
            <% if pp.post.can_be_seen_by?(@current_user) %>
              <%= link_to(image_tag(pp.post.preview_url, :width => pp.post.preview_dimensions[0], :height => pp.post.preview_dimensions[1]), {:controller => "post", :action => "show", :id => pp.post_id}, :title => pp.post.cached_tags)%>
            <% end %>
          </td>
          <td>
            <%= text_field_tag "pool_post_sequence[#{pp.id}]", pp.sequence, :class => "pp", :size => 5, :tabindex => 1 %>
            <%= link_to_function t('.plus_one'), "orderShift(#{pp.id}, +1)", :class=>"text-button" %>
            <%= link_to_function t('.minus_one'), "orderShift(#{pp.id}, -1)", :class=>"text-button" %>
          </td>
        </tr>
      <% end %>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="2"><%= submit_tag t('buttons.save'), :tabindex => 2 %> <%= button_to_function t('.auto_order'), "orderAutoFill()", :tabindex => 2 %> <%= button_to_function t('.reverse'), "orderReverse()", :tabindex => 2 %> <%= button_to_function t('buttons.cancel'), "history.back()", :tabindex => 2 %></td>
      </tr>
    </tfoot>
  </table>
<% end %>
