{function menuBox}
   <ul class="nav nav-pills nav-stacked">
      {foreach $sectionList as $item}
         <li class="section_{$item.id}">
            {strip}
               <a href="{url s=category IDcat=$item.id}">
                  <span class="fc fc-angle-right"></span>

                  {$item.title}
               </a>
            {/strip}
         </li>
      {/foreach}
   </ul>
{/function}

{function sectionsTree}
   <ul class="nav nav-pills nav-stacked">
      {foreach $sectionList as $item}
         <li class="section_{$item.id} nav-item">
            {if $item.submenu}
               <i class="fc fc-plus opener"></i>
            {/if}

            {strip}
               <a href="{url s=category IDcat=$item.id}" class="nav-link">
                  {$item.title}
               </a>
            {/strip}

            {if $item.submenu && $item.level < $level_max}
               {sectionsTree sectionList=$item.submenu}

               {if $item.level == 0}
                  <div class="menu-box {if $item.submenu|count < 7}menu-box-small{/if}">
                     {menuBox sectionList=$item.submenu }
                  </div>
               {/if}
            {/if}
         </li>
      {/foreach}
   </ul>
{/function}

{if not $fromCache}
   {$firstCategory = $categories|next}
   <div class="side-sections">
      {*<h3>{$firstCategory.parent.title}</h3>*}
      {sectionsTree sectionList=$categories}
   </div>

   <script>
      wpj.onReady.push(function(){
         $(".side-sections").on("click", ".opener", function(e){
            $(this).closest("li").toggleClass("opened");
         });
      });
   </script>

{else}
   {if $selection}
      <script>
         wpj.onReady.push(function(){
            {foreach $selection as $item}
            $(".section_{$item}").addClass("opened"){if $item@last}.addClass("active"){/if};
            {/foreach}
         });
      </script>
   {/if}
{/if}
