{%- extends "base.html" %}

{%- block title %}{{ site.title }}{% endblock %}

{%- block container %}
<div class="title">{{ site.title }}</div>

<div class="index">
  {%- if site.index %}  {# custom index page #}
    {{ page.content }}
  {%- else %}  {# auto generate index page #}
    {%- for category in pages %}
      {%- if site.default_ext not in category %}  {# is category #}
    <div class="category">
      <h2 id="{{ category.name }}">
        {%- if 'label' in category %}{{ category.label }}
        {%- else %}{{ category.name|capitalize }}{% endif %}
      </h2>
      <div class="category_pages">
        <ul>
          {%- for page in category.pages %}
            {%- if site.default_ext in page.fname %}  {# is page #}
          <li class="pagelist item_arrow">
              <a href="./{{ category.name }}/{{ page.name }}.html">{{ page.title }}</a>
              {%- if 'description' in page %}
              &nbsp;&nbsp;&nbsp;{{ page.description }}
              {% endif %}
            {%- elif 'pages' in page %}  {# is collection #}
          <li class="pagelist">
              {% set coll = page %}  {# for readability #}
              <div class="list_wrapper">
                <div class="coll_name item_arrow">{{ coll.name }}&nbsp;&#58;&nbsp;</div>
                <div class="coll_list">
              {%- for coll_page in coll.pages %}
                  <a href="./{{ category.name }}/{{ coll_page.name }}.html">{{ coll_page.title }}</a>
                {%- if 'description' in coll_page %}
                  &nbsp;{{ coll_page.description }}
                {% endif %}
                {%- if not loop.last %}&nbsp;&#47;&nbsp;{% endif %}
              {%- endfor %}
                </div>
              </div>
            {%- endif %}
          </li>
          {%- endfor %}
        </ul>
      </div> <!-- end category_pages -->
    </div> <!-- end category -->
      {%- endif %}
    <div class="clearfix"></div>
    {%- endfor %}
  {%- endif %}
</div>
{%- endblock %}

{%- block script %}
<script>
  var list_wrappers = document.getElementsByClassName('list_wrapper')
  for (var i = 0, len = list_wrappers.length; i < len; i++) {
    var list_wrapper = list_wrappers[i];
    var coll_name = list_wrapper.getElementsByClassName('coll_name')[0];
    var coll_list = list_wrapper.getElementsByClassName('coll_list')[0];
    var width = coll_name.clientWidth + 3;
    // http://stackoverflow.com/a/10118190/1276501
    coll_list.setAttribute("style","margin-left: " + width + "px");
    coll_list.style.marginLeft = width + "px";
  }
</script>
{%- endblock %}
