/**
  * Renders menu tree. Internal method.
  *
  * @param ioMenuItem  $item      Menu item
  * @param integer $depth         The depth of children to render
  * @param boolean $renderAsChild Render with attributes on the li (true) or the ul around the children (false)
  *
  * @return string
  */
 protected function _render(ioMenuItem $item, $depth = null, $renderAsChild = false)
 {
     /**
      * Return an empty string if any of the following are true:
      *   a) The menu has no children eligible to be displayed
      *   b) The depth is 0
      *   c) This menu item has been explicitly set to hide its children
      */
     if (!$item->hasChildren() || $depth === 0 || !$item->showChildren()) {
         return;
     }
     if ($renderAsChild) {
         $attributes = array('class' => 'menu_level_' . $item->getLevel());
     } else {
         $attributes = $item->getAttributes();
         // give the top ul a class of "menu" of none specified
         if (!isset($attributes['class'])) {
             $attributes['class'] = 'menu';
         }
     }
     // render children with a depth - 1
     $childDepth = $depth === null ? null : $depth - 1;
     $html = $this->_format($item->getLevel(), '<ul' . _tag_options($attributes) . '>', 'ul');
     $html .= $this->_renderChildren($item, $childDepth);
     $html .= $this->_format($item->getLevel(), '</ul>', 'ul');
     return $html;
 }