Index: book.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/book.module,v
retrieving revision 1.314
diff -U3 -r1.314 book.module
--- book.module	30 Aug 2005 15:22:29 -0000	1.314
+++ book.module	3 Sep 2005 21:28:16 -0000
@@ -485,45 +485,51 @@
   }
   $node->breadcrumb[] = array('path' => 'node/'. $node->nid);
 
-  if ($node->nid) {
-    $output .= '<div class="book">';
-
-    if ($tree = book_tree($node->nid)) {
-      $output .= '<div class="tree">'. $tree .'</div>';
-    }
+  // Construct the links and titles
+  $prev = book_prev($node);
+  $next = book_next($node);
+  if ($prev) {
+    $links .= '<div class="prev">';
+    $links .= l(t('previous'), 'node/'. $prev->nid, array('title' => t('View the previous page.')));
+    $links .= '</div>';
+    $titles .= '<div class="prev">'. check_plain($prev->title) .'</div>';
+  }
+  elseif($next) {
+    // Make an empty div to fill the space only if there are $next links
+    $links .= '<div class="prev">&nbsp;</div>';
+  }
+
+  if ($next) {
+    $links .= '<div class="next">';
+    $links .= l(t('next'), 'node/'. $next->nid, array('title' => t('View the next page.')));
+    $links .= '</div>';
+    $titles .= '<div class="next">'. check_plain($next->title) .'</div>';
+  }
+  elseif($prev) {
+    // Make an empty div to fill the space only if there are $prev links
+    $links .= '<div class="next">&nbsp;</div>';
+  }
+  
+  if ($node->parent) {
+    $links .= '<div class="up">';
+    $links .= l(t('up'), 'node/'. $node->parent, array('title' => t('View this page\'s parent section.')));
+    $links .= '</div>';
+  }
 
-    if ($prev = book_prev($node)) {
-      $links .= '<div class="prev">';
-      $links .= l(t('previous'), 'node/'. $prev->nid, array('title' => t('View the previous page.')));
-      $links .= '</div>';
-      $titles .= '<div class="prev">'. check_plain($prev->title) .'</div>';
-    }
-    else {
-      $links .= '<div class="prev">&nbsp;</div>'; // Make an empty div to fill the space.
-    }
-    if ($next = book_next($node)) {
-      $links .= '<div class="next">';
-      $links .= l(t('next'), 'node/'. $next->nid, array('title' => t('View the next page.')));
-      $links .= '</div>';
-      $titles .= '<div class="next">'. check_plain($next->title) .'</div>';
-    }
-    else {
-      $links .= '<div class="next">&nbsp;</div>'; // Make an empty div to fill the space.
-    }
-    if ($node->parent) {
-      $links .= '<div class="up">';
-      $links .= l(t('up'), 'node/'. $node->parent, array('title' => t('View this page\'s parent section.')));
-      $links .= '</div>';
-    }
+  if ($tree = book_tree($node->nid)) {
+    $output = '<div class="tree">'. $tree .'</div>';
+  }
 
+  if($links) {
     $output .= '<div class="nav">';
     $output .= ' <div class="links">'. $links .'</div>';
     $output .= ' <div class="titles">'. $titles .'</div>';
     $output .= '</div>';
-    $output .= '</div>';
   }
 
-  $node->body = $node->body.$output;
+  if($output) {
+    $node->body = $node->body .'<div class="book">'. $output .'</div>';
+  }
 
   return $node;
 }
