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

{%- block extrahead %}
  {{ super() }}
  <link rel="stylesheet" href="{{ pathto('_static/custom.css', 1) }}" type="text/css" />
  {% if theme_touch_icon %}
    <link rel="apple-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" />
  {% endif %}
  {% if theme_canonical_url %}
    <link rel="canonical" href="{{ theme_canonical_url }}{{ pagename }}.html"/>
  {% endif %}
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  <link rel="stylesheet" href="{{ pathto('_static/css/hljs_styles/monokai.css', 1) }}" type="text/css" />
  <script type="text/javascript" src="{{ pathto('_static/js/highlight.pack.js', 1) }}"></script>
  <script src="https://cdn.rawgit.com/iacchus/abcjs/master/bin/abcjs_plugin_3.1.2-hotfix-min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script>
  $(document).ready(function() {
    $('.highlight-none pre').each(function(i, block) {
      hljs.highlightBlock(block);
    });
    $('.highlight pre').each(function(i, block) {
      hljs.highlightBlock(block);
    });
  });
</script>

<script>
  abcjs_plugin_autostart = false;
  window.ABCJS.plugin.auto_render = false;

$(document).ready(function(){
  function is_it_abc(elem) {
    if(window.ABCJS.plugin.getABCContainingElements(elem).length) return true;
    else return false;
  }

  if($(".highlight-abc pre").length)
  {
    var tunes_code = $(".highlight-abc pre");
			
    for(var $i=0; tunes_code[$i]; $i++)
    {               
      if(! is_it_abc($(tunes_code[$i]))) continue;

      var ws_strip="";
      var mystr="";

      ws_strip = $(tunes_code[$i]).text().split('\n');
      for(var aaa=0; ws_strip[aaa]; aaa++) { mystr+=ws_strip[aaa].trim() + "\n"; }

      $(tunes_code[$i]).text(mystr); //abctune

      $('<div id="abctune-' + $i + '" class="abctune-rendered"></div>').insertBefore($(tunes_code[$i]).parent());
      ABCJS.renderAbc(
        "abctune-"+$i, //container
        "%%staffsep 27pt\n" + $(tunes_code[$i]).text(), //abctune
        { }, //parserParams
        {
          scale: 1,
          staffwidth:600,
          paddingtop: 0,
          paddingbottom: 0,
          paddingright: 0,
          paddingleft: 0,
        }, //engraverParams
        { viewportHorizontal: true } //renderParams
      );
      $(tunes_code[$i]).parent().hide();
    }
  }

  if($("code.abckeep").length)
  {
    var tunes_code = $("code.abckeep");
			
    for(var $i=0; tunes_code[$i]; $i++)
    {               
      if(! is_it_abc($(tunes_code[$i]))) continue;

      var ws_strip="";
      var mystr="";

      ws_strip = $(tunes_code[$i]).text().split('\n');
      for(var aaa=0; ws_strip[aaa]; aaa++) { mystr+=ws_strip[aaa].trim() + "\n"; }

      $(tunes_code[$i]).text(mystr); //abctune

      $('<div id="abctunekeep-' + $i + '" class="abctune-rendered"></div>').insertBefore($(tunes_code[$i]).parent());
      ABCJS.renderAbc(
        "abctunekeep-"+$i, //container
        "%%staffsep 27pt\n"+$(tunes_code[$i]).text(), //abctune
        { }, //parserParams
        {
          scale: 1,
          staffwidth:700,
          paddingtop: 0,
          paddingbottom: 0,
          paddingright: 0,
          paddingleft: 0,
        }, //engraverParams
        { viewportHorizontal: true } //renderParams
      );
      $(tunes_code[$i]).parent().css({marginTop:0})
      //$(tunes_code[$i]).hide();
    }
  }
})
</script>
{% endblock %}
{# top+bottom related navs; we also have our own in sidebar #}
{%- macro rellink_markup() %}
  <nav id="rellinks">
    <ul>
      {%- if prev %}
        <li>
          &larr;
          <a href="{{ prev.link|e }}" title="Previous document">{{ prev.title }}</a>
        </li>
      {%- endif %}
      {%- if next %}
        <li>
          <a href="{{ next.link|e }}" title="Next document">{{ next.title }}</a>
          &rarr;
        </li>
      {%- endif %}
    </ul>
  </nav>
{%- endmacro %}

{%- set theme_show_relbar_top = theme_show_relbar_top or theme_show_relbars %}
{%- set theme_show_relbar_bottom = theme_show_relbar_bottom or theme_show_relbars %}

{# removed existing top+bottom related nav, and embed in main content #}
{%- block relbar1 %}{% endblock %}
{%- block relbar2 %}{% endblock %}

{# Nav should appear before content, not after #}
{%- block content %}
{%- if theme_fixed_sidebar|lower == 'true' %}
  <div class="document">
    {{ sidebar() }}
    {%- block document %}
      <div class="documentwrapper">
      {%- if render_sidebar %}
        <div class="bodywrapper">
      {%- endif %}

          {%- block relbar_top %}
            {%- if theme_show_relbar_top|tobool %}
              <div class="related top">
                &nbsp;
                {{- rellink_markup () }}
              </div>
            {%- endif %}
          {% endblock %}

          <div class="body" role="main">
            {% block body %} {% endblock %}
          </div>

          {%- block relbar_bottom %}
            {%- if theme_show_relbar_bottom|tobool %}
              <div class="related bottom">
                &nbsp;
                {{- rellink_markup () }}
              </div>
            {%- endif %}
          {% endblock %}

      {%- if render_sidebar %}
        </div>
      {%- endif %}
      </div>
    {%- endblock %}
    <div class="clearer"></div>
  </div>
{%- else %}
{{ super() }}
{%- endif %}
{%- endblock %}

{%- block footer %}
    <div class="footer">
      {% if show_copyright %}&copy;{{ copyright }}.{% endif %}
      {% if theme_show_powered_by|lower == 'true' %}
      {% if show_copyright %}|{% endif %}
      Powered by <a href="http://sphinx-doc.org/">Sphinx {{ sphinx_version }}</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster {{ alabaster_version }}</a>
      {% endif %}
      {%- if show_source and has_source and sourcename %}
      {% if show_copyright or theme_show_powered_by %}|{% endif %}
      <a href="{{ pathto('_sources/' + sourcename, true)|e }}"
          rel="nofollow">{{ _('Page source') }}</a>
      {%- endif %}
    </div>

    {% if theme_github_banner|lower != 'false' %}
    <a href="https://github.com/{{ theme_github_user }}/{{ theme_github_repo }}" class="github">
        <img style="position: absolute; top: 0; right: 0; border: 0;" src="{{ pathto('_static/' ~ theme_github_banner, 1) if theme_github_banner|lower != 'true' else 'https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png' }}" alt="Fork me on GitHub"  class="github"/>
    </a>
    {% endif %}

    {% if theme_analytics_id %}
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '{{ theme_analytics_id }}']);
      _gaq.push(['_setDomainName', 'none']);
      _gaq.push(['_setAllowLinker', true]);
      _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 %}
