Index: trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java	(revision 2601)
+++ trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java	(revision 2602)
@@ -102,6 +102,7 @@
      * @param buttonIcons
      */
-    public void setButtonIcons(String[] buttonIcons) {
+    public ExtendedDialog setButtonIcons(String[] buttonIcons) {
         this.bIcons = buttonIcons;
+        return this;
     }
 
@@ -112,6 +113,7 @@
      * @param toolTipTexts the tool tip texts. Ignored, if null.
      */
-    public void setToolTipTexts(String[] toolTipTexts) {
+    public ExtendedDialog setToolTipTexts(String[] toolTipTexts) {
         this.bToolTipTexts = toolTipTexts;
+        return this;
     }
 
@@ -124,6 +126,6 @@
      * @param content Any element that can be displayed in the message dialog
      */
-    public void setContent(Component content) {
-        setContent(content, true);
+    public ExtendedDialog setContent(Component content) {
+        return setContent(content, true);
     }
 
@@ -138,7 +140,8 @@
      *
      */
-    public void setContent(Component content, boolean placeContentInScrollPane) {
+    public ExtendedDialog setContent(Component content, boolean placeContentInScrollPane) {
         this.content = content;
         this.placeContentInScrollPane = placeContentInScrollPane;
+        return this;
     }
 
@@ -152,6 +155,6 @@
      * @param message The text that should be shown to the user
      */
-    public void setContent(String message) {
-        setContent(string2label(message), false);
+    public ExtendedDialog setContent(String message) {
+        return setContent(string2label(message), false);
     }
 
@@ -160,9 +163,9 @@
      * for the dialog. You can retrieve the result using <code>getValue</code>
      */
-    public void showDialog() {
+    public ExtendedDialog showDialog() {
         // Check if the user has set the dialog to not be shown again
         if(toggleCheckState(togglePref)) {
             result = ExtendedDialog.DialogNotShown;
-            return;
+            return this;
         }
 
@@ -170,4 +173,5 @@
         setVisible(true);
         toggleSaveState();
+        return this;
     }
 
@@ -342,7 +346,8 @@
      *
      */
-    public void setRememberWindowGeometry(String pref, WindowGeometry wg) {
+    public ExtendedDialog setRememberWindowGeometry(String pref, WindowGeometry wg) {
         rememberSizePref = pref == null ? "" : pref;
         defaultWindowGeometry = wg;
+        return this;
     }
 
@@ -354,7 +359,8 @@
      * @param togglePref  The preference to save the checkbox state to
      */
-    public void toggleEnable(String togglePref) {
+    public ExtendedDialog toggleEnable(String togglePref) {
         this.toggleable = true;
         this.togglePref = togglePref;
+        return this;
     }
 
@@ -363,6 +369,7 @@
      * to be called for every dialog, as it's the default anyway.
      */
-    public void toggleDisable() {
+    public ExtendedDialog toggleDisable() {
         this.toggleable = false;
+        return this;
     }
 
@@ -373,6 +380,7 @@
      * @param text
      */
-    public void setToggleCheckboxText(String text) {
+    public ExtendedDialog setToggleCheckboxText(String text) {
         this.toggleCheckboxText = text;
+        return this;
     }
 
@@ -429,7 +437,8 @@
      * @param showHelpButton true, if the dialog displays a help button
      */
-    public void configureContextsensitiveHelp(String helpTopic, boolean showHelpButton) {
+    public ExtendedDialog configureContextsensitiveHelp(String helpTopic, boolean showHelpButton) {
         this.helpTopic = helpTopic;
         this.showHelpButton = showHelpButton;
+        return this;
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java	(revision 2601)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java	(revision 2602)
@@ -542,4 +542,7 @@
             if (!layerList.getCellBounds(index, index).contains(e.getPoint()))
                 return;
+            if (!layerList.isSelectedIndex(index)) {
+                layerList.setSelectedIndex(index);
+            }
             Layer layer = model.getLayer(index);
             LayerListPopup menu = new LayerListPopup(layerList, layer);
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 2601)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 2602)
@@ -68,5 +68,5 @@
      */
     protected boolean isCollapsed;
-
+    
     /** the preferred height if the toggle dialog is expanded */
     private int preferredHeight;
@@ -76,5 +76,5 @@
 
     /** the JDialog displaying the toggle dialog as undocked dialog */
-    private JDialog detachedDialog;
+    protected JDialog detachedDialog;
 
     /**
@@ -295,5 +295,5 @@
      *
      */
-    private class TitleBar extends JPanel {
+    protected class TitleBar extends JPanel {
         final private JLabel lblTitle;
         final private JComponent lblTitle_weak;
@@ -478,4 +478,5 @@
         isShowing = val;
         Main.pref.put(preferencePrefix+".visible", val);
+        stateChanged();
     }
 
@@ -483,4 +484,5 @@
         isDocked = val;
         Main.pref.put(preferencePrefix+".docked", val);
+        stateChanged();
     }
 
@@ -488,4 +490,5 @@
         isCollapsed = val;
         Main.pref.put(preferencePrefix+".minimized", val);
+        stateChanged();
     }
 
@@ -549,4 +552,10 @@
         return true;
     }
+    
+    /**
+     * primitive stateChangedListener for subclasses
+     */
+    protected void stateChanged() {
+    }
 
     /***
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java	(revision 2601)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java	(revision 2602)
@@ -133,5 +133,4 @@
             // To avoid issues when the user tries to zoom in on the image borders, this point is not calculated 
             // again if there was less than 1.5seconds since the last event.
-            System.out.println(e);
             if (e.getWhen() - lastTimeForMousePoint > 1500 || mousePointInImg == null) {
                 lastTimeForMousePoint = e.getWhen();
@@ -535,23 +534,33 @@
 
     private Rectangle calculateDrawImageRectangle(Rectangle visibleRect) {
-        Dimension size = getSize();
+        return calculateDrawImageRectangle(visibleRect, new Rectangle(0, 0, getSize().width, getSize().height));
+    }
+    
+    /**
+     * calculateDrawImageRectangle
+     *
+     * @param imgRect the part of the image that should be drawn (in image coordinates)
+     * @param compRect the part of the component where the image should be drawn (in component coordinates)
+     * @return the part of compRect with the same width/height ratio as the image
+     */
+    static Rectangle calculateDrawImageRectangle(Rectangle imgRect, Rectangle compRect) {
         int x, y, w, h;
         x = 0;
         y = 0;
-        w = size.width;
-        h = size.height;
-
-        int wFact = w * visibleRect.height;
-        int hFact = h * visibleRect.width;
+        w = compRect.width;
+        h = compRect.height;
+
+        int wFact = w * imgRect.height;
+        int hFact = h * imgRect.width;
         if (wFact != hFact) {
             if (wFact > hFact) {
-                w = hFact / visibleRect.height;
-                x = (size.width - w) / 2;
+                w = hFact / imgRect.height;
+                x = (compRect.width - w) / 2;
             } else {
-                h = wFact / visibleRect.width;
-                y = (size.height - h) / 2;
-            }
-        }
-        return new Rectangle(x, y, w, h);
+                h = wFact / imgRect.width;
+                y = (compRect.height - h) / 2;
+            }
+        }
+        return new Rectangle(x + compRect.x, y + compRect.y, w, h);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 2601)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 2602)
@@ -9,10 +9,14 @@
 
 import java.awt.BorderLayout;
+import java.awt.Component;
 import java.awt.Dimension;
-import java.awt.FlowLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
-
+import java.awt.event.WindowEvent;
+
+import javax.swing.Box;
 import javax.swing.AbstractAction;
 import javax.swing.ImageIcon;
@@ -23,5 +27,4 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.gui.SideButton;
 import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
 import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
@@ -37,4 +40,5 @@
     private static final String COMMAND_REMOVE = "remove";
     private static final String COMMAND_PREVIOUS = "previous";
+    private static final String COMMAND_COLLAPSE = "collapse";
 
     private ImageDisplay imgDisplay = new ImageDisplay();
@@ -43,4 +47,6 @@
     // Only one instance of that class
     static private ImageViewerDialog INSTANCE = null;
+
+    private boolean collapseButtonClicked = false;
 
     public static ImageViewerDialog getInstance() {
@@ -53,4 +59,5 @@
     private JButton btnNext;
     private JButton btnPrevious;
+    private JButton btnCollapse;
 
     private ImageViewerDialog() {
@@ -73,13 +80,9 @@
         content.add(imgDisplay, BorderLayout.CENTER);
 
-        JPanel buttons = new JPanel();
-        buttons.setLayout(new FlowLayout());
-
         Dimension buttonDim = new Dimension(26,26);
-        
+
         ImageAction prevAction = new ImageAction(COMMAND_PREVIOUS, ImageProvider.get("dialogs", "previous"), tr("Previous"));
         btnPrevious = new JButton(prevAction);
         btnPrevious.setPreferredSize(buttonDim);
-        buttons.add(btnPrevious);
         Shortcut scPrev = Shortcut.registerShortcut(
             "geoimage:previous", tr("Geoimage: {0}", tr("Show previous Image")), KeyEvent.VK_PAGE_UP, Shortcut.GROUP_DIRECT);
@@ -92,10 +95,8 @@
         JButton btnDelete = new JButton(new ImageAction(COMMAND_REMOVE, ImageProvider.get("dialogs", "delete"), tr("Remove photo from layer")));
         btnDelete.setPreferredSize(buttonDim);
-        buttons.add(btnDelete);
-      
+
         ImageAction nextAction = new ImageAction(COMMAND_NEXT, ImageProvider.get("dialogs", "next"), tr("Next"));
         btnNext = new JButton(nextAction);
         btnNext.setPreferredSize(buttonDim);
-        buttons.add(btnNext);
         Shortcut scNext = Shortcut.registerShortcut(
             "geoimage:next", tr("Geoimage: {0}", tr("Show next Image")), KeyEvent.VK_PAGE_DOWN, Shortcut.GROUP_DIRECT);
@@ -108,11 +109,37 @@
         JToggleButton tbCentre = new JToggleButton(new ImageAction(COMMAND_CENTERVIEW, ImageProvider.get("dialogs", "centreview"), tr("Center view")));
         tbCentre.setPreferredSize(buttonDim);
-        buttons.add(tbCentre);
-       
+
         JButton btnZoomBestFit = new JButton(new ImageAction(COMMAND_ZOOM, ImageProvider.get("dialogs", "zoom-best-fit"), tr("Zoom best fit and 1:1")));
         btnZoomBestFit.setPreferredSize(buttonDim);
+
+        btnCollapse = new JButton(new ImageAction(COMMAND_COLLAPSE, ImageProvider.get("dialogs", "collapse"), tr("Move dialog to the side pane")));
+        btnCollapse.setPreferredSize(new Dimension(20,20));
+        btnCollapse.setAlignmentY(Component.TOP_ALIGNMENT);
+
+        JPanel buttons = new JPanel();
+        buttons.add(btnPrevious);
+        buttons.add(btnNext);
+        buttons.add(Box.createRigidArea(new Dimension(14, 0)));
+        buttons.add(tbCentre);
         buttons.add(btnZoomBestFit);
-
-        content.add(buttons, BorderLayout.SOUTH);
+        buttons.add(Box.createRigidArea(new Dimension(14, 0)));
+        buttons.add(btnDelete);
+
+        JPanel bottomPane = new JPanel();
+        bottomPane.setLayout(new GridBagLayout());
+        GridBagConstraints gc = new GridBagConstraints();
+        gc.gridx = 0;
+        gc.gridy = 0;
+        gc.anchor = GridBagConstraints.CENTER;
+        gc.weightx = 1;
+        bottomPane.add(buttons, gc);
+
+        gc.gridx = 1;
+        gc.gridy = 0;
+        gc.anchor = GridBagConstraints.PAGE_END;
+        gc.weightx = 0;
+        bottomPane.add(btnCollapse, gc);
+
+        content.add(bottomPane, BorderLayout.SOUTH);
 
         add(content, BorderLayout.CENTER);
@@ -150,4 +177,7 @@
                    currentLayer.removeCurrentPhoto();
                 }
+            } else if (COMMAND_COLLAPSE.equals(action)) {
+                collapseButtonClicked = true;
+                detachedDialog.getToolkit().getSystemEventQueue().postEvent(new WindowEvent(detachedDialog, WindowEvent.WINDOW_CLOSING));
             }
         }
@@ -186,4 +216,5 @@
         if (entry != null) {
             imgDisplay.setImage(entry.file);
+            titleBar.setTitle("Geotagged Images" + (entry.file != null ? " - " + entry.file.getName() : ""));
             StringBuffer osd = new StringBuffer(entry.file != null ? entry.file.getName() : "");
             if (entry.elevation != null) {
@@ -227,5 +258,17 @@
     @Override
     protected boolean dockWhenClosingDetachedDlg() {
+        if (collapseButtonClicked) {
+            collapseButtonClicked = false;
+            return true;
+        }
         return false;
+    }
+
+    @Override
+    protected void stateChanged() {
+        super.stateChanged();
+        if (btnCollapse != null) {
+            btnCollapse.setVisible(!isDocked);
+        }
     }
 
