Index: dhtml_menu.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dhtml_menu/dhtml_menu.module,v
retrieving revision 1.39
diff -u -p -r1.39 dhtml_menu.module
--- dhtml_menu.module	20 Nov 2008 19:12:51 -0000	1.39
+++ dhtml_menu.module	20 Nov 2008 19:26:04 -0000
@@ -43,27 +43,29 @@ function dhtml_menu_init() {
  * follow the recursion of menu_tree_output().
  */
 function dhtml_menu_theme_menu_item_link($link) {
-  static $disabled;
+  static $disabled, $theme;
   if (!isset($disabled)) {
     $disabled = variable_get('dhtml_menu_disabled', array());
+    $theme = variable_get('dhtml_menu_theme_menu_item_link', 'theme_menu_item_link');
   }
 
-  // TODO: Find out why options sometimes are serialized. Fix this workaround before D7 release!
-  if (!isset($link['localized_options']) || !is_array($link['localized_options'])) {
-    $link['localized_options'] = array('attributes' => '');
-  }
+  // Only work with menu items that have an mlid, a menu name, and are not disabled.
+  if (isset($link['menu_name']) && isset($link['mlid']) && empty($disabled[$link['menu_name']])) {
+    // TODO: Find out why options sometimes are serialized. Fix this workaround before D7 release!
+    if (!isset($link['localized_options']) || !is_array($link['localized_options'])) {
+      $link['localized_options'] = array('attributes' => '');
+    }
 
-  if (!isset($link['menu_name']) || !isset($link['mlid']) || !empty($disabled[$link['menu_name']])) {
+    $link['localized_options']['attributes']['id'] = 'dhtml_menu-' . _dhtml_menu_unique_id($link['mlid']);
+
+    // Each link in series is another level of recursion. Add it to the stack.
+    _dhtml_menu_stack($link);
+  }
+  else {
     $link['dhtml_disabled'] = TRUE;
   }
 
-  $link['localized_options']['attributes']['id'] = 'dhtml_menu-' . _dhtml_menu_unique_id($link['mlid']);
-
-  // Each link in series is another level of recursion. Add it to the stack.
-  _dhtml_menu_stack($link);
-
   // Pass the altered variables to the normal menu themer.
-  $theme = variable_get('dhtml_menu_theme_menu_item_link', 'theme_menu_item_link');
   return $theme($link);
 }
 
@@ -73,9 +75,10 @@ function dhtml_menu_theme_menu_item_link
  * were not rendered, and loads and renders them.
  */
 function dhtml_menu_theme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
-  static $cookie;
+  static $cookie, $theme;
   if (!isset($cookie)) {
-    $cookie = explode(',', @$_COOKIE['dhtml_menu']);
+    $cookie = !empty($_COOKIE['dhtml_menu']) ? explode(',', $_COOKIE['dhtml_menu']) : array();
+    $theme = variable_get('dhtml_menu_theme_menu_item', 'theme_menu_item');
   }
 
   /* When theme('menu_item') is called, the menu tree below it has been
@@ -91,7 +94,8 @@ function dhtml_menu_theme_menu_item($lin
   $current = current($stack);
   if (!empty($current['dhtml_disabled'])) {
     $extra_class .= ' no-dhtml ';
-    return theme_menu_item($link, $has_children, $menu, $in_active_trail, $extra_class);
+    // Cascade up to the original theming function.
+    return $theme($link, $has_children, $menu, $in_active_trail, $extra_class);
   }
   
   // If there are children, but they were not loaded...
@@ -109,8 +113,6 @@ function dhtml_menu_theme_menu_item($lin
     $extra_class .= ' collapsed start-collapsed ';
   }
 
-  // Cascade up to the original theming function.
-  $theme = variable_get('dhtml_menu_theme_menu_item', 'theme_menu_item');
   return $theme($link, $has_children, $menu, $in_active_trail, $extra_class);
 }
 
