/**
  * Render the menu items
  */
 protected function renderMenuRecursive($items, $sub = false)
 {
     $count = 0;
     $first = true;
     $n = count($items);
     foreach ($items as $item) {
         $count++;
         $options = isset($item['itemOptions']) ? $item['itemOptions'] : array();
         $class = array();
         if ($item['active'] && $this->activeCssClass != '') {
             $class[] = $this->activeCssClass;
         }
         if ($count === 1 && $this->firstItemCssClass !== null) {
             $class[] = $this->firstItemCssClass;
         }
         if ($count === $n && $this->lastItemCssClass !== null) {
             $class[] = $this->lastItemCssClass;
         }
         if ($this->itemCssClass !== null) {
             $class[] = $this->itemCssClass;
         }
         if ($class !== array()) {
             if (empty($options['class'])) {
                 $options['class'] = implode(' ', $class);
             } else {
                 $options['class'] .= ' ' . implode(' ', $class);
             }
         }
         if (isset($this->itemTemplate) || isset($item['template'])) {
             $template = isset($item['template']) ? $item['template'] : $this->itemTemplate;
         } else {
             $template = '';
         }
         switch ($template) {
             case '{brand}':
                 EBootstrap::mergeClass($options, array('brand'));
                 echo EBootstrap::link($item['label'], $item['url'], $options) . "\n";
                 break;
             case '{divider}':
                 echo EBootstrap::openTag('li', array('class' => 'divider-vertical'));
                 echo EBootstrap::closeTag('li') . "\n";
                 break;
             case '{search}':
                 //Input options
                 if (isset($options['input'])) {
                     $itemOptions = $options['input'];
                     unset($options['input']);
                 } else {
                     $itemOptions = array();
                 }
                 if (isset($itemOptions['name'])) {
                     $name = $itemOptions['name'];
                     unset($itemOptions['name']);
                 } else {
                     $name = 'search';
                 }
                 if (isset($itemOptions['value'])) {
                     $value = $itemOptions['value'];
                     unset($itemOptions['value']);
                 } else {
                     $value = '';
                 }
                 $itemHtmlOptions = isset($itemOptions['htmlOptions']) ? $itemOptions['htmlOptions'] : array();
                 EBootstrap::mergeClass($options, array('navbar-search'));
                 echo EBootstrap::openTag('form', $options) . "\n";
                 echo EBootstrap::searchField($name, $value, $itemHtmlOptions) . "\n";
                 echo EBootstrap::closeTag('form') . "\n";
                 break;
             default:
                 $listOptions = array('class' => 'nav navbar-nav');
                 if (isset($item['align']) and $item['align'] == 'right' and isset($item['items'])) {
                     //Allign navigation right
                     EBootstrap::mergeClass($listOptions, array('pull-right'));
                     if ($this->_ul > 0) {
                         $this->_ul--;
                         echo EBootstrap::closeTag('ul');
                     }
                     $this->_ul++;
                     echo EBootstrap::openTag('ul', $listOptions) . "\n";
                     $this->renderMenuRecursive($item['items'], true);
                     $this->_ul--;
                     echo EBootstrap::closeTag('ul');
                     continue;
                 } elseif ($first and !$sub) {
                     $this->_ul++;
                     echo EBootstrap::openTag('ul', $listOptions) . "\n";
                     $first = false;
                 }
                 //Create dropdown
                 if (isset($item['dropdown']) and $item['dropdown'] == true) {
                     if (isset($options['class'])) {
                         $options['class'] = implode(' ', explode(' ', $options['class'])) . ' dropdown';
                     } else {
                         $options['class'] = 'dropdown';
                     }
                     $item['linkOptions']['data-toggle'] = 'dropdown';
                     if (isset($item['linkOptions']['class'])) {
                         $item['linkOptions']['class'] = implode(' ', explode(' ', $item['linkOptions']['class']) + array('dropdown-toggle'));
                     } else {
                         $item['linkOptions']['class'] = 'dropdown-toggle';
                     }
                     $item['label'] .= '<b class="caret"></b>';
                 }
                 echo EBootstrap::openTag('li', $options);
                 if (isset($item['label'])) {
                     $menu = $this->renderMenuItem($item);
                     if (!empty($template)) {
                         echo strtr($template, array('{menu}' => $menu));
                     } else {
                         echo $menu;
                     }
                 }
                 if (isset($item['items']) && count($item['items'])) {
                     $options = isset($item['submenuOptions']) ? $item['submenuOptions'] : $this->submenuHtmlOptions;
                     if (isset($item['dropdown']) and $item['dropdown'] == true) {
                         EBootstrap::mergeClass($options, array('dropdown-menu'));
                     } else {
                         EBootstrap::mergeClass($options, array('nav'));
                     }
                     $this->_ul++;
                     echo "\n" . EBootstrap::openTag('ul', $options) . "\n";
                     $this->renderMenuRecursive($item['items'], true);
                     if (!isset($options['align'])) {
                         $this->_ul--;
                         echo EBootstrap::closeTag('ul') . "\n";
                     } elseif ($options['align'] == 'right') {
                         echo EBootstrap::closeTag('div') . "\n";
                     }
                 }
                 echo EBootstrap::closeTag('li') . "\n";
         }
     }
     if (!$sub and $this->_ul > 0) {
         $this->_ul--;
         echo EBootstrap::closeTag('ul') . "\n";
     }
 }