Index: /Users/ucweb/Sites/drupal/sites/all/modules/headerimage/headerimage.module
===================================================================
--- /Users/ucweb/Sites/drupal/sites/all/modules/headerimage/headerimage.module	(revision 447)
+++ /Users/ucweb/Sites/drupal/sites/all/modules/headerimage/headerimage.module	(revision 453)
@@ -343,6 +343,9 @@
           case 'php':
             $match = drupal_eval($condition);
             break;
+					case 'og':
+						$match = headerimage_eval_og($condition);
+						break;
         }
       }
       if ($match) break;
@@ -473,6 +476,38 @@
 }
 
 /**
+ * Evaluate og condition
+ * 
+ * Return true if current node belongs to the group selected in the condition
+ * 
+ * @param $condition
+ *   array of organic group nids
+ *
+ * @return
+ *   true: current node is a page in $condition's groups
+ *   false: if not
+ */
+function headerimage_eval_og($condition) {
+	
+  if (is_numeric(arg(1))) {
+		if (in_array(arg(1), $condition)) return true; // Node may be a group itself
+	
+		/* TODO: We should probably make sure that organic groups is installed
+			 before calling og_get_node_groups_result. Scenario: User removes 
+			 the og module after Header Image is already configured. However, 
+			 headerimage_eval_book doesn't check for the book module, so both
+			 of these and any others should be fixed in a different patch.
+		*/
+		$result = og_get_node_groups_result(arg(1));
+	
+		while ($og = db_fetch_object($result))
+			if (in_array($og->group_nid, $condition)) return true;
+	}
+
+  return false; // Current node does not meet any group conditions
+}
+
+/**
  * Implementation of hook_form_alter
  */
 function headerimage_form_alter($form_id, &$form) {
@@ -614,6 +649,33 @@
                 '#rows' => 4,
               );
               break;
+						case 'og':
+							if (module_exists('og')) {
+								$result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {og} g INNER JOIN {node} n ON g.nid = n.nid WHERE n.status = 1 ORDER BY n.title ASC'));
+								while ($data = db_fetch_object($result)) {
+                  $groups[$data->nid] = $data->title;
+                }
+
+                if (isset($groups)) {
+                  $description = t("One or more groups may be selected.");
+                }
+                else {
+                  $description = t("No groups defined. Please create a group before using it as a condition.");
+                }
+                $form['headerimage'][$name] = array(
+                  '#type' => 'select',
+                  '#title' => $title,
+                  '#description' => $description,
+                  '#default_value' => $form['#node']->$name,
+                  '#options' => $groups,
+                  '#multiple' => true,
+                );
+
+							}
+              else {
+                drupal_set_message(t("The og module is not enabled. Please enable the module or remove it from the !settings.",
+                  array('!settings' => l(t('Header Image settings'), 'admin/settings/headerimage/settings'))));
+              }
           }
         }
       }
@@ -737,6 +799,7 @@
     'book' => t('Book'),
     'nodetype' => t('Node type'),
     'php' => t('PHP'),
+		'og' => t('Organic Groups'),
   );
 }
 
