<?php if(is_array($this->items)): ?>
    <?php foreach ($this->items as $item): ?>
        <li<?php if ($item['class']) echo ' class="' . $item['class'] . '"'; ?>>
            <a href="<?= $item['href'] ?: './' ?>"
               title="<?= $item['pageTitle'] ?: $item['title'] ?>"
                <?php if ($item['class']) echo ' class="' . $item['class'] . '"'; ?>
                <?php if ($item['accesskey']) echo ' accesskey="' . $item['accesskey'] . '"'; ?>
                <?php if ($item['tabindex']) echo ' tabindex="' . $item['tabindex'] . '"'; ?>
                <?php if ($item['nofollow']) echo ' rel="nofollow"'; ?><?= $item['target'] ?>
                <?php if (!empty($item['subitems'])) echo ' aria-haspopup="true"'; ?>>
                <?= $item['link'] ?>

            </a>
            <?php if(!empty($item['subitems'])): ?>
                <i class="material-icons right" style="z-index: 999;position: relative;right: 5px;top: -55px;">arrow_drop_down</i>
            <?php endif; ?>
        </li>
        <?php if (!empty($item['subitems'])): ?>
            <li class="subitems" style="display:none;background:rgba(0, 0, 0, .05);">
                <ul>
                    <?php foreach ($item['subitems'] as $sItem): ?>
                        <li>
                            <a href="<?= $sItem['href'] ?: './' ?>" class="<?php if($sItem['isActive']): ?> active<?php endif; ?>"
                               title="<?= $sItem['pageTitle'] ?: $sItem['title'] ?>">
                                <?= $sItem['link'] ?>
                            </a>
                            <?php if(!empty($sItem['subitems'])): ?>
                                <i id="toggleMenu" class="material-icons right" style="z-index: 999;position: relative;right: 5px;top: -55px;">arrow_drop_down</i>
                            <?php endif; ?>
                        </li>

                        <?php if (!empty($sItem['subitems'])): ?>
                            <li style="display:none;background:rgba(0, 0, 0, .05);">
                                <ul>
                                    <?php foreach ($sItem['subitems'] as $itemLvl3): ?>
                                        <li>
                                            <a href="<?= $itemLvl3['href'] ?: './' ?>" class="<?php if($itemLvl3['isActive']): ?> active<?php endif; ?>"
                                               title="<?= $itemLvl3['pageTitle'] ?: $itemLvl3['title'] ?>">
                                                <?= $itemLvl3['link'] ?>
                                            </a>
                                            <?php if(!empty($itemLvl3['subitems'])): ?>
                                                <i id="toggleMenu" class="material-icons right" style="z-index: 999;position: relative;right: 5px;top: -55px;">arrow_drop_down</i>
                                            <?php endif; ?>
                                        </li>
                                        <?php if (!empty($itemLvl3['subitems'])): ?>
                                            <li style="display:none;background:rgba(0, 0, 0, .05);">
                                                <ul>
                                                    <li>
                                                        <?php foreach ($itemLvl3['subitems'] as $itemLvl4): ?>
                                                            <a href="<?= $itemLvl4['href'] ?: './' ?>" class="<?php if($itemLvl4['isActive']): ?> active<?php endif; ?>"
                                                               title="<?= $itemLvl4['pageTitle'] ?: $itemLvl4['title'] ?>">
                                                                <?= $itemLvl4['link'] ?>
                                                            </a>
                                                        <?php endforeach; ?>
                                                    </li>
                                                </ul>
                                            </li>
                                        <?php endif; ?>
                                    <?php endforeach; ?>
                                </ul>
                            </li>
                        <?php endif; ?>

                    <?php endforeach; ?>
                </ul>
            </li>
        <?php endif; ?>

    <?php endforeach; ?>
<?php endif; ?>

<?php $GLOBALS['TL_BODY'][] = '<script>
jQuery(document).ready( function($) {
    jQuery(".mobile-menu i").bind("touchstart click", function() {
      $(this).html() == "arrow_drop_down" ? $(this).html("arrow_drop_up") : $(this).html("arrow_drop_down");
    });
    jQuery(".mobile-menu i").bind("touchstart click", function() {
      $(this).parent("li").next().toggle();return false;
    });
});
</script>'; ?>