--- bookold.module	2006-10-25 02:09:42.000000000 -0400
+++ book.module	2006-10-25 01:55:05.000000000 -0400
@@ -169,13 +169,6 @@ function book_block($op = 'list', $delta
   }
 }
 
-/**
- * Implementation of hook_load().
- */
-function book_load($node) {
-  $book = db_fetch_object(db_query('SELECT * FROM {book} WHERE vid = %d', $node->vid));
-  return $book;
-}
 
 /**
  * Implementation of hook_insert().
@@ -185,25 +178,6 @@ function book_insert($node) {
 }
 
 /**
- * Implementation of hook_update().
- */
-function book_update($node) {
-  if ($node->revision) {
-    db_query("INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)", $node->nid, $node->vid, $node->parent, $node->weight);
-  }
-  else {
-    db_query("UPDATE {book} SET parent = %d, weight = %d WHERE vid = %d", $node->parent, $node->weight, $node->vid);
-  }
-}
-
-/**
- * Implementation of hook_delete().
- */
-function book_delete(&$node) {
-  db_query('DELETE FROM {book} WHERE nid = %d', $node->nid);
-}
-
-/**
  * Implementation of hook_submit().
  */
 function book_submit(&$node) {
@@ -279,17 +253,16 @@ function book_form(&$node) {
  */
 function book_outline($nid) {
   $node = node_load($nid);
-  $page = book_load($node);
 
   $form['parent'] = array('#type' => 'select',
     '#title' => t('Parent'),
-    '#default_value' => $page->parent,
+    '#default_value' => $node->parent,
     '#options' => book_toc($node->nid),
     '#description' => t('The parent page in the book.'),
   );
   $form['weight'] = array('#type' => 'weight',
     '#title' => t('Weight'),
-    '#default_value' => $page->weight,
+    '#default_value' => $node->weight,
     '#delta' => 15,
     '#description' => t('Pages at a given level are ordered first by weight and then by title.'),
   );
@@ -299,7 +272,7 @@ function book_outline($nid) {
   );
 
   $form['nid'] = array('#type' => 'value', '#value' => $nid);
-  if ($page->nid) {
+  if (is_numeric($node->parent)) {
     $form['update'] = array('#type' => 'submit',
       '#value' => t('Update book outline'),
     );
@@ -488,6 +461,23 @@ function book_nodeapi(&$node, $op, $teas
         }
       }
       break;
+    case 'load':
+      $book = db_fetch_object(db_query('SELECT * FROM {book} WHERE vid = %d', $node->vid));
+      if ($book) {
+        $node->parent = $book->parent;
+        $node->weight = $book->weight;
+      }
+      break;
+    case 'update':
+      if (is_numeric($node->parent)) { // don't fire if this node is not in an outline
+        if ($node->revision) {
+          db_query("INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)", $node->nid, $node->vid, $node->parent, $node->weight);
+        }
+        else {
+          db_query("UPDATE {book} SET parent = %d, weight = %d WHERE vid = %d", $node->parent, $node->weight, $node->vid);
+        }
+      }
+      break;
     case 'delete revision':
       db_query('DELETE FROM {book} WHERE vid = %d', $node->vid);
       break;
