--- /f/projects/drupal/cvs/contributions/modules/taxonomy_dhtml/taxonomy_dhtml.module	2006-05-26 19:35:26.218750000 -0400
+++ modules/taxonomy_dhtml/taxonomy_dhtml.module	2006-05-27 01:53:59.765625000 -0400
@@ -22,22 +22,33 @@ function taxonomy_dhtml_block($op = "lis
 
 // TODO: recipe.module and node_aggregator did use $type to filter results to their own node type. no longer supported (but should be)
 function taxonomy_dhtml_vocab_vert($vocabulary_id, $op = NULL) {
-  $tree = taxonomy_get_tree($vocabulary_id);
-  // build an array which holds all children of current term. necessary to build a proper 'or' value in the HREF
-  foreach ($tree as $term) {
-    $url = "taxonomy/term/$term->tid/9";
-    if ($op) {
-      $url .= "/$op";
-    }
-    $link = l(t($term->name), $url, array("title" => t($term->description)));
-    $out .= _taxonomy_depth($term->depth, "&nbsp;")."- $link";
+  return theme('item_list', _taxonomy_dhtml_build_list_items($index = 0, taxonomy_get_tree($vocabulary_id), $op));
+}
+
+function _taxonomy_dhtml_build_list_items(&$index, $tree, $op = NULL) {
+  $items = array();
+  $current_depth = $tree[$index]->depth;
+  while($index < count($tree) && $tree[$index]->depth >= $current_depth) {
+    $term = $tree[$index];
     $count = taxonomy_term_count_nodes($term->tid);
     if ($count) {
-      $out .= " ($count)";
+      $term_path = "taxonomy/term/$term->tid/9". ($op ? "/$op" : '');
+      $term_link = l(t($term->name), $term_path, array('title' => t($term->description)));
+      $item = $term_link . " ($count)";
+      if ($tree[$index+1]->depth > $current_depth) {
+        $index++;
+        $items[] = array('item' => $item, 'children' => _taxonomy_dhtml_build_list_items($index, $tree, $op));
+      }
+      else {
+        $items[] = $item;
+        $index++;
+      }
+    }
+    else {
+      $index++;
     }
-    $out .= "<br />";
   }
-  return $out;
+  return $items;
 }
 
 // accepts an optional param for restricting nodes to a particular type
