Index: glossary.module
===================================================================
--- glossary.module	(revision 80)
+++ glossary.module	(working copy)
@@ -733,11 +733,9 @@
 
   $dest = drupal_get_destination();
   $tbl = get_html_translation_table(HTML_SPECIALCHARS);
-  $tbl[' '] = '_';
-  $output = '<div id="'. strtr(drupal_strtolower($vocab->name), $tbl) .'">';
-  if ($vocab->description) {
-    $output .= '<p class="glossary-description">'. $vocab->description .'</p>';
-  }
+  $tbl[' '] = '_';
+	$divid = strtr(drupal_strtolower($vocab->name), $tbl);
+
   $vid = $vocab->vid;
   if ($letter) {
     $letter = drupal_substr($letter, 6, 1, 'UTF-8');
@@ -749,31 +747,65 @@
   $show_desc = variable_get('glossary_show_description', false);
   $separate = variable_get('glossary_separate_letters', false);
   $tree = taxonomy_get_tree($vid);
-  $synonyms = _glossary_get_synonyms($vid);
-  $output .= _glossary_alphabar($vid, $tree);
-  $output .= '<div class="glossary-list">'."\n";
-  $output .= '<dl>'."\n";
-  if ($tree) {
-    foreach ($tree as $term) {
-      $term->synonyms = $synonyms[$term->tid];
-      // See if it's a new section.
-      // If we're looking for a single letter, see if this is it.
-      if ((!$no_overview && !$letter) || $term->let == $letter) {
-        // See if it's a new section.
-        if ($term->let != $current_let) {
-          $current_let = $term->let;
-          $output .= "\n".'<a id="letter'. $term->let .'"></a>';
-          if ($separate) {
-            $output .= '<div class="glossary-letter">'. $term->let .'</div>';
-          }
-        }
-        $output .= theme('glossary_overview_item', $term, $show_desc, $dest);
-      }
-    }
-  }
-  $output .= '</dl></div>';
-  $output .= glossary_admin_links($vocab, $dest);
-  return $output .'</div>';
+  $synonyms = _glossary_get_synonyms($vid);
+	$alphabar = _glossary_alphabar($vid, $tree);
+	$glossary_items = array();
+	
+	if ($tree) {
+		foreach ($tree as $term) {
+			$this_item = '';
+			$term->synonyms = $synonyms[$term->tid];
+      
+			// See if it's a new section.
+			// If we're looking for a single letter, see if this is it.
+			if ((!$no_overview && !$letter) || $term->let == $letter) {
+				// See if it's a new section.
+				if ($term->let != $current_let) {
+					$current_let = $term->let;
+					$this_item .= "\n".'<a id="letter'. $term->let .'"></a>';
+
+					if ($separate) {
+						$this_item .= '<div class="glossary-letter">'. $term->let .'</div>';
+					}
+				}
+				$this_item .= theme('glossary_overview_item', $term, $show_desc, $dest);
+				$glossary_items[] = $this_item;
+			}
+		}
+	}
+	
+  $admin_links = theme('glossary_admin_links', $vocab, $dest);
+  
+  return theme('glossary_overview', $divid, $vocab->description, $alphabar, $glossary_items, $admin_links);
+}
+
+function theme_glossary_overview($divid, $description, $alphabar, $glossary_items) {
+	$output = '<div id="'. $divid .'">';
+	
+	// Render the introductory paragraph.
+	$output .= '<p class="glossary-description">';
+	$output .= $description;
+	$output .= '</p>';
+	
+	//Render the alphabar with the links for each letter.
+	$output .= $alphabar;
+	
+	// If there are any glossary items to display in this section, show them.
+	// Otherwise, don't bother showing an empty div.
+	if (count($glossary_items)) {
+		$output .= '<div class="glossary-list">'."\n";
+		$output .= "<dl>\n";
+		
+		foreach ($glossary_items as $glossary_item) {
+			$output .= $glossary_item;
+		}
+		
+		$output .= '</dl></div>';
+	}
+	
+	$output .= '</div>';
+	
+	return $output;
 }
 
 function theme_glossary_overview_item($term, $show_desc = true, $destination = null, $block = false) {
@@ -903,7 +935,7 @@
   return htmlspecialchars_decode($output);
 }
 
-function glossary_admin_links($vocabulary, $destination = null) {
+function theme_glossary_admin_links($vocabulary, $destination = null) {
   $output = '<div class="glossary-admin-links">';
   $links = array();
   if (user_access('administer taxonomy')) {
@@ -929,7 +961,7 @@
     $output .= theme('links', $links);
   }
   return $output .'</div>';
-  }
+}
 
 function _glossary_list() {
   $output = "";
@@ -1022,10 +1054,10 @@
 
 function _glossary_is_boundary($char) {
   if (extension_loaded('mbstring')) {
-    return (mb_strpos("!\"#\$%&'()*+,-./:;<=>?@[\]^_`{|}~’ “”´°®©¼½¾ \t\n\r", $char) !== false);
+    return (mb_strpos("!\"#\$%&'()*+,-./:;<=>?@[\]^_`{|}~ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ \t\n\r", $char) !== false);
   }
   else {
-    return (strpos("!\"#\$%&'()*+,-./:;<=>?@[\]^_`{|}~’ “”´°®©¼½¾ \t\n\r", $char) !== false);
+    return (strpos("!\"#\$%&'()*+,-./:;<=>?@[\]^_`{|}~ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ \t\n\r", $char) !== false);
   }
 }
 
