<%
  css = if ((defined?(apply_css) && apply_css) || !defined?(apply_css)) and
           (classes = css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count||=nil)).any?
    " class='#{classes.join(' ')}'"
  end
  dom_id = (" id='item_#{menu_branch_counter}'" if menu_branch.parent_id.nil? and menu_branch.title.present?)
  @menu_pages.reject! { |branch| branch == menu_branch } # Remove page from the array, so that future searching will be faster.
  children = @menu_pages.select { |p| p.parent_id == menu_branch.id && p.in_menu? }
-%>
<li<%= css -%><%= dom_id -%>>
  <%= link_to menu_branch.title, menu_branch.url %>

  <% unless hide_children or children.empty? %>
    <ul class='clearfix'>
      <%=
        render :partial => "/shared/menu_branch",
               :collection => children,
               :locals => {
                 :hide_children => false, # hide children can't be true or we wouldn't get here.
                 :sibling_count => children.size - 1
               } -%>
    </ul>
  <% end %>
</li>

<%
  css = if ((defined?(apply_css) && apply_css) || !defined?(apply_css)) and
           (classes = css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count||=nil)).any?
    "class='#{classes.join(' ')}'"
  end
  dom_id = ("id='item_#{menu_branch_counter}'" if menu_branch.parent_id.nil? and menu_branch.title.present?)
  
  hide_children = (defined?(hide_children) && hide_children)
  children = hide_children ? [] : @menu_pages.select { |p| p.parent_id == menu_branch.id && p.in_menu? }
-%>
<li<%= ['', css, dom_id].join(' ').gsub(/\ *$/, '') %>>
  <%= link_to menu_branch.title, menu_branch.url %>

  <% if children.present? %>
    <ul class='clearfix'>
      <%=
        render :partial => "/shared/menu_branch",
               :collection => children,
               :locals => {
                 :hide_children => hide_children,
                 :sibling_count => children.size - 1
               } -%>
    </ul>
  <% end %>
</li>

Tidy up how children are generated and how the css & dom_id are combined. Stopped removing pages from the collection as it is too likely to come back to bite us later.
Tidy up how children are generated and how the css & dom_id are combined. Stopped removing pages from the collection as it is too likely to come back to bite us later.
