First and Last Classes

This little chunk of code should be handy:
http://drupal.org/node/138656

This will allow me to add first and last classes to menu items that are in blocks - which if I get this project that I am thinking of (where the designer is super anal) I can utilize this code:

<?php
function phptemplate_menu_tree($pid 1) {
  if (
$tree phptemplate_menu_tree_improved($pid)) {
    return 
"\n<ul class=\"menu\">\n"$tree ."\n</ul>\n";
  }
}

function 
phptemplate_menu_tree_improved($pid 1) {
  
$menu menu_get_menu();
  
$output '';

  if (isset(
$menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
    
$num_children count($menu['visible'][$pid]['children']);
    for (
$i=0$i $num_children; ++$i) {
      
$mid $menu['visible'][$pid]['children'][$i];
      
$type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;
      
$children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
      
$extraclass $i == 'first' : ($i == $num_children-'last' '');
      
$output .= theme('menu_item'$midmenu_in_active_trail($mid) || ($type MENU_EXPANDED) ? theme('menu_tree'$mid) : ''count($children) == 0$extraclass);     
    }
  }

  return 
$output;
}

function 
phptemplate_menu_item($mid$children ''$leaf TRUE$extraclass '') {
  return 
'<li class="'. ($leaf 'leaf' : ($children 'expanded' 'collapsed')) . ($extraclass ' ' $extraclass '') . '">'menu_item_link($midTRUE$extraclass) . $children ."</li>\n";
}
?>