<?php
 
  //$megamenu = $helper->renderModule('pavmegamenu');
?>
     <!-- menu -->
          <div id="mainnav">    
  <div class="container">                     
    <div id="pav-mainnav">
      <div class="container-inner">
        <?php
        /**
         * Main Menu modules: as default if do not put megamenu, the theme will use categories menu for main menu
         */
        $modules = $helper->renderModule('pavmegamenu');

        if (count($modules) && !empty($modules)) { ?>                  
        <?php echo $modules; ?>
        <?php } elseif ($categories) { ?>
        <div class="navbar navbar-inverse"> 
              <nav id="mainmenutop" class="pav-megamenu" role="navigation"> 
                  <div class="navbar-header">
                      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                          <span class="sr-only">Toggle navigation</span>
                          <span class="fa fa-bars"></span>
                      </button>
                  </div>

                  <div class="collapse navbar-collapse navbar-ex1-collapse">
                      <ul class="nav navbar-nav">
                          
                          <?php foreach ($categories as $category) { ?>

                              <?php if ($category['children']) { ?>     
                                  <li class="parent dropdown deeper ">
                                      <a href="<?php echo $category['href']; ?>" class="dropdown-toggle" data-toggle="dropdown"><?php echo $category['name']; ?>
                                          <b class="fa fa-angle-down"></b>
                                          <span class="triangles"></span>
                                      </a>
                                  <?php } else { ?>
                                  <li>
                                      <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
                                  <?php } ?>
                                  <?php if ($category['children']) { ?>
                                      <ul class="dropdown-menu">
                                          <?php for ($i = 0; $i < count($category['children']);) { ?>
                                              <?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
                                              <?php for (; $i < $j; $i++) { ?>
                                                  <?php if (isset($category['children'][$i])) { ?>
                                                      <li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
                                                  <?php } ?>
                                              <?php } ?>
                                          <?php } ?>
                                      </ul>
                                  <?php } ?>
                              </li>
                          <?php } ?>
                      </ul>
                  </div>  
              </nav>
          </div>    
      <?php } ?>
      </div>    
    </div>
</div>
        <!-- menu -->  