{% extends "skel.html" %}
{% load kegweblib %}
{% load humanize %}

{% block title %}{% if kbsite.settings.title %}{{ kbsite.settings.title }}{% else %}Kegbot{% endif %}{% endblock %}

{% block js %}
{{ block.super }}

  <script type="text/javascript">
    $(document).ready(function() {
        var defaultUseMetric = {% if kbsite.settings.volume_display_units != 'metric' %}false{% else %}true{% endif%};
        window.app.setApiBase("/api/")

        window.app.getPageSettings().setMetric(defaultUseMetric);
        window.app.getPageSettings().setGuestInfo("{{kbsite.settings.guest_name}}",
            "{% if kbsite.settings.guest_image %}{{kbsite.settings.guest_image.thumbnail.url}}{% else %}{{STATIC_URL}}images/unknown-drinker.png{% endif %}");
        $("span.hmeasure").autounits({metric:defaultUseMetric})
        $("abbr.timeago").timeago();
        $(".alert").alert()
        $(".clickable").each(function() {
          var href = $(this).attr("data-href");
          $(this).click(function(e) {
            var node = e.target.nodeName.toLowerCase();
            if (node == 'a' || node == 'img') return;
            window.location = href;
            return false;
          });
        });
        $("img.lazy").lazyload();
        $("a.gallery-image").fancybox({
          'speedIn' : 100,
          'speedOut' : 100,
          'titlePosition' : 'inside',
          'cyclic' : true,
        });
    });
  </script>

  {% if user.is_staff %}
  {% include 'kegadmin/includes/extrajs.html' %}
  {% endif %}

  <style>
    body {
  {% if kbsite %}{% if kbsite.settings.background_image %}
      background-image: url({{kbsite.settings.background_image.image.url}});
  {% else %}
      background-image: url({{ STATIC_URL }}images/background.png);
  {% endif %} {% endif %}
      background-repeat: no-repeat;
      background-attachment: fixed;
    }
  </style>

{% endblock js %}

{% block body %}
  <div class="navbar navbar-inverse navbar-fixed-top">
    <div class="navbar-inner">
      <div class="container">
        {% spaceless %}
        {% if kbsite %}
        <a class="brand" href="{% url "kb-home" %}">
        {% else %}
        <a class="brand" href="/">
        {% endif %}
        {{ kbsite.settings.title }}
        </a>{% endspaceless %}

        <ul class="nav">
          {% if kbsite %}
          {% if HAVE_SESSIONS %}{% navitem "kb-sessions" "Sessions" %}{% endif %}
          {% navitem "kb-kegs" "Kegs" %}
          {% navitem "kb-stats" "Stats" %}
          {% if user.is_authenticated %}{% navitem "kb-account-main" "Account" %}{% endif %}
          {% if user.is_staff %}
          {% navitem "kegadmin-dashboard" "Admin" %}
          {% endif %}
          {% endif %}
        </ul>

        {% if not user.is_authenticated %}
        <ul class="nav pull-right">
          {% if kbsite.settings.registration_allowed %}
          <li><a href="{% url "registration_register" %}"><i class="icon-edit icon-white"></i> New Drinker</a></li>
          {% endif %}
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user icon-white"></i> Sign In <b class="caret"></b></a>
            <ul class="dropdown-menu" style="padding: 15px;">
              <form action="/accounts/login/" method="POST">
                {% csrf_token %}
                {% with login_form as form %}
                  {% for hidden in form.hidden_fields %}
                  {{ hidden }}
                  {% endfor %}
                {% endwith %}
                <input class="span2" name="username" type="text" placeholder="Username" >
                <input class="span2" name="password" type="password" placeholder="Password">
                <button class="btn" type="submit">Log In <i class="icon-ok"></i></button>
              </form>
            </ul>
          </li>
        </ul>
        {% else %}
        <ul class="nav pull-right">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user icon-white"></i> {{ user.username}} <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="{% url "django.contrib.auth.views.logout" %}">Logout</a></li>
            </ul>
          </li>
        </ul>
        {% endif %}

      </div>
    </div>
  </div> <!-- /.navbar -->

  <div class="container">
    {% block header-margin %}
    <div class="page-header">
      <h1>{% block pagetitle %}{% endblock %}</h1>
      {% block breadcrumbs %}{% endblock %}
      {% block messages %}
      {% for message in messages %}
        <div class="alert {% for tag in message.tags.split %}alert-{{tag}} {% endfor %}">
          <a class="close" data-dismiss="alert" href="#">×</a>
          <p>
            {{message}}
          </p>
        </div>
      {% endfor %}
      {% endblock messages %}
    </div>
    {% endblock %}

    <div id="content">
    {% block content %}{% endblock %}
    {% block extra-content %}{% endblock %}
    </div>

    <footer>
      <p class="muted">
        <small>
          Powered by
          <a href="http://kegbot.org/?utm_source=kbserver">Kegbot&trade;</a>{% if user.is_staff %}, version {{ VERSION }}{% endif %}
          &mdash;
          &copy; 2003-2013 <a href="http://bevbot.com/?utm_source=kbserver">Bevbot LLC</a>
          &mdash;
          Charts by <a href="http://highcharts.com/" target="_blank">Highcharts</a>
          &mdash;
          <a href='#' onClick='window.app.get("pageSettings").toggleMetric();'>Toggle Units</a>
          <span id="page-settings"></span>
        </small>
      </p>
    </footer>
  </div> <!-- /container -->
{% endblock body %}

