<% provide :title, params[:query] ? t('.title', :q => params[:query]) : t('.title_main') %>
<div id="pool-index">
  <div style="margin-bottom: 2em;">
    <%= form_tag({:action => "index"}, :method => :get) do %>
      <% if params.has_key?(:order) %>
      <%= hidden_field_tag "order", params[:order] %>
      <% end %>
      <%= text_field_tag "query", params[:query], :size => 40 %>
      <%= submit_tag t('.search') %>
    <% end %>
  </div>

  <%= image_tag 'blank.gif', :id => 'hover-thumb', :alt => '', :style => 'position: absolute; display: none; border: 2px solid #000; right: 42%;' %>

  <table width="100%" class="highlightable">
    <thead>
      <tr>
        <th width="60%"><%= t('.table.name') %></th>
        <th width="*"><%= t('.table.creator') %></th>
        <th width="*"><%= t('.table.posts') %></th>
        <th width="*"><%= t('.table.created') %></th>
        <th width="*"><%= t('.table.updated') %></th>
      </tr>
    </thead>
    <tbody>
      <% @pools.each do |p| %>
        <tr class="<%= cycle 'even', 'odd' %>" id="p<%= p.id %>">
          <td><%= link_to h(p.pretty_name), :action => "show", :id => p.id %></td>
          <td><%= h(p.user.pretty_name) %></td>
          <td><%= p.post_count %></td>
          <td><%= t('time.x_ago', :t => time_ago_in_words(p.created_at)) %></td>
          <td><%= t('time.x_ago', :t => time_ago_in_words(p.updated_at)) %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>

<div id="paginator">
  <%= will_paginate(@pools) %>
</div>

<% content_for :post_cookie_javascripts do %>
<script type="text/javascript">
  var thumb = $("hover-thumb");
  <% @samples.each do |pool, post| %>
    Post.register(<%= json_escape post.to_json.html_safe %>);
    var hover_row = $("p<%= pool.id %>");
    var container = hover_row.up("TABLE");
    Post.init_hover_thumb(hover_row, <%= post.id %>, thumb, container);
  <% end %>
  Post.init_blacklisted({replace: true});
</script>

<script class="js-preload-posts" type="application/json">
  <%= @samples.map { |pool, post| { id: post.id, url: post.preview_url } }.to_json.html_safe %>
</script>
<% end %>

<%= render :partial => "footer" %>
