Index: node_gallery.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/node_gallery.inc,v
retrieving revision 1.2.2.95
diff -u -p -r1.2.2.95 node_gallery.inc
--- node_gallery.inc	22 Dec 2010 17:34:27 -0000	1.2.2.95
+++ node_gallery.inc	26 Dec 2010 11:25:42 -0000
@@ -897,7 +897,8 @@ function _node_gallery_create_new_galler
   $node = new stdClass;
   $node->type = $content_type;
   node_object_prepare($node);
-  $node->title = '';
+  $node->title = 'Unnamed Gallery';
+  $node->status = 0;
   $node->name = $user->name;
   node_save($node);
   return $node;
Index: node_gallery.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/node_gallery.module,v
retrieving revision 1.18.2.152
diff -u -p -r1.18.2.152 node_gallery.module
--- node_gallery.module	22 Dec 2010 17:34:27 -0000	1.18.2.152
+++ node_gallery.module	26 Dec 2010 11:41:25 -0000
@@ -205,6 +205,13 @@ function node_gallery_menu() {
     'weight' => -4,
     'type' => MENU_LOCAL_TASK,
   );
+  $items['node-gallery/json/gallery/create'] = array(
+    'page callback' => 'node_gallery_json_create_gallery',
+    'page arguments' => array(4),
+    'access callback' => TRUE,
+    'file' => 'node_gallery.pages.inc',
+    'type' => MENU_CALLBACK,
+  );
   $items['node-gallery/json/gallery/%node_gallery_gallery/sort'] = array(
     'page callback' => 'node_gallery_json_get_sorted_images',
     'page arguments' => array(3, 5, 6),
Index: node_gallery.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/node_gallery.pages.inc,v
retrieving revision 1.12.2.78
diff -u -p -r1.12.2.78 node_gallery.pages.inc
--- node_gallery.pages.inc	22 Dec 2010 17:34:27 -0000	1.12.2.78
+++ node_gallery.pages.inc	26 Dec 2010 10:55:31 -0000
@@ -8,10 +8,31 @@
  */
 
 function node_gallery_upload_image_to_new_gallery_form($image_type) {
+  drupal_set_message(t('Using this wizard, a gallery will be created automatically during upload. Please remember to enter a title and to publish the Gallery on the next screen.'));
   $relationship = node_gallery_get_relationship(NULL, $image_type);
-  $gallery = _node_gallery_create_new_gallery($relationship['gallery_type']);
-  $gallery->edit_after_plupload = TRUE;
-  return node_gallery_upload_image_form($gallery);
+  $gallery = array(
+    'nid' => -1,
+    'type' => $relationship['gallery_type'],
+    'edit_after_plupload' => TRUE,
+  );
+  return node_gallery_upload_image_form((object)$gallery);
+}
+
+/**
+ * Javascript page callback to create an empty gallery.
+ *
+ * @param String $gallery_type
+ *  The type of the gallery to create.
+ * @return
+ *  Json encoded newly created gallery.
+ */
+function node_gallery_json_create_gallery($gallery_type) {
+  $gallery = (object)array('type', $gallery_type);
+  if (!node_gallery_user_access('create', $gallery)) {
+    return FALSE;
+  }
+  $gallery = _node_gallery_create_new_gallery($gallery_type);
+  drupal_json($gallery);
 }
 
 /**
@@ -26,17 +47,19 @@ function node_gallery_upload_image_to_ne
 function node_gallery_upload_image_form($gallery) {
   global $user;
 
-  drupal_set_breadcrumb(array(
-    l(t('Home'), NULL),
-    l(t('Galleries'), 'galleries'),
-    l(t('!user\'s Galleries', array('!user' => $gallery->name)), 'galleries/' . $gallery->uid),
-    l($gallery->title, 'node/'. $gallery->nid)
+  if ($gallery->nid > 0) {
+    drupal_set_breadcrumb(array(
+      l(t('Home'), NULL),
+      l(t('Galleries'), 'galleries'),
+      l(t('!user\'s Galleries', array('!user' => $gallery->name)), 'galleries/' . $gallery->uid),
+      l($gallery->title, 'node/'. $gallery->nid)
     ));
+  }
   $relationship = node_gallery_get_relationship($gallery->type);
 
   if (module_exists('plupload') && variable_get('node_gallery_plupload_integration', TRUE)) {
     $filefield_name = $relationship['image_type'] .':::'. $relationship['imagefield_name'];
-    $options = array('drupal_pluploaded' => TRUE, 'drupal_gid' => $gallery->nid, 'drupal_plupload_import_field_type' => $filefield_name);
+    $options = array('drupal_pluploaded' => TRUE, 'drupal_gid' => $gallery->nid, 'drupal_plupload_import_field_type' => $filefield_name);    
     $output = '';
     if (!user_access('bulk upload files with plupload')) {
       drupal_set_message(t('You have permissions to view this tab, but not to upload images.  Please inform an administrator that you need the \'bulk upload files with plupload\' permission.'), 'warning');
@@ -44,7 +67,8 @@ function node_gallery_upload_image_form(
     else {
       if ($gallery->edit_after_plupload) {
         $settings = array(
-          'redirectTarget' => url('node/'. $gallery->nid .'/edit'),
+          'gid' => $gallery->nid,
+          'galleryType' => $gallery->type,
         );
         drupal_add_js(array('node_gallery' => $settings), 'setting');
         drupal_add_js(drupal_get_path('module', 'node_gallery') .'/js/ng_plupload.js');
Index: js/ng_plupload.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/js/Attic/ng_plupload.js,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 ng_plupload.js
--- js/ng_plupload.js	22 Dec 2010 15:27:51 -0000	1.1.2.1
+++ js/ng_plupload.js	26 Dec 2010 11:39:17 -0000
@@ -10,7 +10,17 @@
 Drupal.behaviors.nodeGalleryPlupload = function (context) {
   var self = this;
   this.context = context;
-  this.redirectTarget = Drupal.settings.node_gallery.redirectTarget;
+  this.gid = Drupal.settings.node_gallery.gid;
+  this.galleryType = Drupal.settings.node_gallery.galleryType;
+
+  var updateGallery = function (gallery) {
+    self.gid = gallery.nid;
+  }
+
+  var galleryCreationFailed = function () {
+    alert(Drupal.t("Failed to create gallery."));
+    self.uploader.stop();
+  }
 
   var init = function () {
     // check if upload instance is already there, else try again later.
@@ -21,7 +31,30 @@ Drupal.behaviors.nodeGalleryPlupload = f
     }
     self.uploader.bind('FileUploaded', function () {
       if (self.uploader.total.queued == 0) {
-        window.location.href = self.redirectTarget;
+        window.location.href = Drupal.settings.basePath + 'node/' + self.gid + '/edit';
+      }
+    });
+    self.uploader.bind('BeforeUpload', function () {
+      if (!self.gid || self.gid < 0) {
+        // create the gallery on the fly.
+        var url = Drupal.settings.basePath + 'node-gallery/json/gallery/create/' + self.galleryType;
+        // we use a synchronous call here, so plupload waits for us.
+        $.ajax({
+          url: url,
+          success: updateGallery,
+          error: galleryCreationFailed,
+          dataType: 'json',
+          async: false
+        });
+        if (!self.gid || self.gid < 0) {
+          var error = Drupal.t("Failed to create gallery.");
+          alert(error);
+          self.uploader.stop();
+          self.uploader.trigger('Error', {code: "102", message: error, id: self.uploader.id});          
+        } else {
+          // update plupload query string with correct gallery nid.
+          self.uploader.settings.url = self.uploader.settings.url.replace(/gid=-1/i, "gid=" + self.gid);
+        }
       }
     });
   }
