Index: image_attach_browse/image_attach_browse.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image_attach_browse/image_attach_browse.js,v
retrieving revision 1.3
diff -u -p -r1.3 image_attach_browse.js
--- image_attach_browse/image_attach_browse.js	4 Mar 2010 21:05:54 -0000	1.3
+++ image_attach_browse/image_attach_browse.js	5 Mar 2010 18:05:26 -0000
@@ -12,31 +12,39 @@ function myImageBrowserLoad(hash) {
     var checkbox = $('input', this);
     checkbox.attr('checked', !checkbox.attr('checked'));
     imageAttachBrowserChoice(checkbox.val(), checkbox.attr('checked'));
+    return false;
   });
 
   $(Drupal.settings.phImageBrowser + ' #image-browser-cancel').bind('click', function() {
     $(Drupal.settings.phImageBrowser).jqmHide();
-    $('#edit-iids-wrapper').slideDown();
+    $(Drupal.settings.imageAttachSelectWrapper).slideDown();
     return false;
   });
   
   $(Drupal.settings.phImageBrowser + ' input[type="submit"]').bind('click', function() { 
-    if (!!$(Drupal.settings.imageBrowserChoices)) {
-      $(Drupal.settings.imageBrowserChoices).each(function(key, value) {
-        $('#edit-iids option[value="' + value + '"]').attr('selected', 'selected');
+    $(Drupal.settings.imageAttachSelect + ' option').attr('selected', '');
+    if (!!Drupal.settings.imageBrowserChoices && Drupal.settings.imageBrowserChoices.length) {
+      jQuery.each(Drupal.settings.imageBrowserChoices, function(key, value) {
+        if (value == 0) {
+          return; // continue;
+        }
+        $(Drupal.settings.imageAttachSelect + ' option[value="' + value + '"]').attr('selected', 'selected');
       });
     }
     $(Drupal.settings.phImageBrowser).jqmHide();
-    $('#edit-iids-wrapper').slideDown();
+    $(Drupal.settings.imageAttachSelectWrapper).slideDown();
     return false;
   });
 }
 
 function imageAttachBrowserChoice(value, onoff) {
   if (onoff) {
-    Drupal.settings.imageBrowserChoices[value] = value;
+    Drupal.settings.imageBrowserChoices.push(value);
   } else {
-    Drupal.settings.imageBrowserChoices[value] = null;
+    var i = Drupal.settings.imageBrowserChoices.indexOf(value);
+    if (i >= 0) {
+      Drupal.settings.imageBrowserChoices[i] = 0;
+    }
   }
 }
 
@@ -47,27 +55,48 @@ function initImageBrowser() {
     ajax: '@href',
     onLoad:myImageBrowserLoad
   });
-  if (!Drupal.settings.imageBrowserChoices) {
+
+  // Check the checkboxes that correspond to selected options
+  if (!!$(Drupal.settings.imageAttachSelect).val() && $(Drupal.settings.imageAttachSelect).val().length) {
     Drupal.settings.imageBrowserChoices = new Array();
+    jQuery.each($(Drupal.settings.imageAttachSelect).val(), function(key, value) {
+      if(value == 0) {
+        // If "None" is selected, deselect everything and break
+        $(Drupal.settings.phImageBrowser + ' a.image-browser-choice input').attr('checked', '');
+        return false;
+      }
+      if(!!$(Drupal.settings.phImageBrowser + ' a.image-browser-choice input[value="' + value + '"]')) {
+        $(Drupal.settings.phImageBrowser + ' a.image-browser-choice input[value="' + value + '"]').attr('checked', 'checked');
+        Drupal.settings.imageBrowserChoices.push(value);
+      }
+    });
   }
-  $(Drupal.settings.imageBrowserChoices).each(function(key, value) {
-    if (value && !!$(Drupal.settings.phImageBrowser + ' a.image-browser-choice input[value="' + value + '"]')) {
-      $(Drupal.settings.phImageBrowser + ' a.image-browser-choice input[value="' + value + '"]').attr('checked', true);
-    }
-  });
-
-  jQuery.each($('#edit-iids').val(), function(key, value) {
-    console.log(key);
-    console.log(value);
-    if(!!$(Drupal.settings.phImageBrowser + ' a.image-browser-choice input[value="' + value + '"]')) {
-      Drupal.settings.imageBrowserChoices[$(this).val()] = $(this).val();
-      $(Drupal.settings.phImageBrowser + ' a.image-browser-choice input[value="' + value + '"]').attr('checked', 'checked');
-    }
-  });
 }
 
 Drupal.behaviors.image_attach_browse = function() {
-  $('body').prepend($(Drupal.settings.phImageBrowser));
-  $(Drupal.settings.phImageBrowser).html(Drupal.settings.waiting);
-  initImageBrowser();
+  if ($(Drupal.settings.imageAttachSelect + ' option').length > 1) {
+    $('body').prepend($(Drupal.settings.phImageBrowser));
+    $(Drupal.settings.phImageBrowser).html(Drupal.settings.waiting);
+    initImageBrowser();
+    Drupal.settings.imageBrowserChoices = new Array();
+    if ($(Drupal.settings.imageAttachSelect + ' option:selected').length) {
+      $(Drupal.settings.imageAttachSelect + ' option:selected').each(function() {
+        if ($(this).val() == 0) {
+          return false;
+        }
+        Drupal.settings.imageBrowserChoices.push($(this).val());
+      });
+    }
+    $(Drupal.settings.imageAttachSelect).bind('change', function() {
+      Drupal.settings.imageBrowserChoices = new Array();
+      if (!!$(this).val() && $(this).val().length) {
+        jQuery.each($(this).val(), function(key, value) {
+          Drupal.settings.imageBrowserChoices.push(value);
+        });
+      }
+    });
+  } else {
+    // Remove the browse button if there are no images uploaded yet!
+    $(Drupal.settings.imageBrowserTrigger).remove();
+  }
 }
Index: image_attach_browse/image_attach_browse.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image_attach_browse/image_attach_browse.module,v
retrieving revision 1.8
diff -u -p -r1.8 image_attach_browse.module
--- image_attach_browse/image_attach_browse.module	5 Mar 2010 14:38:36 -0000	1.8
+++ image_attach_browse/image_attach_browse.module	5 Mar 2010 18:05:26 -0000
@@ -151,7 +151,7 @@ function image_attach_browse_browser() {
       echo theme('image_attach_browse_browser', $rows) 
         . '<div id="' . PH_IMAGE_BROWSER_DOM_ID . 'Pager">' . theme('pager') . '</div>';
     } else {
-      echo t('No attached images found.');
+      echo '<div class="nonmodal">' . t('No attached images found.') . '</div>';
     }
   }
 }
@@ -188,7 +188,9 @@ function theme_image_attach_browse_attac
   drupal_add_css(drupal_get_path('module', 'image_attach_browse') . '/image_attach_browse.css');
   drupal_add_js(array(
     'phImageBrowser' => '#'.PH_IMAGE_BROWSER_DOM_ID,
-    'imageBrowserTrigger' => '#edit-iids-wrapper div.description a'
+    'imageBrowserTrigger' => '#' . $element['iids']['#id'] . '-wrapper div.description a',
+    'imageAttachSelect' => '#' . $element['iids']['#id'],
+    'imageAttachSelectWrapper' => '#' . $element['iids']['#id'] . '-wrapper',
     ), 'setting');
 
   $element['iids']['#description'] .= ' ' . $element['browse']['#value'];
