{% macro loop_over(navigation,chapnum) %}

    {% import _self as macros %}

    {% for element in navigation %}

		{% set depth = element.keyPathArray|length %}

        {% if element.activeParent %}
			<li class="bt bb margin-bottom-1 {{ element.elementType }} level-{{ depth }} activeParent">
		{% elseif element.active %}
			<li class="bt bb margin-bottom-1 {{ element.elementType }} level-{{ depth }} active">
		{% else %}
			<li class="bt bb margin-bottom-1 {{ element.elementType }} level-{{ depth }}">
		{% endif %}
        
        {% if (element.elementType == 'folder') %}
				<a class="link dib w-100 relative fw7 pv2 pr2 indent-l-{{depth}} margin-bottom-1 arrow-after" href="{{ element.urlAbs }}">{% if chapnum %}{{ element.chapter }}. {% endif %}{{ element.name }}</a>
		{% if (element.folderContent|length > 0) and (element.contains == 'pages') %}	
                <ul class="list pa0">
                    {{ macros.loop_over(element.folderContent, chapnum) }}
                </ul>
		{% endif %}
            {% else %}
				<a class="link dib w-100 relative fw3 pv2 pr2 indent-l-{{depth}} margin-bottom-1 arrow-after" href="{{ element.urlAbs }}">{% if chapnum %}{{ element.chapter }} {% endif %}{{ element.name }}</a>
            {% endif %}
        </li>
    {% endfor %}
{% endmacro %}

{% import _self as macros %}

{% if settings.themes.cyanine.collapseNav %}
    <button id="expander" data-expandlabel="{{ settings.themes.cyanine.expand|default('expand navigation') }}" data-collapselabel="{{ settings.themes.cyanine.collapse|default('collapse navigation') }}" class="expander dim dn db-l link pointer w-100 ba pa2 mb3 f6">{{ settings.themes.cyanine.expand|default('expand navigation') }}</button>
{% endif %}

<ul class="cy-nav mainnavigation list pa0 menu f5">
    {{ macros.loop_over(navigation, settings.themes.cyanine.chapnum ) }}
</ul>