<% default_action = false %>

<div class="tabs">
  <ul>
  <% tabs.each do |tab| -%>
    <% action = get_tab_action(tab) %>
    <li><%= link_to l(tab[:label]), (tab[:url] || { :tab => tab[:name] }),
                                    :id => "tab-#{tab[:name]}",
                                    :class => (tab[:name] != selected_tab ? nil : 'selected'),
                                    :onclick => (action.nil? ? nil : "#{ action }; return false;") %></li>
    <% default_action = action if tab[:name] == selected_tab %>
  <% end -%>
  </ul>
  <div class="tabs-buttons" style="display:none;">
    <button class="tab-left icon-only" type="button" onclick="moveTabLeft(this);">
      <%= sprite_icon "angle-left" %>
    </button>
    <button class="tab-right icon-only" type="button" onclick="moveTabRight(this);">
      <%= sprite_icon "angle-right" %>
    </button>
  </div>
</div>

<% tabs.each do |tab| -%>
  <%= content_tag('div', (render(:partial => tab[:partial], :locals => {:tab => tab}) if tab[:partial]) ,
                       :id => "tab-content-#{tab[:name]}",
                       :style => (tab[:name] != selected_tab ? 'display:none' : nil),
                       :class => 'tab-content') if tab[:partial] || tab[:remote] %>
<% end -%>

<%= javascript_tag default_action if default_action %>
