--- switchtheme_old.module	2008-04-20 16:33:33.000000000 -0400
+++ switchtheme_D5_new.module	2008-12-03 11:54:52.000000000 -0500
@@ -13,8 +13,10 @@ function switchtheme_help($section) {
   switch ($section) {
     case 'admin/settings/modules#description':
       return t('Creates a switch theme block to allow users to switch themes on the fly. The block can be enabled by role and the admin can define labels to use for each available theme.');
-
+	case 'admin/settings/switchtheme/browser':
+      return t('Change which theme is used for each browser.');
     case 'admin/settings/switchtheme':
+    case 'admin/settings/switchtheme/themes':
       return t('Set a label for each enabled theme. This is what will be displayed to the user in the selection box.');
   }
 }
@@ -33,16 +35,38 @@ function switchtheme_menu($may_cache) {
   global $custom_theme, $user;
   $items = array();
 
-  if ($may_cache) {
+  if ($may_cache) {	
     $items[] = array(
       'path'     => 'admin/settings/switchtheme',
-      'title'    => t('switchtheme settings'),
+      'title'    => t('Switchtheme settings'),
       'description' => t('Set the labels for the themes in the switchtheme block.'),
       'access'   => user_access('administer switch'),
       'callback' => 'drupal_get_form',
       'callback arguments' => array('switchtheme_admin_settings')
+    
     );
-  }
+	$items[] = array(
+	  'path' => 'admin/settings/switchtheme/themes',
+	  'title' => 'Themes',
+      'description' => 'Theme display settings for the Switchtheme block.',
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+      'weight' => -10,
+	); //This part works
+	
+	if (module_exists('browscap')) {
+    $items[] = array(
+      'path' =>'admin/settings/switchtheme/browser',
+      'title' => 'Browser',
+      'description' => "Configuration of switching the theme based on the visitor's browser.",
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('switchtheme_admin_browser_settings'),
+      'access' => array('administer switch'),
+      'type' => MENU_LOCAL_TASK,
+      'weight' => 2,
+    );
+		}
+  	}
+  
   else {
     drupal_add_css(drupal_get_path('module', 'switchtheme') .'/switchtheme.css');
 
@@ -56,13 +80,27 @@ function switchtheme_menu($may_cache) {
     if (isset($_SESSION['custom_theme']) && !isset($custom_theme)) {
       $custom_theme = $_SESSION['custom_theme'];
     }
+    //the browser code - apparently not working/distinguishing the browser.
+        if (module_exists('browscap') && variable_get('switchtheme_browser_enabled', FALSE)) {
+    $browser = browscap_get_browser();
+    if (isset($browser['parent'])) {
+      $parent = trim($browser['parent']);
+      $browser_theme = variable_get('switchtheme_browser_'. md5($parent), 'default');
+      if ($browser_theme != 'default') {
+        $custom_theme = $browser_theme;
+      }
+    }
+  }
+
+  
   }
   return $items;
 }
 
 /**
- * Form builder function for administration page; menu callback.
+ * Form builder function for theme page; menu callback.
  */
+ 
 function switchtheme_admin_settings() {
   $options = switchtheme_options();
   foreach ($options as $option) {
@@ -77,6 +115,47 @@ function switchtheme_admin_settings() {
 }
 
 /**
+ * Form builder function for browser page; menu callback.
+ * This part shows up and retrieves the browsers from the browscap table properly, but chokes when you try to submit.
+ */
+function switchtheme_admin_browser_settings() {
+  $form = array();
+  $form['switchtheme_browser_enabled'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Browser-based theme switching'),
+    '#description' => t('If enabled, the theme will be switched based on the browser of a visitor.'),
+    '#default_value' => variable_get('switchtheme_browser_enabled', FALSE),
+  );
+  
+  $themes = switchtheme_select();
+  $themes['default'] = 'Default';
+  $useragents = array();
+  $result = db_query('SELECT data FROM {browscap}');
+  while ($row = db_fetch_object($result)) {
+    $data = $row->data;
+    $data = unserialize($data);
+    if (isset($data['parent'])) {
+      $useragents[trim($data['parent'])][] = isset($data['platform']) ? $data['platform'] : '';
+    }
+  }
+  $form['switchtheme_browser'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Browsers'),
+    '#collapsible' => FALSE,
+    '#collapsed' => FALSE,
+  );
+  foreach ($useragents as $parent => $platforms) {
+    $form['switchtheme_browser']['switchtheme_browser_'. md5($parent)] = array(
+      '#type' => 'select',
+      '#title' => $parent,
+      '#options' => $themes,
+      '#default_value' => variable_get('switchtheme_browser_'. md5($parent), 'default'),
+    );
+  }
+  return system_settings_form($form);
+}
+
+/**
  * Implementation of hook_block().
  */
 function switchtheme_block($op = 'list', $delta = 0, $edit = array()) {
