Index: trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 2575)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 2577)
@@ -46,26 +46,26 @@
 public class ToggleDialog extends JPanel implements Helpful {
     /** The action to toggle this dialog */
-    private ToggleDialogAction toggleAction;
-    private String preferencePrefix;
+    protected ToggleDialogAction toggleAction;
+    protected String preferencePrefix;
 
     /** DialogsPanel that manages all ToggleDialogs */
-    private DialogsPanel dialogsPanel;
-
-    private TitleBar titleBar;
+    protected DialogsPanel dialogsPanel;
+
+    protected TitleBar titleBar;
 
     /**
      * Indicates whether the dialog is showing or not.
      */
-    private boolean isShowing;
+    protected boolean isShowing;
     /**
      * If isShowing is true, indicates whether the dialog is docked or not, e. g.
      * shown as part of the main window or as a seperate dialog window.
      */
-    private boolean isDocked;
+    protected boolean isDocked;
     /**
      * If isShowing and isDocked are true, indicates whether the dialog is
      * currently minimized or not.
      */
-    boolean isCollapsed;
+    protected boolean isCollapsed;
 
     /** the preferred height if the toggle dialog is expanded */
@@ -139,4 +139,5 @@
 
         public void actionPerformed(ActionEvent e) {
+            toggleButtonHook();
             if (isShowing) {
                 hideDialog();
@@ -204,4 +205,5 @@
         detachedDialog = new DetachedDialog();
         detachedDialog.setVisible(true);
+        setIsShowing(true);
         setIsDocked(false);
     }
@@ -213,4 +215,5 @@
     public void collapse() {
 //        if (isShowing && isDocked && !isCollapsed) {
+        if (isDialogInDefaultView()) {
             setContentVisible(false);
             setIsCollapsed(true);
@@ -220,6 +223,6 @@
             lblMinimized.setIcon(ImageProvider.get("misc", "minimized"));
             hideNotify();
-//        }
-//        else throw ...
+        }
+        else throw new IllegalStateException();
     }
 
@@ -229,4 +232,5 @@
     protected void expand() {
 //        if (isShowing && isDocked && isCollapsed) {
+        if (isDialogInCollapsedView()) {
             setContentVisible(true);
             setIsCollapsed(false);
@@ -235,6 +239,6 @@
             lblMinimized.setIcon(ImageProvider.get("misc", "normal"));
             showNotify();
-//        }
-//        else throw ...
+        }
+        else throw new IllegalStateException();
     }
 
@@ -392,7 +396,13 @@
                     getContentPane().removeAll();
                     dispose();
-                    dock();
-                    expand();
-                    dialogsPanel.reconstruct(Action.INVISIBLE_TO_DEFAULT, ToggleDialog.this);
+                    if (dockWhenClosingDetachedDlg()) {
+                        dock();
+                        if (isDialogInCollapsedView()) {
+                            expand();
+                        }
+                        dialogsPanel.reconstruct(Action.INVISIBLE_TO_DEFAULT, ToggleDialog.this);
+                    } else {
+                        hideDialog();
+                    }
                 }
             });
@@ -426,20 +436,4 @@
 
     /**
-     * Change the Geometry of the detached dialog to better fit the content.
-     * Overrride this to make it useful.
-     */
-    protected Rectangle getDetachedGeometry(Rectangle last) {
-        return last;
-    }
-
-    /**
-     * Default size of the detached dialog.
-     * Override this method to customize the initial dialog size.
-     */
-    protected Dimension getDefaultDetachedSize() {
-        return new Dimension(Main.map.DEF_TOGGLE_DLG_WIDTH, preferredHeight);
-    }
-
-    /**
      * Replies the action to toggle the visible state of this toggle dialog
      *
@@ -481,15 +475,15 @@
     }
 
-    private void setIsShowing(boolean val) {
+    protected void setIsShowing(boolean val) {
         isShowing = val;
         Main.pref.put(preferencePrefix+".visible", val);
     }
 
-    private void setIsDocked(boolean val) {
+    protected void setIsDocked(boolean val) {
         isDocked = val;
         Main.pref.put(preferencePrefix+".docked", val);
     }
 
-    private void setIsCollapsed(boolean val) {
+    protected void setIsCollapsed(boolean val) {
         isCollapsed = val;
         Main.pref.put(preferencePrefix+".minimized", val);
@@ -498,25 +492,4 @@
     public int getPreferredHeight() {
         return preferredHeight;
-    }
-
-    /**
-     * Replies true if this dialog is showing either as docked or as detached dialog
-     */
-    public boolean isDialogShowing() {
-        return isShowing;
-    }
-
-    /**
-     * Replies true if this dialog is docked and expanded
-     */
-    public boolean isDialogInDefaultView() {
-        return isShowing && isDocked && (! isCollapsed);
-    }
-
-    /**
-     * Replies true if this dialog is docked and collapsed
-     */
-    public boolean isDialogInCollapsedView() {
-        return isShowing && isDocked && isCollapsed;
     }
 
@@ -526,3 +499,57 @@
         return "Dialog/"+help;
     }
+    /**
+     * Replies true if this dialog is showing either as docked or as detached dialog
+     */
+    public boolean isDialogShowing() {
+        return isShowing;
+    }
+
+    /**
+     * Replies true if this dialog is docked and expanded
+     */
+    public boolean isDialogInDefaultView() {
+        return isShowing && isDocked && (! isCollapsed);
+    }
+
+    /**
+     * Replies true if this dialog is docked and collapsed
+     */
+    public boolean isDialogInCollapsedView() {
+        return isShowing && isDocked && isCollapsed;
+    }
+
+    /***
+     * The following methods are intended to be overridden, in order to customize
+     * the toggle dialog behavior.
+     **/
+
+    /**
+    * Change the Geometry of the detached dialog to better fit the content.
+    */
+    protected Rectangle getDetachedGeometry(Rectangle last) {
+        return last;
+    }
+
+    /**
+     * Default size of the detached dialog.
+     * Override this method to customize the initial dialog size.
+     */
+    protected Dimension getDefaultDetachedSize() {
+        return new Dimension(dialogsPanel.getWidth(), preferredHeight);
+    }
+
+    /**
+     * Do something when the toggleButton is pressed.
+     */
+    protected void toggleButtonHook() {
+    }
+
+    protected boolean dockWhenClosingDetachedDlg() {
+        return true;
+    }
+
+    /***
+     * End of override hooks
+     **/
 }
Index: trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 2575)
+++ trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 2577)
@@ -322,5 +322,5 @@
                     return;
                 }
-                JFileChooser fc = new JFileChooser(Main.pref.get("tagimages.lastdirectory"));
+                JFileChooser fc = new JFileChooser(Main.pref.get("tagimages.lastdirectory", Main.pref.get("lastDirectory")));
                 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                 fc.setMultiSelectionEnabled(true);
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 2575)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 2577)
@@ -21,4 +21,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
+import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.ImageEntry;
 import org.openstreetmap.josm.tools.ImageProvider;
@@ -45,5 +46,5 @@
         return INSTANCE;
     }
-    
+
     private JButton btnNext;
     private JButton btnPrevious;
@@ -52,4 +53,9 @@
         super(tr("Geotagged Images"), "geoimage", tr("Display geotagged images"), Shortcut.registerShortcut("tools:geotagged", tr("Tool: {0}", tr("Display geotagged images")), KeyEvent.VK_Y, Shortcut.GROUP_EDIT), 200);
 
+        /* Don't show a detached dialog right from the start. */
+        if (isShowing && !isDocked) {
+            setIsShowing(false);
+        }
+
         if (INSTANCE != null) {
             throw new IllegalStateException("Image viewer dialog should not be instanciated twice !");
@@ -57,5 +63,5 @@
 
         INSTANCE = this;
-        
+
         JPanel content = new JPanel();
         content.setLayout(new BorderLayout());
@@ -188,6 +194,36 @@
             imgDisplay.setOsdText("");
         }
-    }
-    
+        if (! isDialogShowing()) {
+            setIsDocked(false);     // always open a detached window when an image is clicked and dialog is closed
+            showDialog();
+        } else {
+            if (isDocked && isCollapsed) {
+                expand();
+                dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, this);
+            }
+        }
+
+    }
+
+    /**
+     * When pressing the Toggle button always show the docked dialog.
+     */
+    @Override
+    protected void toggleButtonHook() {
+        if (! isShowing) {
+            setIsDocked(true);
+            setIsCollapsed(false);
+        }
+    }
+
+    /**
+     * When an image is closed, really close it and do not pop
+     * up the side dialog.
+     */
+    @Override
+    protected boolean dockWhenClosingDetachedDlg() {
+        return false;
+    }
+
     /**
      * Returns whether an image is currently displayed
