Index: richtext/frontend/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.java
===================================================================
--- richtext/frontend/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.java	(revision 39264)
+++ richtext/frontend/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.java	(working copy)
@@ -34,9 +34,9 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.wicket.Component;
 import org.apache.wicket.RequestCycle;
 import org.apache.wicket.ResourceReference;
-import org.apache.wicket.Session;
 import org.apache.wicket.ajax.AjaxEventBehavior;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
@@ -44,17 +44,21 @@
 import org.apache.wicket.behavior.AttributeAppender;
 import org.apache.wicket.markup.html.IHeaderContributor;
 import org.apache.wicket.markup.html.IHeaderResponse;
+import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.form.DropDownChoice;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.IChoiceRenderer;
 import org.apache.wicket.markup.html.form.upload.FileUpload;
 import org.apache.wicket.markup.html.form.upload.FileUploadField;
 import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
 import org.apache.wicket.model.Model;
+import org.apache.wicket.model.PropertyModel;
 import org.apache.wicket.model.StringResourceModel;
 import org.apache.wicket.protocol.http.WebRequestCycle;
 import org.apache.wicket.util.value.IValueMap;
 import org.apache.wicket.util.value.ValueMap;
+import org.hippoecm.frontend.i18n.types.TypeChoiceRenderer;
 import org.hippoecm.frontend.i18n.types.TypeTranslator;
 import org.hippoecm.frontend.model.nodetypes.JcrNodeTypeModel;
 import org.hippoecm.frontend.plugin.IPluginContext;
@@ -88,16 +92,32 @@
 
     public final static List<String> ALIGN_OPTIONS = Arrays.asList("top", "middle", "bottom", "left", "right");
     private static final String CONFIG_KEY_PREFERRED_RESOURCE_NAMES = "preferred.resource.names";
+    private static final String GALLERY_TYPE_SELECTOR_ID = "galleryType";
 
     DropDownChoice<String> type;
 
     private LinkedHashMap<String, String> nameTypeMap;
 
     private IModel<XinhaImage> imageModel;
+    private boolean uploadSelected;
+    private AjaxButton uploadButton;
+    private Component uploadTypeSelector;
+    private final LoadableDetachableModel<List<String>> galleryTypesModel;
+    private String galleryType;
 
     public ImageBrowserDialog(IPluginContext context, final IPluginConfig config, final IModel<XinhaImage> model) {
         super(context, config, model);
         imageModel = model;
+
+        galleryTypesModel = new LoadableDetachableModel<List<String>>() {
+            @Override
+            protected List<String> load() {
+                return loadGalleryTypes();
+            }
+        };
+
+        add(createUploadForm());
+
         if (nameTypeMap == null) {
             nameTypeMap = new  LinkedHashMap<String, String>();
         }
@@ -125,8 +145,6 @@
         type.setNullValid(false);
         add(type);
 
-        createUploadForm(config);
-
         add(new ThrottledTextFieldWidget("alt", new StringPropertyModel(model, XinhaImage.ALT)) {
             private static final long serialVersionUID = 1L;
 
@@ -178,6 +196,29 @@
         }
     }
 
+    /**
+     * This is the callback to enable/disable the OK button of the image browser dialog.
+     * We abuse it here as a signal that a new folder may have been selected. If so, the
+     * drop-down menu for selecting the target gallery type for uploaded images may need to
+     * be adjusted.
+     *
+     * @param isset pass-through parameter
+     */
+    @Override
+    protected void setOkEnabled(boolean isset) {
+        super.setOkEnabled(isset);
+
+        // function is called by parent constructor, when our constructor hasn't run yet...
+        if (uploadTypeSelector != null && uploadButton != null) {
+
+            AjaxRequestTarget target = AjaxRequestTarget.get();
+            if (target != null) {
+                target.addComponent(uploadTypeSelector);
+                target.addComponent(uploadButton);
+            }
+        }
+    }
+
     private void setPreferredTypeChoice() {
         IPluginConfig config = getPluginConfig();
         if (config.containsKey(CONFIG_KEY_PREFERRED_RESOURCE_NAMES)) {
@@ -238,17 +279,30 @@
     }
 
     @SuppressWarnings("unchecked")
-    private void createUploadForm(final IPluginConfig config) {
+    private Component createUploadForm() {
         Form<?> uploadForm = new Form("uploadForm");
 
         uploadForm.setOutputMarkupId(true);
         final FileUploadField uploadField = new FileUploadField("uploadField");
         uploadField.setOutputMarkupId(true);
 
-        final AjaxButton uploadButton = new AjaxButton("uploadButton", uploadForm) {
+        // we use a container to enable Ajax-based (in)visibility while not meddling with the selected upload file.
+        uploadTypeSelector = new WebMarkupContainer("uploadTypeSelector").add(createTypeSelector());
+        uploadTypeSelector.setOutputMarkupId(true);
+
+        uploadButton = new AjaxButton("uploadButton", uploadForm) {
             private static final long serialVersionUID = 1L;
 
             @Override
+            public boolean isEnabled() {
+                if (uploadSelected) {
+                    List<String> galleryTypes = galleryTypesModel.getObject();
+                    return galleryTypes.size() > 0; // disable upload if the current folder has no gallery types at all
+                }
+                return false;
+            }
+
+            @Override
             protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
 
                 final FileUpload upload = uploadField.getFileUpload();
@@ -267,12 +321,11 @@
                             Node folderNode = getFolderModel().getObject();
 
                             //TODO replace shortcuts with custom workflow category(?)
-                            GalleryWorkflow workflow = (GalleryWorkflow) manager.getWorkflow("shortcuts", folderNode);
+                            GalleryWorkflow workflow = (GalleryWorkflow) manager.getWorkflow("gallery", folderNode);
                             String nodeName = getNodeNameCodec().encode(filename);
                             String localName = getLocalizeCodec().encode(filename);
-                            List<String> galleryTypes = workflow.getGalleryTypes();
-                            Document document = workflow.createGalleryItem(nodeName, galleryTypes.get(0));
-                            node = (HippoNode) UserSession.get().getJcrSession().getNodeByUUID(document.getIdentity());
+                            Document document = workflow.createGalleryItem(nodeName, getGalleryType());
+                            node = (HippoNode) UserSession.get().getJcrSession().getNodeByIdentifier(document.getIdentity());
                             DefaultWorkflow defaultWorkflow = (DefaultWorkflow) manager.getWorkflow("core", node);
                             if (!node.getLocalizedName().equals(localName)) {
                                 defaultWorkflow.localizeName(localName);
@@ -326,30 +379,32 @@
             }
         };
 
+        uploadSelected = false;
+
         uploadButton.setOutputMarkupId(true);
         uploadField.add(new AjaxEventBehavior("onchange") {
             private static final long serialVersionUID = 1L;
 
             @Override
             protected void onEvent(AjaxRequestTarget target) {
-                uploadButton.setEnabled(true);
+                uploadSelected = true;
                 target.addComponent(uploadButton);
             }
         });
-        uploadButton.setEnabled(false);
         uploadForm.add(uploadField);
+        uploadForm.add(uploadTypeSelector);
         uploadForm.add(uploadButton);
 
-        add(uploadForm);
-
         //OMG: ugly workaround.. Input[type=file] is rendered differently on OSX in all browsers..
         WebRequestCycle requestCycle = (WebRequestCycle) RequestCycle.get();
         HttpServletRequest httpServletReq = requestCycle.getWebRequest().getHttpServletRequest();
         String ua = httpServletReq.getHeader("User-Agent");
-        if (ua.indexOf("Macintosh") > -1) {
+        if (ua.contains("Macintosh")) {
             uploadField.add(new AttributeAppender("class", true, new Model<String>("browse-button-osx"), " "));
             uploadButton.add(new AttributeAppender("class", true, new Model<String>("upload-button-osx"), " "));
         }
+
+        return uploadForm;
     }
 
     @Override
@@ -409,4 +464,60 @@
         StringCodecFactory stringCodecFactory = settingsService.getStringCodecFactory();
         return stringCodecFactory.getStringCodec("encoding.display");
     }
+
+    private String getGalleryType() {
+        List<String> galleryTypes = galleryTypesModel.getObject();
+
+        if (galleryType == null || galleryTypes.indexOf(galleryType) < 0) {
+            if (galleryTypes.size() > 0) {
+                galleryType = galleryTypes.get(0);
+            }
+        }
+        return galleryType;
+    }
+
+    /**
+     * Create the galleryTypeSelector, only shown in the UI if there actually is something to choose from.
+     * Send changes to the backend using Ajax, in order to remember old choices while navigating through the
+     * gallery.
+     *
+     * @return the type selector component
+     */
+    @SuppressWarnings("unchecked")
+    private Component createTypeSelector() {
+        getGalleryType(); // initialize the galleryType value
+        return new DropDownChoice<String>(GALLERY_TYPE_SELECTOR_ID, new PropertyModel(this, "galleryType"),
+                galleryTypesModel, new TypeChoiceRenderer(this)) {
+            @Override
+            public boolean isVisible() {
+                return getChoices().size() > 1;
+            }
+        }
+        .setNullValid(false)
+        .add(new AjaxFormComponentUpdatingBehavior("onchange") {
+            @Override
+            protected void onUpdate(AjaxRequestTarget target) {
+                // required because abstract, but all we need is to have galleryType set, which happens underwater.
+            }
+        });
+    }
+
+    /**
+     * Load gallery types from repo-based configuration (target folder)
+     * @return list of supported type names for the current folder.
+     */
+    private List<String> loadGalleryTypes() {
+        List<String> types = new ArrayList<String>();
+        WorkflowManager manager = UserSession.get().getWorkflowManager();
+
+        try {
+            Node folderNode = getFolderModel().getObject();
+            GalleryWorkflow workflow = (GalleryWorkflow) manager.getWorkflow("gallery", folderNode);
+            types = workflow.getGalleryTypes();
+        } catch (Exception e) {
+            log.error("Failed to load gallery types", e);
+        }
+
+        return types;
+    }
 }
Index: richtext/frontend/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.html
===================================================================
--- richtext/frontend/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.html	(revision 39264)
+++ richtext/frontend/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.html	(working copy)
@@ -22,6 +22,7 @@
                     <wicket:message key="select-file-label"/>
                 </label>
                 <input wicket:id="uploadField" size="60" id="upload" type="file" class="browse-button"/>
+                <span wicket:id="uploadTypeSelector"><select wicket:id="galleryType">[ ImageSet dropdown ]</select></span>
                 <input wicket:id="uploadButton" type="submit" value="Upload" class="upload-button"/>
             </div>
         </form>
