diff -urp book_orig/book.admin.inc book/book.admin.inc
--- book_orig/book.admin.inc	2008-10-22 21:26:01.000000000 +0200
+++ book/book.admin.inc	2010-05-18 19:36:57.000000000 +0200
@@ -160,7 +160,12 @@ function _book_admin_table($node, &$form
       '#type' => 'value',
       '#value' => $hash,
     );
-    _book_admin_table_tree($tree['below'], $form['table']);
+    // Delta must be an integer > the number of nodes in the book.
+    $delta = count($tree['below']) + 1;
+    if ($delta < 15) {
+      $delta = 15;
+    }
+    _book_admin_table_tree($tree['below'], $form['table'], $delta);
   }
 }
 
@@ -169,7 +174,7 @@ function _book_admin_table($node, &$form
  *
  * @see book_admin_edit()
  */
-function _book_admin_table_tree($tree, &$form) {
+function _book_admin_table_tree($tree, &$form, $delta) {
   foreach ($tree as $data) {
     $form['book-admin-'. $data['link']['nid']] = array(
       '#item' => $data['link'],
@@ -185,7 +190,7 @@ function _book_admin_table_tree($tree, &
       'weight' => array(
         '#type' => 'weight',
         '#default_value' => $data['link']['weight'],
-        '#delta' => 15,
+        '#delta' => $delta,
       ),
       'plid' => array(
         '#type' => 'textfield',
@@ -198,7 +203,7 @@ function _book_admin_table_tree($tree, &
       ),
     );
     if ($data['below']) {
-      _book_admin_table_tree($data['below'], $form);
+      _book_admin_table_tree($data['below'], $form, $delta);
     }
   }
 
diff -urp book_orig/book.module book/book.module
--- book_orig/book.module	2009-02-25 12:47:37.000000000 +0100
+++ book/book.module	2010-05-18 19:38:34.000000000 +0200
@@ -214,6 +214,38 @@ function book_block($op = 'list', $delta
           // There should only be one element at the top level.
           $data = array_shift($tree);
           $block['subject'] = theme('book_title_link', $data['link']);
+          /* With many pages on the same depth one level below the index page for the book
+          the bookmenu becomes very long. This code was added to create a "context sensitive"
+          menu when browsing a book: an x number of pages above the current one and the same number
+          of pages below the current one is shown in the book menu.
+          At the index page and the first (x + 1) pages only the first (2*x + 1) pages are shown. */
+          if (isset($data['below'])) {
+            $no_shown_above_below = 10;
+            $totaal = count($data['below']);
+            if ($totaal > (2 * $no_shown_above_below + 1)) {
+              $nummer_in_array = 0;
+              $on_index_page = 1;
+              // we need to know where we are in the menu array
+              foreach($data['below'] as $key => $subdata) {
+                $nummer_in_array++;
+                if ($subdata['link']['in_active_trail'] == 1) {
+                  $on_index_page--;
+                  break; // active page found
+                }
+              }
+              if (($nummer_in_array < ($no_shown_above_below + 1) && $on_index_page == 0) | $on_index_page == 1) {
+              // early page or on index page
+                $data['below'] = array_slice($data['below'], 0, (2 * $no_shown_above_below + 1));
+              } 
+              elseif ($totaal - $nummer_in_array < $no_shown_above_below && $on_index_page == 0) {
+              // close to the end of the number of pages
+                $data['below'] = array_slice($data['below'], ($totaal - (2 * $no_shown_above_below + 1)), (2 * $no_shown_above_below + 1));
+              } 
+              else {
+                $data['below'] = array_slice($data['below'], ($nummer_in_array - $no_shown_above_below - 1), (2 * $no_shown_above_below + 1));
+              }
+            }
+          }
           $block['content'] = ($data['below']) ? menu_tree_output($data['below']) : '';
         }
       }
@@ -381,12 +413,17 @@ function _book_add_form_elements(&$form,
   }
 
   $form['book']['plid'] = _book_parent_select($node->book);
+  // Delta must be an integer > the number of nodes in the book.
+  $delta = db_result(db_query('SELECT COUNT(nid) - 1 FROM {book} WHERE bid = %d', $node->book['bid'])) + 1;
+  if ($delta < 15) {
+    $delta = 15;
+  }
 
   $form['book']['weight'] = array(
     '#type' => 'weight',
     '#title' => t('Weight'),
     '#default_value' => $node->book['weight'],
-    '#delta' => 15,
+    '#delta' => $delta,
     '#weight' => 5,
     '#description' => t('Pages at a given level are ordered first by weight and then by title.'),
   );
