diff --git includes/menu.inc includes/menu.inc
index fb61fd3..ed25da3 100644
--- includes/menu.inc
+++ includes/menu.inc
@@ -1197,7 +1197,7 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail =
         // parameters accordingly.
         if ($item['access']) {
           // Find a menu link corresponding to the current path.
-          if ($active_link = menu_link_get_preferred()) {
+          if ($active_link = menu_link_get_preferred(NULL, $menu_name)) {
             // The active link may only be taken into account to build the
             // active trail, if it resides in the requested menu. Otherwise,
             // we'd needlessly re-run _menu_build_tree() queries for every menu
@@ -2204,6 +2204,12 @@ function theme_menu_local_tasks(&$variables) {
 
 /**
  * Set (or get) the active menu for the current page - determines the active trail.
+ *
+ * @return
+ *   An array of menu machine names, in order of preference. The
+ *   'menu_default_active_menus' variable may be used to assert a menu order
+ *   different from the order of creation, or to prevent a particular menu from
+ *   being used at all in the active trail.
  */
 function menu_set_active_menu_names($menu_names = NULL) {
   $active = &drupal_static(__FUNCTION__);
@@ -2336,6 +2342,10 @@ function menu_set_active_trail($new_trail = NULL) {
  * @param $path
  *   The path, for example 'node/5'. The function will find the corresponding
  *   menu link ('node/5' if it exists, or fallback to 'node/%').
+ * @param $menu_name
+ *   The name of a menu used to restrict the search for a prefered menu link.
+ *   If not specified, all the menus returned by menu_get_active_menu_names()
+ *   will be used.
  *
  * @return
  *   A fully translated menu link, or NULL if not matching menu link was
@@ -2343,15 +2353,15 @@ function menu_set_active_trail($new_trail = NULL) {
  *   the most preferred menu (as defined by menu_get_active_menu_names()) is
  *   returned.
  */
-function menu_link_get_preferred($path = NULL) {
+function menu_link_get_preferred($path = NULL, $menu_name = '') {
   $preferred_links = &drupal_static(__FUNCTION__);
 
   if (!isset($path)) {
     $path = $_GET['q'];
   }
 
-  if (!isset($preferred_links[$path])) {
-    $preferred_links[$path] = FALSE;
+  if (!isset($preferred_links[$path][$menu_name])) {
+    $preferred_links[$path][$menu_name] = FALSE;
 
     // Look for the correct menu link by building a list of candidate paths,
     // which are ordered by priority (translated hrefs are preferred over
@@ -2373,7 +2383,12 @@ function menu_link_get_preferred($path = NULL) {
     }
 
     // Retrieve a list of menu names, ordered by preference.
-    $menu_names = menu_get_active_menu_names();
+    if ($menu_name !== '') {
+      $menu_names = array($menu_name);
+    }
+    else {
+      $menu_names = menu_get_active_menu_names();
+    }
 
     $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
     $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
@@ -2381,7 +2396,6 @@ function menu_link_get_preferred($path = NULL) {
     // Weight must be taken from {menu_links}, not {menu_router}.
     $query->addField('ml', 'weight', 'link_weight');
     $query->fields('m');
-    $query->condition('ml.menu_name', $menu_names, 'IN');
     $query->condition('ml.link_path', $path_candidates, 'IN');
 
     // Sort candidates by link path and menu name.
@@ -2391,27 +2405,31 @@ function menu_link_get_preferred($path = NULL) {
       $candidates[$candidate['link_path']][$candidate['menu_name']] = $candidate;
     }
 
-    // Pick the most specific link, in the most preferred menu.
+    // Store the most specific link for each menu. Also save the most specific
+    // link of the most preferred menu in $preferred_link.
+    $preferred_link = FALSE;
     foreach ($path_candidates as $link_path) {
-      if (!isset($candidates[$link_path])) {
-        continue;
-      }
-      foreach ($menu_names as $menu_name) {
-        if (!isset($candidates[$link_path][$menu_name])) {
-          continue;
-        }
-        $candidate_item = $candidates[$link_path][$menu_name];
-        $map = explode('/', $path);
-        _menu_translate($candidate_item, $map);
-        if ($candidate_item['access']) {
-          $preferred_links[$path] = $candidate_item;
+      if (isset($candidates[$link_path])) {
+        foreach ($menu_names as $menu) {
+          if (!$preferred_links[$path][$menu] && isset($candidates[$link_path][$menu])) {
+            $candidate_item = $candidates[$link_path][$menu];
+            $map = explode('/', $path);
+            _menu_translate($candidate_item, $map);
+            if ($candidate_item['access']) {
+              $preferred_links[$path][$menu] = $candidate_item;
+              if (!$preferred_link) {
+                $preferred_link = $candidate_item;
+              }
+            }
+          }
         }
-        break 2;
       }
     }
+    // Store the most specific link.
+    $preferred_links[$path][''] = $preferred_link;
   }
 
-  return $preferred_links[$path];
+  return $preferred_links[$path][$menu_name];
 }
 
 /**
diff --git modules/menu/menu.install modules/menu/menu.install
index 7f6a1fa..e77d700 100644
--- modules/menu/menu.install
+++ modules/menu/menu.install
@@ -70,3 +70,33 @@ function menu_uninstall() {
   menu_rebuild();
 }
 
+/**
+ * @addtogroup updates-6.x-to-7.x
+ * @{
+ */
+
+/**
+ * Add missing custom menus to active menus list.
+ */
+function menu_update_7000(&$sandbox) {
+  // Make sure all custom menus are present in the active menus variable so that
+  // their items may appear in the active trail.
+  // @see menu_set_active_menu_names()
+  $active_menus = variable_get('menu_default_active_menus', array_keys(menu_list_system_menus()));
+  $update_variable = FALSE;
+  foreach (menu_get_names() as $menu_name) {
+    if (!in_array($menu_name, $active_menus) && (strpos($menu_name, 'menu-') === 0)) {
+      $active_menus[] = $menu_name;
+      $update_variable = TRUE;
+    }
+  }
+  if ($update_variable) {
+    variable_set('menu_default_active_menus', $active_menus);
+  }
+  // Clear the menu cache.
+  cache_clear_all(NULL, 'cache_menu');
+}
+
+/**
+ * @} End of "addtogroup updates-6.x-to-7.x"
+ */
diff --git modules/menu/menu.module modules/menu/menu.module
index 44b3772..7c1a499 100644
--- modules/menu/menu.module
+++ modules/menu/menu.module
@@ -262,6 +262,15 @@ function menu_save($menu) {
 
   switch ($status) {
     case SAVED_NEW:
+      // Make sure the menu is present in the active menus variable so that its
+      // items may appear in the menu active trail.
+      // @see menu_set_active_menu_names()
+      $active_menus = variable_get('menu_default_active_menus', array_keys(menu_get_menus()));
+      if (!in_array($menu['menu_name'], $active_menus)) {
+        $active_menus[] = $menu['menu_name'];
+        variable_set('menu_default_active_menus', $active_menus);
+      }
+
       module_invoke_all('menu_insert', $menu);
       break;
 
@@ -299,6 +308,15 @@ function menu_delete($menu) {
   // Delete all links from the menu.
   menu_delete_links($menu['menu_name']);
 
+  // Remove menu from active menus variable.
+  $active_menus = variable_get('menu_default_active_menus', array_keys(menu_get_menus()));
+  foreach ($active_menus as $i => $menu_name) {
+    if ($menu['menu_name'] == $menu_name) {
+      unset($active_menus[$i]);
+      variable_set('menu_default_active_menus', $active_menus);
+    }
+  }
+
   // Delete the custom menu.
   db_delete('menu_custom')
     ->condition('menu_name', $menu['menu_name'])
