--- galleria.module	2009-03-24 03:40:16.000000000 +1300
+++ galleria.module.new	2009-05-18 11:22:15.000000000 +1200
@@ -19,6 +19,7 @@ function galleria_includes() {
 
     $settings = array(
       'thumb_opacity' => variable_get('galleria_thumb_opacity', 0.3),
+      'galleria_lightbox' => variable_get('galleria_lightbox', 0),
     );
     drupal_add_js($settings, 'setting');
     $included = TRUE;
@@ -63,13 +64,23 @@ function galleria_is_valid($node) {
 
   if (is_object($node)) {
     // are there attachments?
-    if (!empty($node->files)) {
-      if (!($valid = galleria_validate_file_extensions($node->files))) {
-        galleria_set_message(t('Invalid Galleria: one or more attached files are not images.'), 'error');
-      }
-    }
-    else {
-      galleria_set_message(t('Invalid Galleria: there are no attachments.'), 'error');
+    switch(variable_get('galleria_mode', 'upload')){
+      case 'upload':
+        if (!empty($node->files)) {
+          if (!($valid = galleria_validate_file_extensions($node->files))) {
+            galleria_set_message(t('Invalid Galleria: one or more attached files are not images.'), 'error');
+          }
+        }
+        else {
+          galleria_set_message(t('Invalid Galleria: there are no attachments.'), 'error');
+        }        
+        break;
+      case 'imagefield':
+        $imagefield = variable_get('galleria_imagefield', '');
+        if( ! empty($node->$imagefield )){
+          $valid = true;
+        }
+        break;
     }
   }
   else {
@@ -198,7 +209,14 @@ function galleria_nodeapi(&$node, $op, $
           if (galleria_is_valid($node)) {
             // this is a galleria node, so perform modifications!
             galleria_includes();
-            unset($node->content['files']);
+            // remove default image display
+            $mode = variable_get('galleria_mode', 'upload');
+            if($mode == 'upload' ){
+              unset($node->content['files']);              
+            }elseif( $mode=='imagefield' ){
+              $imagefield = variable_get('galleria_imagefield', '');
+              unset($node->content[$imagefield]); 
+            }
             $node->content['galleria']['#value'] = theme('galleria', $node);
             $node->content['galleria']['#weight'] = module_exists('content') ? content_extra_field_weight($node->type, "galleria") : -10;
           }
@@ -236,7 +254,13 @@ function theme_galleria_lightbox_link($n
  */
 function template_preprocess_galleria(&$vars) {
   $node = $vars['node'];
-  $files = $node->files;
+  $mode = variable_get('galleria_mode', 'upload');
+  if( $mode == 'upload' ){
+    $files = $node->files;
+  }elseif( $mode == 'imagefield' ){
+    $imagefield = variable_get('galleria_imagefield', '');
+    $files = $node->$imagefield;
+  }
   $images = array();
   $i = 0;
 
@@ -245,31 +269,32 @@ function template_preprocess_galleria(&$
   $thumb_preset = variable_get('galleria_thumb_imagecache_preset', '');
 
   foreach ($files as $file) {
-    $caption = $file->description != $file->filename ? $file->description : '';
+    $file = (array)$file;
+    $caption = $file['description'] != $file['filename'] ? $file['description'] : '';
     $url = $file->filepath;
 
     if ($imagecache_exists && $thumb_preset) {
-      $thumb = theme('imagecache', $thumb_preset, $file->filepath, $caption, $caption);
+      $thumb = theme('imagecache', $thumb_preset, $file['filepath'], $caption, $caption);
     }
 
     if ($imagecache_exists && $img_preset) {
       if ($thumb) {
         // Preset for both thumbnail and gallery image
-        $image = l($thumb, imagecache_create_url($img_preset, $file->filepath), array('html' => TRUE, 'attributes' => array('title' => $caption)));
+        $image = l($thumb, imagecache_create_url($img_preset, $file['filepath']), array('html' => TRUE, 'attributes' => array('title' => $caption)));
       }
       else {
         // Preset for only the gallery image
-        $image = theme('imagecache', $img_preset, $file->filepath, $caption, $caption);
+        $image = theme('imagecache', $img_preset, $file['filepath'], $caption, $caption);
       }
     }
     else {
       if ($thumb) {
         // Preset for only the thumbnail image
-        $image = l($thumb, $file->filepath, array('html' => TRUE, 'attributes' => array('title' => $caption)));
+        $image = l($thumb, $file['filepath'], array('html' => TRUE, 'attributes' => array('title' => $caption)));
       }
       else {
         // No presets selected
-        $image = theme('image', $file->filepath, $caption, $caption);
+        $image = theme('image', $file['filepath'], $caption, $caption);
       }
     }
 
