{#
    cloud/layout.html
    ~~~~~~~~~~~~~~~~~

    Sphinx layout template for the cloud theme.

    :copyright: Copyright 2009-2011 Assurance Technologies LLC
    :license: BSD

    roottarget - optional target for root link (default to toc)
    logotarget - optional target for logo link (defaults to root target)
    googleanalytics_id - if set, enabled google analytics snippet & footer
    googleanalytics_path - optional subpatch for GA cookie

#}

{% extends "basic/layout.html" %}

{% set reldelim2 = reldim2 is not defined and ' &nbsp; &nbsp;' or reldelim2 %}

{# compat hack for sphinx < 1.8 #}
{% macro compat_js_tag(asset) %}
    {% if js_tag is undefined %} {# sphinx 1.6 / 1.7 #}
        <script type="text/javascript" src="{{ pathto(asset, 1) }}"></script>
    {% else %} {# sphinx >= 1.8.0 #}
        {{ js_tag(asset) }}
    {% endif %}
{% endmacro %}

{%- block scripts %}
    {{ super() }}

    {# add script file to instrument collapsable sections  and other features #}
    {{ compat_js_tag("_static/jquery.cookie.js") }}
    {{ compat_js_tag("_static/cloud.base.js") }}
    {{ compat_js_tag("_static/cloud.js") }}

{%- endblock %}

{# add font stylesheets #}
{% set css_files = css_files + [theme_fontcssurl] %}

{# make root link redirectable #}
{%- set theme_roottarget = (theme_roottarget == "<toc>" and master_doc or theme_roottarget) %}
{% block rootrellink %}
    <li><a href="{{ pathto(theme_roottarget) }}">{{shorttitle|e}}</a>{{reldelim1}}</li>
{% endblock %}

{# make logo link redirectable #}
{%- set theme_logotarget = (theme_logotarget == "<root>" and theme_roottarget or (theme_logotarget == "<toc>" and master_doc or theme_logotarget)) %}
{%- block sidebarlogo %}
    {%- if logo %}
        <p class="logo"><a href="{{ pathto(theme_logotarget) }}" title="{{ theme_logotarget }}">
          <img class="logo" src="{{ pathto('_static/' + logo, 1) }}" alt="Logo"/>
        </a></p>
    {%- endif %}
{%- endblock %}

{# wrap relbars in distinct classes to make themeing easier #}
{%- block relbar1 %}
    <div class="relbar-top">
        {{ super() }}
    </div>
{% endblock %}

{%- block relbar2 %}
    <div class="relbar-bottom">
        {{ super() }}
    </div>
{% endblock %}

{% block extrahead -%}
        {{ super() }}
        <meta name="viewport" content="width=device-width, initial-scale=1">
        {%- if theme_googleanalytics_id -%}
<script type="text/javascript">
var ga_enabled = !$.cookie('disable-ga');
if(ga_enabled){
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '{{ theme_googleanalytics_id }}']);
  _gaq.push(['_setCookiePath', '{{ theme_googleanalytics_path }}']);
  _gaq.push(['_setDetectFlash', false]);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
}
</script>
        {%- endif %}
{%- endblock %}

{% block body -%}
    {# hack to insert lang=en in scope of div.body #}
    {% if theme_hyphenation_langage %}
        <div lang="{{ theme_hyphenation_language }}">{{ super() }}</div>
    {% endif %}
{%- endblock %}

{% block sidebar2 -%}
    {{ super() }}
    {# insert markup for sidebar toggle button #}
    {% block sidebartoggle %}
        <div class="sidebar-toggle-group no-js">
            {% set right = theme_rightsidebar|tobool %}
            <button class="sidebar-toggle" id="sidebar-hide" title="Hide the sidebar menu">
                {% if not right %} «{% endif %}
                <span class="show-for-small">hide menu</span>
                {% if right %} »{% endif %}
            </button>
            <button class="sidebar-toggle" id="sidebar-show" title="Show the sidebar menu">
                {% if right %} «{% endif %}
                <span class="show-for-small">menu</span>
                <span class="hide-for-small">sidebar</span>
                {% if not right %} »{% endif %}
            </button>
        </div>
    {% endblock %}
{%- endblock %}

{% block footer -%}
    {{ super() }}
    {%- if theme_googleanalytics_id -%}
<script type="text/javascript">
    if(ga_enabled){
        document.write("<div class=\"footer\">This page uses <a href=\"http://analytics.google.com\">Google Analytics</a> to collect statistics. ");
        document.write("Click <button title=\"set cookie to disable analytics for this site\" class=\"link\" onclick=\"$.cookie('disable-ga', 'true', {expires: 3650, path: '{{ theme_googleanalytics_path }}'}); window.location.reload(); return false; \">here</button> to disable analytics for this site.");
        document.write("</div>");
    }else{
        document.write("<div class=\"footer\">Google Analytics has been disabled. ");
        document.write("Click <button title=\"set cookie to re-enable analytics for this site\" class=\"link\" onclick=\"$.cookie('disable-ga', null, {path: '{{ theme_googleanalytics_path }}'}); window.location.reload(); return false; \">here</button> to re-enable analytics for this site.");
    };
</script>
    {%- endif %}
    <!-- cloud_sptheme 1.4 -->
{%- endblock %}
