Index: /trunk/admin.php
===================================================================
--- /trunk/admin.php	(revision 5172)
+++ /trunk/admin.php	(revision 5173)
@@ -165,4 +165,6 @@
 // +-----------------------------------------------------------------------+
 
+$template->assign('ACTIVE_MENU', get_active_menu($page['page']));
+
 if (count($page['errors']) != 0)
 {
Index: /trunk/admin/include/functions.php
===================================================================
--- /trunk/admin/include/functions.php	(revision 5172)
+++ /trunk/admin/include/functions.php	(revision 5173)
@@ -1906,3 +1906,79 @@
   return 'http://'.$subscribe_domain.'/announcement/subscribe/';
 }
+
+/**
+ * Accordion menus need to know which section to open by default when
+ * loading the page
+ */
+function get_active_menu($menu_page)
+{
+  global $page;
+
+  if (isset($page['active_menu']))
+  {
+    return $page['active_menu'];
+  }
+
+  // specific cases
+  if ('element_set' == $menu_page)
+  {
+    if (isset($_GET['cat']) and is_numeric($_GET['cat']))
+    {
+      return 1;
+    }
+    else
+    {
+      return 0;
+    }
+  }
+  
+  switch ($menu_page)
+  {
+    case 'photos_add':
+    case 'upload':
+    case 'comments': // really needs to be moved somewhere else
+    case 'rating':
+    case 'tags':
+    case 'picture_modify':
+      return 0;
+
+    case 'site_manager':
+    case 'site_update':
+    case 'cat_list':
+    case 'cat_modify':
+    case 'cat_move':
+    case 'cat_options':
+    case 'cat_perm':
+    case 'permalinks':
+      return 1;
+      
+    case 'user_list':
+    case 'user_perm':
+    case 'group_list':
+    case 'group_perm':
+    case 'notification_by_mail':
+      return 2;
+
+    case 'plugins_list':
+    case 'plugins_update':
+    case 'plugins_new':
+    case 'plugin':
+      return 3;
+      
+    case 'stats':
+    case 'history':
+    case 'maintenance':
+    case 'advanced_feature':
+    case 'thumbnail':
+      return 4;
+
+    case 'configuration':
+    case 'extend_for_templates':
+    case 'menubar':
+    case 'themes_new':
+    case 'themes_installed':
+      return 5;
+  }
+  return 0;
+}
 ?>
Index: unk/admin/include/functions_themes.inc.php
===================================================================
--- /trunk/admin/include/functions_themes.inc.php	(revision 5172)
+++ 	(revision )
@@ -1,58 +1,0 @@
-<?php
-/**
- * Accordion menus need to be stable (called by themeconf.inc which need it)
- */
-function selected_admin_menu()
-{
-  if (isset($_GET['page']))
-  {
-    switch ($_GET['page']) {
-      case 'configuration':
-      case 'extend_for_templates':
-      case 'menubar':
-        return 1;
-      case 'site_manager':
-      case 'site_update':
-      case 'cat_list':
-      case 'cat_modify':
-      case 'cat_move':
-      case 'cat_options':
-      case 'cat_perm':
-      case 'permalinks':
-        return 2;
-      case 'element_set':
-        if (isset($_GET['cat']) and is_numeric($_GET['cat']) ) {
-          return 2;
-        }
-      case 'picture_modify':
-        return 3;
-      case 'comments':
-      case 'upload':
-      case 'thumbnail':
-      case 'rating':
-      case 'tags':
-        return 3;
-      case 'user_list':
-      case 'user_perm':
-      case 'group_list':
-      case 'group_perm':
-      case 'notification_by_mail':
-        return 4;
-      case 'stats':
-      case 'history':
-      case 'maintenance':
-      case 'advanced_feature':
-      case 'plugins_list':
-      case 'plugins_update':
-      case 'plugins_new':
-      case 'plugin':
-        return 5;
-    }
-  }
-  if (isset($_GET['plgmenu'])) /* Later added plugins will add plgmenu in url */
-  {
-    return 5;
-  }
-  return 0;
-}
-?>
Index: /trunk/admin/themes/clear/themeconf.inc.php
===================================================================
--- /trunk/admin/themes/clear/themeconf.inc.php	(revision 5172)
+++ /trunk/admin/themes/clear/themeconf.inc.php	(revision 5173)
@@ -1,12 +1,7 @@
 <?php
-if (!function_exists('selected_admin_menu')) 
-{
-  include_once(PHPWG_ROOT_PATH.'admin/include/functions_themes.inc.php');
-}
 $themeconf = array(
   'theme'    => 'clear',
   'parent'   => 'default',
   'admin_icon_dir' => 'admin/themes/clear/icon',
-  'selected_admin_menu' => selected_admin_menu(),
 );
 ?>
Index: /trunk/admin/themes/default/template/admin.tpl
===================================================================
--- /trunk/admin/themes/default/template/admin.tpl	(revision 5172)
+++ /trunk/admin/themes/default/template/admin.tpl	(revision 5173)
@@ -8,5 +8,5 @@
     header: "dt.rdion",
     event: "click",
-    active: {$U_ACTIVE_MENU|default:$themeconf.selected_admin_menu}
+    active: {$ACTIVE_MENU}
   });
 });
Index: /trunk/admin/themes/roma/themeconf.inc.php
===================================================================
--- /trunk/admin/themes/roma/themeconf.inc.php	(revision 5172)
+++ /trunk/admin/themes/roma/themeconf.inc.php	(revision 5173)
@@ -1,11 +1,6 @@
 <?php
-if (!function_exists('selected_admin_menu')) 
-{
-  include_once(PHPWG_ROOT_PATH.'admin/include/functions_themes.inc.php');
-}
 $themeconf = array(
   'theme'  => 'roma',
   'parent' => 'default',
-  'selected_admin_menu' => selected_admin_menu(),
 );
 ?>
