{% extends host_template %}

{% load i18n cyclope_utils fb_versions obj_perms %}

{% block extra_head %}
{{ block.super }}
<script type="text/javascript">
var hide_children = function (el){
    $(el).children('ul').css('display', 'none');
}

var show_children = function (el){
    $(el).children('ul').css('display', 'block');
}

jQuery(document).ready(function(){
    $('.category_add_content').each(function(){
        hide_children($(this));
    });
    $('.category_add_content').each(function(){
        $(this).mouseenter(function(){
            show_children($(this));
            return false;
        })
        $(this).mouseleave(function(){
            hide_children($(this));
            return false;
        });
    });
});
</script>
{% endblock %}

{% block content %}

  {% per_category_perms category as cat_perms %}
  {% if cat_perms.add_content %}
  <div class="category_add_content">
    <a href="{% url category-default category.slug %}">{% trans "Add content" %}</a>
    <ul class="content_types">
      {% for c_type in category.collection.content_types.all %}
      <li>
        <a href="/admin/{{ c_type.app_label }}/{{ c_type.model }}/add?_frontend=1&_popup=1&_from_category={{category.slug}}" class="add_content add_{{ c_type.model }}">
          {{ c_type.name.capitalize }}
        </a>
      </li>
      {% endfor %}
    </ul>
  </div>
  {% endif %}

  {% if view_options.navigation == "TOP" %}
    {% include 'collections/hierarchycal_navigation_block.html' %}
  {% endif %}

  {% if view_options.show_title %}
  <div class="category_title">
    <h1 class="title">
      <a href="{% url category-default category.slug %}">{{ category.name }}</a>
    </h1>
  </div>
  {% endif %}

  {% if category.description and view_options.show_description or category.image and view_options.show_image %}
  <div class="collection_teaser">
    {% if category.image and view_options.show_image %}
    <img class="image" src="{% version category.image.path 'small' %}" border="0"/>
    {% endif %}
    {% if category.description and view_options.show_description %}
    <div class="summary">{{ category.description|smart_style }}</div>
    {% endif %}
  </div>
  {% endif %}

  {% block category_content %}{% endblock %}
  {% spaceless %}
  {% if view_options.navigation == "BOTTOM" %}
    {% include 'collections/hierarchycal_navigation_block.html' %}
  {% endif %}

  {% if page %}
    {% if view_options.sort_by == "ALPHABETIC" %}
      {% include 'cyclope/alphabetical_pagination_block.html' %}
    {% else %}
      {% include 'cyclope/pagination_block.html' %}
    {% endif %}
  {% endif %}
  {% endspaceless %}
{% endblock %}
