--- original-betterselect.module	2011-01-22 08:21:37.000000000 -0800
+++ betterselect.module	2011-01-22 13:00:37.000000000 -0800
@@ -46,6 +46,13 @@ function betterselect_admin_settings() {
     '#description' => t('Only convert select lists on node forms'),
     '#default_value' => variable_get('betterselect_node_form_only', FALSE),
   );
+  
+  $form['betterselect_general']['betterselect_group_parents'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Group parents'),
+    '#description' => t('Contain parents in elements for advanced theming.'),
+    '#default_value' => variable_get('betterselect_group_parents', FALSE),
+  );
 
   $form['betterselect_taxonomy'] = array(
     '#type' => 'fieldset',
@@ -65,6 +72,7 @@ function betterselect_admin_settings() {
     '#description' => t('Add an extra div to each betterselect option, with a class indicating depth in taxonomy hierarchy. Good for styling parent/child.'),
     '#default_value' => variable_get('betterselect_add_depth_classes', FALSE),
   );
+  
 
   return system_settings_form($form);
 }
@@ -149,6 +157,7 @@ function betterselect_process($element, 
     // Add classes to items that indicate depth, for taxonomy, useful for
     // styling parent terms differently.
     if (variable_get('betterselect_add_depth_classes', FALSE)) {
+      $group_parents = variable_get('betterselect_group_parents', FALSE);
       $prev = NULL;
       $prev_depth = 0;
       foreach (element_children($element) as $key) {
@@ -168,11 +177,23 @@ function betterselect_process($element, 
             $alt_classes = 'checkbox-depth-' . $prev_depth . ' has-children';
             $prev['#prefix'] = '<div class="' . $alt_classes . '">';
             $prev['#suffix'] = '</div>';
+            if($group_parents) {
+	            $gclass = 'checkbox-group ';
+	            $retval = strtolower(str_replace(' ', '_', $prev['#return_value']));
+	            $gclass .= 'checkbox-group-'.$retval;
+	            $prev['#prefix'] = '<span class="'.$gclass.'">'."\n".$prev['#prefix'];
+            }
+          }
+          if($group_parents) {
+	          if($depth < $prev_depth) {
+		          $prev['#suffix'] .= "\n".'</span>';
+	          }
           }
         }
         $prev = &$element[$key];
         $prev_depth = $depth;
       }
+      
     }
 
     // Add the necessary prefix/suffix to make JS/CSS work.
