<!– include menubar.html –> <nav class=“menubar”>

    {%- comment -%}<!-- include the menu icon -->{%- endcomment -%}

    {%- include menubar-icon.html -%}

    {%- comment -%}<!-- Create a list of top menu item titles -->{%- endcomment -%}

    {%- assign buildTimeInSecondsSinceEpoch = site.time | date: "%s" | plus: 0 -%}

{%- assign pagesForPublishing = "" | split: "" -%}

    {%- if site.data.setup.exclude-pages-from-menus -%}{%- else -%}
        {%- for ape in site.pages -%}
                {%- assign pageInSecondsSindsEpoch = ape.date | date:"%s" | plus: 0 -%}
                {%- if pageInSecondsSindsEpoch < buildTimeInSecondsSinceEpoch -%}
                    {%- assign pagesForPublishing = pagesForPublishing | push: ape -%}
                {%- endif -%}
    {%- endfor -%}
{%- endif -%}

    {%- if site.data.setup.include-posts-in-menus -%}
            {%- assign pagesForPublishing = pagesForPublishing | concat: site.posts -%}
    {%- endif -%}

    {%- assign topTitles = "" | split: "" -%}
    {%- assign sortedPages = pagesForPublishing | where:'menuInclude', true | where_exp:'item', 'item.menuTopTitle != nil' | sort: 'menuTopIndex', 'last' -%}
    {%- for ape in sortedPages -%}{%- assign topTitles = topTitles | push: ape.menuTopTitle -%}{%- endfor -%}       
    {%- assign topTitles = topTitles | uniq -%}

    {%- comment -%}<!-- Home page -->{%- endcomment -%}
    {%- assign home = 'Home' -%}
    {%- if site.data.text-for.tHome -%}{%- assign home = site.data.text-for.tHome -%}{%- endif -%}
    {%- if page.url == '/' %}
    <div class="item isActiveSelection">
    {%- else %}
    <div class="item">
    {%- endif %}
            <div class="title">
                    <label class="symbol"><p></p></label>
                    <div class="text"><a href="{{ site.url }}{{ site.baseurl }}/index.html"><p>{{ home }}</p></a></div>
            </div>
    </div>

    {%- comment -%}<!-- Page menus -->{%- endcomment -%}
    {%- for topTitle in topTitles -%}

            {%- if jekyll.environment != 'production' and site.data.setup.fast-content-build -%}{%- else -%}

                    {%- comment -%}<!-- note: the html comment tags are for editor coloring support

                    Due to the poor support for variables in Liquid we have to resort to some fairly laborious code.

                    First determine all pages that contain sub menu information for the running top menu item. These are collected in "titlePages"

                    Then create four lists containing the sub menu title, index, url and link respectively. These lists are all in the same sequence such that entry [n] is applicable to the same sub menu in all lists. (I.e. they are synchronous)

                    Then sort the lists into four new lists. Again these lists must be kept synchronous.

                    Lastly, step through the lists to create the actual sub menu's

                    -->{%- endcomment -%}

                    {%- assign titlePages = sortedPages | where:'menuTopTitle', topTitle -%}

                    {%- assign subMenuTitles = "" | split: "" -%}
                    {%- assign subMenuIndexes = "" | split: "" -%}
                    {%- assign subMenuUrls = "" | split: "" -%}
                    {%- assign subMenuLinks = "" | split: "" -%}

                    {%- for ape in titlePages -%}
                            {%- if ape.menuSubTitle != nil -%}
                                    {%- assign subMenuTitles = subMenuTitles | push: ape.menuSubTitle -%}
                                    {%- if ape.menuSubIndex != nil -%}
                                            {%- assign subMenuIndexes = subMenuIndexes | push: ape.menuSubIndex -%}
                                    {%- else -%}
                                            {%- assign subMenuIndexes = subMenuIndexes | push: -1 -%}
                                    {%- endif -%}
                                    {%- assign subMenuUrls = subMenuUrls | push: ape.url -%}
                                    {%- if ape.menuLink != nil -%}
                                            {%- assign subMenuLinks = subMenuLinks | push: ape.menuLink -%}
                                    {%- else -%}
                                            {%- assign subMenuLinks = subMenuLinks | push: true -%}
                                    {%- endif -%}
                            {%- endif -%}
                            {%- if ape.menuSubs != nil -%}
                                    {%- for sub in ape.menuSubs -%}
                                            {%- assign subMenuTitles = subMenuTitles | push: sub.title -%}
                                            {%- if sub.index != nil -%}
                                                    {%- assign subMenuIndexes = subMenuIndexes | push: sub.index -%}
                                            {%- else -%}
                                                    {%- assign subMenuIndexes = subMenuIndexes | push: -1 -%}
                                            {%- endif -%}
                                            {%- if sub.url != nil -%}
                                                    {%- if sub.anchorId != nil -%}
                                                            {%- assign urlWithAnchorId = sub.url | append: '#' | append: sub.anchorId -%}
                                                    {%- else -%}
                                                            {%- assign urlWithAnchorId = sub.url -%}
                                                    {%- endif -%}
                                            {%- else -%}
                                                    {%- if sub.anchorId != nil -%}
                                                            {%- assign urlWithAnchorId = ape.url | append: '#' | append: sub.anchorId -%}
                                                    {%- else -%}
                                                            {%- assign urlWithAnchorId = ape.url -%}
                                                    {%- endif -%}
                                            {%- endif -%}
                                            {%- assign subMenuUrls = subMenuUrls | push: urlWithAnchorId -%}
                                            {%- if sub.link != nil -%}
                                                    {%- assign subMenuLinks = subMenuLinks | push: sub.link -%}
                                            {%- else -%}
                                                    {%- assign subMenuLinks = subMenuLinks | push: true -%}
                                            {%- endif -%}
                                    {%- endfor -%}
                            {%- endif -%}
                    {%- endfor -%}

                    {%- assign sortedSubMenuTitles = "" | split: "" -%}
                    {%- assign sortedSubMenuIndexes = subMenuIndexes | sort -%}
                    {%- assign sortedSubMenuUrls = "" | split: "" -%}
                    {%- assign sortedSubMenuLinks = "" | split: "" -%}

                    {%- for menuIndex in sortedSubMenuIndexes -%}
                            {%- if menuIndex != -1 -%}
                                    {%- for aMenuIndex in subMenuIndexes -%}
                                            {%- if aMenuIndex == menuIndex -%}
                                                    {%- assign sortedSubMenuTitles = sortedSubMenuTitles | push: subMenuTitles[forloop.index0] -%}
                                                    {%- assign sortedSubMenuUrls = sortedSubMenuUrls | push: subMenuUrls[forloop.index0] -%}
                                                    {%- assign sortedSubMenuLinks = sortedSubMenuLinks | push: subMenuLinks[forloop.index0] -%}
                                                    {%- continue -%}
                                            {%- endif -%}
                                    {%- endfor -%}
                            {%- endif -%}
                    {%- endfor -%}
                    {%- for aMenuIndex in subMenuIndexes -%}
                            {%- if aMenuIndex == -1 -%}
                                    {%- assign sortedSubMenuTitles = sortedSubMenuTitles | push: subMenuTitles[forloop.index0] -%}
                                    {%- assign sortedSubMenuUrls = sortedSubMenuUrls | push: subMenuUrls[forloop.index0] -%}
                                    {%- assign sortedSubMenuLinks = sortedSubMenuLinks | push: subMenuLinks[forloop.index0] -%}
                                    {%- continue -%}
                            {%- endif -%}
                    {%- endfor -%}

            {%- endif %}
    <div class="item-separator"><p><!-- empty but necessary --></p></div>

            {%- comment -%}<!-- If the menu selection and active page are the same, show it -->{%- endcomment -%}

            {%- if page.menuTopTitle == topTitle  -%}
                    {%- if page.menuLink == false %}
    <div class="item">
                    {%- else %}
    <div class="item isActiveSelection">
                    {%- endif -%}
            {%- else %}
    <div class="item">
            {%- endif -%}

            {%- comment -%}<!-- Create top menu item -->{%- endcomment %}
            <input type="checkbox" id="{{ topTitle | replace:' ','-' | append:'-checkbox'}}">
            <div class="title">
                    <label class="symbol" for="{{ topTitle | replace:' ','-' | append:'-checkbox'}}">
            {%- if sortedSubMenuTitles.size > 0 %}
                            <p class="code"><!-- will be filled by disclosure indicator --></p>
            {%- else %}
                            <p></p>
            {%- endif %}
                    </label>
                    <div class="text">

            {%- comment -%}<!-- Find page to link to -->{%- endcomment -%}

            {%- assign pageFound = false -%}
            {%- for ape in sortedPages -%}
                    {%- if ape.menuTopTitle == topTitle and ape.menuSubTitle == nil and ape.menuSubs == nil -%}
                            {%- if ape.menuLink == false %}
                            <p class="paddingAsLink">{{ topTitle }}</p>
                            {%- else %}
                                {%- if ape.url contains "http" -%}
                            <a href="{{ ape.url }}"><p>{{ topTitle }}</p></a>
                                    {%- else -%}
                            <a href="{{ ape.url | relative_url }}"><p>{{ topTitle }}</p></a>
                                {%- endif -%}
                            {%- endif -%}
                            {%- assign pageFound = true -%}
                            {%- break -%}
                    {%- endif -%}
            {%- endfor -%}
            {%- if pageFound == false -%}
                    {%- for ape in sortedPages -%}
                            {%- if ape.menuTopTitle == topTitle and ape.menuTopIndex -%}
                                    {%- if ape.menuLink == false %}
                            <p class="paddingAsLink">{{ topTitle }}</p>
                                    {%- else %}
                                        {%- if ape.url contains "http" -%}
                            <a href="{{ ape.url }}"><p>{{ topTitle }}</p></a>
                                    {%- else -%}
                            <a href="{{ ape.url | relative_url }}"><p>{{ topTitle }}</p></a>
                                    {%- endif -%}
                                    {%- endif -%}
                                    {%- assign pageFound = true -%}
                                    {%- break -%}
                            {%- endif -%}
                    {%- endfor -%}
                    {%- if pageFound == false %}
                            <p class="paddingAsLink">{{ topTitle }}</p>
                    {%- endif -%}
            {%- endif %}
                    </div>
            </div>

            {%- if jekyll.environment != 'production' and site.data.setup.fast-content-build -%}{%- else %}

                    {%- comment -%}<!-- Create sub menu items -->{%- endcomment -%}

                    {% if sortedSubMenuTitles.size > 0 -%}
                            {%- if site.data.setup.drop-down-menu %}
            <div class="dropdown">
                            {%- else %}
            <div class="dropdown-narrow">
                            {%- endif -%}

                            {%- assign processedSubMenuTitles = "" | split: "" -%}

                            {%- for subMenuTitle in sortedSubMenuTitles %}

                                    {%- comment -%}<!-- Do not build the same sub menu item twice -->{%- endcomment -%}

                                    {%- assign subMenuTitleProcessed = false -%}
                                    {%- for smt in processedSubMenuTitles -%}
                                            {%- if smt == subMenuTitle -%}{% assign subMenuTitleProcessed = true -%}{%- endif -%}
                                    {%- endfor -%}
                                    {%- if subMenuTitleProcessed -%}
                                            {%- continue -%}
                                    {%- else -%}
                                            {%- assign processedSubMenuTitles = processedSubMenuTitles | push: subMenuTitle -%}
                                    {%- endif -%}

                                    {%- comment -%}<!-- Build the sub-sub tables for {{ subMenuTitle }} -->{%- endcomment -%}

                                    {% assign subsubMenuTitles = "" | split: "" -%}
                                    {%- assign subsubMenuIndexes = "" | split: "" -%}
                                    {%- assign subsubMenuUrls = "" | split: "" -%}
                                    {%- assign subsubMenuLinks = "" | split: "" -%}

                                    {%- for ape in titlePages %}
                                            {%- if ape.menuSubs != nil %}
                                                    {%- for sub in ape.menuSubs -%}
                                                            {%- if sub.title == subMenuTitle %}
                                                                    {%- if sub.sub != nil %}
                                                                            {%- for subsub in sub.sub %}
                                                                                    {%- assign subsubMenuTitles = subsubMenuTitles | push: subsub.title -%}
                                                                                    {%- if subsub.index != nil -%}
                                                                                            {%- assign subsubMenuIndexes = subsubMenuIndexes | push: subsub.index -%}
                                                                                    {%- else -%}
                                                                                            {%- assign subsubMenuIndexes = subsubMenuIndexes | push: -1 -%}
                                                                                    {%- endif -%}
                                                                                    {%- if subsub.url != nil -%}
                                                                                            {%- if subsub.anchorId != nil -%}
                                                                                                    {%- assign urlWithAnchorId = subsub.url | append: '#' | append: subsub.anchorId -%}
                                                                                            {%- else -%}
                                                                                                    {%- assign urlWithAnchorId = subsub.url -%}
                                                                                            {%- endif -%}
                                                                                    {%- else -%}
                                                                                            {%- if subsub.anchorId != nil -%}
                                                                                                    {%- assign urlWithAnchorId = ape.url | append: '#' | append: subsub.anchorId -%}
                                                                                            {%- else -%}
                                                                                                    {%- assign urlWithAnchorId = ape.url -%}
                                                                                            {%- endif -%}
                                                                                    {%- endif -%}
                                                                                    {%- assign subsubMenuUrls = subsubMenuUrls | push: urlWithAnchorId -%}
                                                                                    {%- if subsub.link != nil -%}
                                                                                            {%- assign subsubMenuLinks = subsubMenuLinks | push: subsub.link -%}
                                                                                    {%- else -%}
                                                                                            {%- assign subsubMenuLinks = subsubMenuLinks | push: true -%}
                                                                                    {%- endif -%}
                                                                            {%- endfor -%}
                                                                    {%- endif -%}
                                                            {%- endif -%}
                                                    {%- endfor -%}
                                            {%- endif -%}
                                    {%- endfor %}

                                    {%- comment -%}<!-- Sort all 4 the lists based on the index of the subMenu that was read -->{%- endcomment -%}

                                    {% assign sortedSubsubMenuTitles = "" | split: "" -%}
                                    {%- assign sortedSubsubMenuIndexes = subsubMenuIndexes | sort -%}
                                    {%- assign sortedSubsubMenuUrls = "" | split: "" -%}
                                    {%- assign sortedSubsubMenuLinks = "" | split: "" -%}

                                    {%- for menuIndex in sortedSubsubMenuIndexes -%}
                                            {%- if menuIndex != -1 -%}
                                                    {%- for aMenuIndex in subsubMenuIndexes -%}
                                                            {%- if aMenuIndex == menuIndex -%}
                                                                    {%- assign sortedSubsubMenuTitles = sortedSubsubMenuTitles | push: subsubMenuTitles[forloop.index0] -%}
                                                                    {%- assign sortedSubsubMenuUrls = sortedSubsubMenuUrls | push: subsubMenuUrls[forloop.index0] -%}
                                                                    {%- assign sortedSubsubMenuLinks = sortedSubsubMenuLinks | push: subsubMenuLinks[forloop.index0] -%}
                                                                    {%- continue -%}
                                                            {%- endif -%}
                                                    {%- endfor -%}
                                            {%- endif -%}
                                    {%- endfor -%}
                                    {%- for aMenuIndex in subsubMenuIndexes -%}
                                            {%- if aMenuIndex == -1 -%}
                                                    {%- assign sortedSubsubMenuTitles = sortedSubsubMenuTitles | push: subsubMenuTitles[forloop.index0] -%}
                                                    {%- assign sortedSubsubMenuUrls = sortedSubsubMenuUrls | push: subsubMenuUrls[forloop.index0] -%}
                                                    {%- assign sortedSubsubMenuLinks = sortedSubsubMenuLinks | push: subsubMenuLinks[forloop.index0] -%}
                                                    {%- continue -%}
                                            {%- endif -%}
                                    {%- endfor %}

                                    {%- comment -%}<!-- Create the sub menu -->{%- endcomment %}
                    <div class="subitem-separator"><p></p></div>
                                    {%- if sortedSubMenuLinks[forloop.index0] != false -%}
                                            {%- if sortedSubMenuUrls[forloop.index0] == page.url %}
                    <div class="subitem isActiveSelection">
                                            {%- else -%}
                                                    {%- assign urlFound = false -%}
                                                    {%- for url in sortedSubsubMenuUrls -%}
                                                            {%- if url == page.url -%}{%- assign urlFound = true -%}{%- endif -%}
                                                    {%- endfor -%}
                                                    {%- if urlFound %}
                    <div class="subitem isActiveSelection">
                                                    {%- else %}
                    <div class="subitem">
                                                    {%- endif -%}
                                            {%- endif %}
                            <input type="checkbox" id="{{ subMenuTitle | replace:' ','-' | append:'-checkbox'}}">
                            <div class="title">
                                    <label class="symbol" for="{{ subMenuTitle | replace:' ','-' | append:'-checkbox'}}">
                                            {%- if sortedSubsubMenuTitles.size > 0 %}
                                            <p class="code"><!-- will be filled by disclosure indicator --></p>
                                            {%- else %}
                                            <p></p>
                                            {%- endif %}
                                    </label>
                                    <div class="text">
                                            {%- if sortedSubMenuUrls[forloop.index0] contains "http" -%}
                                            <a href="{{ sortedSubMenuUrls[forloop.index0] }}"><p>{{ subMenuTitle }}</p></a>
                                            {%- else -%}
                                            <a href="{{ sortedSubMenuUrls[forloop.index0] | relative_url }}"><p>{{ subMenuTitle }}</p></a>
                                            {%- endif -%}
                                    </div>
                            </div>
                                    {%- else -%}
                                            {%- assign urlFound = false -%}
                                            {%- for url in sortedSubsubMenuUrls -%}
                                                    {%- if url == page.url -%}{%- assign urlFound = true -%}{%- endif -%}
                                            {%- endfor -%}
                                            {%- if urlFound %}
                    <div class="subitem isActiveSelection">
                                            {%- else %}
                    <div class="subitem">
                                            {%- endif %}
                            <input type="checkbox" id="{{ subMenuTitle | replace:' ','-' | append:'-checkbox'}}">
                            <div class="title">
                                    <label class="symbol" for="{{ subMenuTitle | replace:' ','-' | append:'-checkbox'}}">
                                            {%- if sortedSubsubMenuTitles.size > 0 %}
                                            <p class="code"><!-- will be filled by disclosure indicator --></p>
                                            {%- else %}
                                            <p></p>
                                            {%- endif %}
                                    </label>
                                    <div class="text"><p class="paddingAsLink">{{ subMenuTitle }}</p></div>
                            </div>
                                    {%- endif -%}

                                    {%- comment -%}<!-- sub sub menu item build -->{%- endcomment -%}

                                    {% if sortedSubsubMenuTitles.size > 0 -%}
                                            {%- if site.data.setup.drop-down-menu %}
                            <div class="sub-dropdown">
                                            {%- else %}
                            <div class="sub-dropdown-narrow">
                                            {%- endif -%}
                                            {%- for subsubMenuTitle in sortedSubsubMenuTitles %}
                                    <div class="subsubitem-separator"><p></p></div>
                                                    {%- if sortedSubsubMenuLinks[forloop.index0] != false -%}
                                                            {%- if sortedSubsubMenuUrls[forloop.index0] == page.url %}
                                    <div class="subsubitem isActiveSelection">
                                                            {%- else %}
                                    <div class="subsubitem">
                                                            {%- endif %}
                                            <div class="title">
                                                    <div class="symbol"><p></p></div>
                                                    <div class="text">
                                                        {%- if sortedSubsubMenuUrls[forloop.index0] contains "http" -%}
                                                            <a href="{{ sortedSubsubMenuUrls[forloop.index0] }}"><p>{{ subsubMenuTitle }}</p></a>
                                                            {%- else -%}
                                                            <a href="{{ sortedSubsubMenuUrls[forloop.index0] | relative_url }}"><p>{{ subsubMenuTitle }}</p></a>
                                                            {%- endif -%}
                                                    </div>
                                            </div>
                                                    {%- else %}
                                    <div class="subsubitem">
                                            <div class="title">
                                                    <div class="symbol"><p></p></div>
                                                    <div class="text"><p class="paddingAsLink">{{ subsubMenuTitle }}</p></div>
                                            </div>
                                                    {%- endif %}
                                    </div>
                                            {%- endfor %}
                            </div>
                                    {%- endif %}
                    </div>
                            {%- endfor %}
            </div>                  
                    {%- endif -%}
            {%- endif %}
    </div>
    {%- endfor -%}

    {%- comment -%}<!-- Categories menu -->{%- endcomment -%}

    {%- if jekyll.environment != 'production' and site.data.setup.fast-content-build -%}{%- else -%}
            {%- if site.data.setup.generate-categories-menu -%}
                    {%- assign cats = pagesForPublishing | where:'layout', 'category-page' | sort:'title' -%}
                    {%- if cats.size > 0 -%}
                            {%- assign categories = 'Categories' -%}
                            {%- if site.data.text-for.tCategories -%}{%- assign categories = site.data.text-for.tCategories -%}{%- endif %}
    <div class="item-separator"><p><!-- empty but necessary --></p></div>

                            {%- comment -%}<!-- Check if a category page is selected -->{%- endcomment -%}

                            {%- assign selected = false -%}
                            {%- for cat in cats -%}{%- if cat.url == page.url -%}{%- assign selected = true -%}{%- endif -%}{%- endfor -%}
                            {%- if selected -%}
                                    {%- if site.data.setup.drop-down-menu %}
    <div class="item isActiveSelection">
                                    {%- else %}
    <div class="item-narrow-only isActiveSelection">
                                    {%- endif -%}
                            {%- else -%}
                                    {%- if site.data.setup.drop-down-menu %}
    <div class="item">
                                    {%- else %}
    <div class="item-narrow-only">
                                    {%- endif -%}
                            {%- endif %}
            <input type="checkbox" id="category-checkbox">
            <div class="title">
                    <label class="symbol" for="category-checkbox">
                            {%- if cats.size > 0 %}
                            <p class="code"><!-- will be filled by disclosure indicator --></p>
                            {%- else -%}
                            <p></p>
                            {%- endif -%}
                    </label>
                    <div class="text"><p class="paddingAsLink">{{ categories }}</p></div>
            </div>
            <div class="dropdown">
                            {%- for cat in cats %}
                    <div class="subitem-separator"><p></p></div>
                                    {%- if cat.url == page.url %}
                    <div class="subitem isActiveSelection">
                                    {%- else %}
                    <div class="subitem">
                                    {%- endif %}
                            <div class="title">
                                    <div class="symbol"></div>
                                    <div class="text">
                                    {%- if cat.url contains "http" -%}
                                            <a href="{{ cat.url }}"><p>{{ cat.title | capitalize }}</p></a>
                                    {%- else -%}
                                            <a href="{{ cat.url | relative_url }}"><p>{{ cat.title | capitalize }}</p></a>
                                    {%- endif -%}
                                    </div>
                            </div>
                    </div>
                            {%- endfor %}
            </div>
    </div>
                    {%- endif -%}
            {%- endif -%}
    {%- endif %}

    {%- comment -%}<!-- Account menus -->{%- endcomment -%}

    {%- if jekyll.environment != 'production' and site.data.setup.fast-content-build -%}{%- else -%}
            {%- include account-menus.html -%}
    {%- endif %}

</nav> <!– end of include menubar.html –>