{% extends "base.html" %}

{#
    A head block must be defined in the Pelican theme's base.html prior to
    closing the HTML head tag so that the siglican stylesheets and javascript
    can be added. simply adding:
        {% block head %}{% endblock %} 
    just before the head closer is sufficient.
#}

{% block head %}
    {{ super() }}
    <link rel="stylesheet" href="{{ SIGLICAN_THEME_URL }}/css/style.min.css">
{% endblock %}

{% block content %}
      <div id="main" role="main" class="twelve columns offset-by-four">
        <header>
          {% if SIGLICAN_ALBUM.breadcrumb %}
          <h2>
            {% for url, title in SIGLICAN_ALBUM.breadcrumb %}
            <a href="{{ url }}">{{ title }}</a>{% if not loop.last %} » {% endif %}
            {% endfor -%}
          </h2>
          <hr>
          {% endif %}
        </header>

        {% set numbers = ["zero", "one", "two", "three", "four", "five", "six",
        "seven", "eight", "nine", "ten", "eleven", "twelve"] %}
        {% set column_size = SIGLICAN_COLORBOX_COLUMN_SIZE %}
        {% set nb_columns = (12 / column_size)|int %}
        {% set column_size_t = numbers[column_size] %}

        {% if SIGLICAN_ALBUM.albums %}
        {% for alb in SIGLICAN_ALBUM.albums %}
          {% if loop.index % nb_columns == 1 %}
          <div id="albums" class="row">
          {% endif%}
            <div class="{{ column_size_t }} columns thumbnail
                        {% if loop.index % nb_columns == 1 %}alpha{% endif%}
                        {% if loop.index % nb_columns == 0 %}omega{% endif%}">
              <a href="{{ alb.url }}">
                <img src="{{ alb.thumbnail }}" class="album_thumb"
                    alt="{{ alb.name }}" title="{{ alb.name }}" /></a>
              <span class="album_title">{{ alb.title }}</span>
            </div>
          {% if loop.last or loop.index % nb_columns == 0 %}
          </div>
          {% endif%}
        {% endfor %}
        {% endif %}

        {% if SIGLICAN_ALBUM.medias %}
          {% macro img_description(media) -%}
            {% if media.big %} data-big="{{ media.big }}"{% endif %}
            {% if media.exif %}
              {% if media.exif.datetime %}
                data-date=", {{ media.exif.datetime }}"
              {% endif %}
            {% endif %}
          {%- endmacro %}
        <div id="gallery" class="row">
          {% for media in SIGLICAN_ALBUM.medias %}
            {% if media.type == "image" %}
            <div class="{{ column_size_t }} columns thumbnail
                        {% if loop.index % nb_columns == 1 %}alpha{% endif%}
                        {% if loop.index % nb_columns == 0 %}omega{% endif%}">
              <a href="{{ media.filename }}" class="gallery" title="{{ media.filename }}" {{ img_description(media) }}>
                <img src="{{ media.thumbnail }}" alt="{{ media.filename }}"
                    title="{{ media.title if media.title else media.filename }}" /></a>
            </div>
            {% endif %}
            {% if media.type == "video" %}
              <div class="{{ column_size_t }} columns thumbnail
                          {% if loop.index % nb_columns == 1 %}alpha{% endif%}
                          {% if loop.index % nb_columns == 0 %}omega{% endif%}">
                <a href="#{{ media.filename|replace('.', '')|replace(' ', '') }}"
                  class="gallery" inline='yes' title="{{ media.filename }}"
                  {% if media.big %} data-big="{{ media.big }}"{% endif %}>
                  <img src="{{ media.thumbnail }}" alt="{{ media.filename }}"
                      title="{{ media.title if media.title else media.filename }}" /></a>
              </div>
              <!-- This contains the hidden content for the video -->
              <div style='display:none'>
                <div id="{{ media.filename|replace('.', '')|replace(' ', '') }}">
                  <video controls>
                  <source src='{{ media.filename }}' type='video/webm' />
                  </video>
                </div>
              </div>
            {% endif %}
          {% endfor %}
        </div>
        {% endif %}

        {% if SIGLICAN_ALBUM.zip %}
        <div id="additionnal-infos" class="row">
          <p><a href="{{ album.zip }}"
              title="Download a zip archive with all images">Download ZIP</a></p>
        </div>
        {% endif %}

        {% if SIGLICAN_ALBUM.description %}
        <div id="description" class="row">
          {{ SIGLICAN_ALBUM.description }}
        </div>
        {% endif %}
      </div>
    </div>

    {% if SIGLICAN_ALBUM.medias %}
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>!window.jQuery && document.write(unescape('%3Cscript src="{{ SIGLICAN_THEME_URL }}/js/jquery-1.10.2.min.js"%3E%3C/script%3E'))</script>
    <script src="{{ SIGLICAN_THEME_URL }}/js/jquery.colorbox.min.js"></script>

    <script>
      $(".gallery").colorbox({
        rel:"gallery",
        transition:"none",
        maxWidth: "90%",
        maxHeight: "90%",
        scalePhotos: true,
        current: "{current} / {total}",
        title: function () {
          title = this.title;
          if(this.hasAttribute("data-big")) {
            title += " (full size)".link(this.getAttribute("data-big"));
          }
          if(this.hasAttribute("data-date")) {
            title += this.getAttribute("data-date");
          }
          return title;
        },
        inline: function() {
          return this.hasAttribute("inline");
        }
      });
    </script>
    {% endif %}

{% endblock %}