--- headerimage.module	2008-02-10 16:51:09.000000000 -0500
+++ headerimage.module	2008-04-14 13:44:34.000000000 -0400
@@ -270,7 +270,7 @@ function headerimage_block($op = 'list',
     case 'configure':
       return headerimage_block_configure($delta);
     case 'save':
-      break;
+      variable_set('headerimage_block_'. $delta .'_random_fallback', $edit['random_fallback']);
     case 'view':
       if (user_access('view header image')) {
         // select node from nodes assigned to this block
@@ -307,7 +307,9 @@ function headerimage_block($op = 'list',
  * Select a node to be displayed in the block
  *
  * Node selection by (1)weight and (2)condition.
- *     If multiple conditions are present, any true condition will select the node
+ * If multiple conditions are present, any true condition will select the node.
+ * If no node is selected by the conditions and random fallback selection is
+ * enabled for the block, one of the available nodes will be selected at random.
  *
  * @param $block
  *   The headerimage block number ($delta)
@@ -321,6 +323,7 @@ function headerimage_select_node($block)
   while ($header_image = db_fetch_object($result)) {
     $conditions = unserialize($header_image->conditions);
     $match = false;
+    $block_nids[] = $header_image->nid; // store the nid in an array for the random selection fallback option
     $selected_types = variable_get(headerimage_condition_types, array('nid' => 'nid'));
     foreach ($conditions as $type => $condition) {
       if (!empty($condition) && !empty($selected_types[$type])) {
@@ -349,7 +352,14 @@ function headerimage_select_node($block)
     }
     if ($match) break;
   }
-  return $match ? $header_image->nid : null;
+  if ($match) {
+    return $header_image->nid;
+    drupal_set_message('nid selected by condition: '. $header_image->nid);
+  } elseif (variable_get('headerimage_block_'. $block .'_random_fallback', 0) && count($block_nids)) {
+    return $block_nids[array_rand($block_nids)];
+  } else {
+    return null;
+  }
 }
 
 /**
@@ -665,6 +675,12 @@ function headerimage_block_configure($de
     '#value' => $output,
     '#suffix' => '</div>',
   );
+  $form['headerimage']['random_fallback'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable a random fallback selection'),
+    '#default_value' => variable_get('headerimage_block_'. $delta .'_random_fallback', 0),
+    '#description' => t('If no node is selected by the conditions, select a random node from those assigned to this block.'),
+  );
   return $form;
 }
 
