<div class="spirit-nav">
<!-- Next prev page -->
{{- $currentNode := . -}}

{{- template "menu-nextprev" dict "menu" .Site.Home "currentnode" $currentNode -}}

{{- define "menu-nextprev" -}}
    {{- $currentNode := .currentnode -}}
    {{- if ne .menu.Params.hidden true -}}
        {{- if hasPrefix $currentNode.URL .menu.URL -}}
            {{- $currentNode.Scratch.Set "NextPageOK" "OK" -}}
            {{- $currentNode.Scratch.Set "prevPage" ($currentNode.Scratch.Get "prevPageTmp") -}}
        {{- else -}}
            {{- if eq ($currentNode.Scratch.Get "NextPageOK") "OK" -}}
                {{- $currentNode.Scratch.Set "NextPageOK" nil -}}
                {{- $currentNode.Scratch.Set "nextPage" .menu -}}
            {{- end -}}
        {{- end -}}
        {{- $currentNode.Scratch.Set "prevPageTmp" .menu -}}

            {{- $currentNode.Scratch.Set "pages" .menu.Pages -}}
            {{- if .menu.IsHome -}}
                {{- $currentNode.Scratch.Set "pages" .menu.Sections -}}
            {{- else if .menu.Sections -}}
                {{- $currentNode.Scratch.Set "pages" (.menu.Pages | union .menu.Sections) -}}
            {{- end -}}
            {{- $pages := ($currentNode.Scratch.Get "pages") -}}

            {{- range $pages.ByWeight -}}
                {{- template "menu-nextprev" dict "menu" . "currentnode" $currentNode -}}
            {{- end -}}
    {{- end -}}
{{- end -}}

{{- if not $.Site.Params.disableNavChevron -}}
    {{- with ($.Scratch.Get "prevPage") -}}
    <a accesskey="p" href="{{cond (in .URL ".html") .URL (printf "%sindex.html" .URL)}}"><img src="{{"images/prev.png" | relURL}}" alt="Prev"></a>
    {{ end -}}
{{- end -}}
    {{with .Parent}}<a accesskey="u" href="{{cond (in .URL ".html") .URL (printf "%sindex.html" .URL)}}"><img src="{{"images/up.png" | relURL}}" alt="Up"></a>{{end}}
    <a accesskey="h" href="{{"/index.html" | relURL}}"><img src="{{"images/home.png" | relURL}}" alt="Home"></a>
{{- if not $.Site.Params.disableNavChevron -}}
    {{- with ($.Scratch.Get "nextPage") -}}
    <a accesskey="n" href="{{cond (in .URL ".html") .URL (printf "%sindex.html" .URL)}}"><img src="{{"images/next.png" | relURL}}" alt="Next"></a>
    {{- end }}
{{- end -}}
</div>