Index: applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryPreferenceEditor.java
===================================================================
--- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryPreferenceEditor.java	(revision 24520)
+++ applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryPreferenceEditor.java	(revision 24521)
@@ -7,4 +7,5 @@
 import java.awt.Dimension;
 import java.awt.FlowLayout;
+import java.awt.Font;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
@@ -27,4 +28,6 @@
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
+import javax.swing.JSlider;
 import javax.swing.JSpinner;
 import javax.swing.JTabbedPane;
@@ -37,4 +40,5 @@
 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
+import org.openstreetmap.josm.plugins.imagery.tms.TMSPreferences;
 import org.openstreetmap.josm.plugins.imagery.wms.AddWMSLayerPanel;
 import org.openstreetmap.josm.plugins.imagery.wms.WMSAdapter;
@@ -54,5 +58,13 @@
     ImageryPlugin plugin = ImageryPlugin.instance;
 
-    public JPanel buildImageryProvidersPanel(final PreferenceTabbedPane gui) {
+    //TMS settings controls
+    private JCheckBox autozoomActive = new JCheckBox();
+    private JCheckBox autoloadTiles = new JCheckBox();
+    private JSpinner maxZoomLvl;
+    private JSpinner minZoomLvl = new JSpinner();
+    private JSlider fadeBackground = new JSlider(0, 100);
+
+
+    private JPanel buildImageryProvidersPanel(final PreferenceTabbedPane gui) {
         final JPanel p = new JPanel(new GridBagLayout());
         model = new ImageryLayerTableModel();
@@ -173,8 +185,6 @@
     }
 
-    public Component buildSettingsPanel() {
-        final JPanel p = new JPanel(new GridBagLayout());
-        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
-
+    private JPanel buildWMSSettingsPanel() {
+        final JPanel pnlW = new JPanel(new GridBagLayout());
         browser = new JComboBox(new String[] {
                 "webkit-image {0}",
@@ -184,9 +194,9 @@
         browser.setEditable(true);
         browser.setSelectedItem(Main.pref.get("wmsplugin.browser", "webkit-image {0}"));
-        p.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GBC.HORIZONTAL));
-        p.add(browser);
+        pnlW.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GBC.HORIZONTAL));
+        pnlW.add(browser);
 
         // Overlap
-        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
+        pnlW.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
 
         overlapCheckBox = new JCheckBox(tr("Overlap tiles"), wmsAdapter.PROP_OVERLAP.get());
@@ -203,21 +213,75 @@
         overlapPanel.add(spinNorth);
 
-        p.add(overlapPanel);
+        pnlW.add(overlapPanel);
 
         // Simultaneous connections
-        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
+        pnlW.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
         JLabel labelSimConn = new JLabel(tr("Simultaneous connections"));
         spinSimConn = new JSpinner(new SpinnerNumberModel(wmsAdapter.PROP_SIMULTANEOUS_CONNECTIONS.get(), 1, 30, 1));
-        JPanel overlapPanelSimConn = new JPanel(new FlowLayout());
+        JPanel overlapPanelSimConn = new JPanel(new FlowLayout(FlowLayout.LEFT));
         overlapPanelSimConn.add(labelSimConn);
         overlapPanelSimConn.add(spinSimConn);
-        p.add(overlapPanelSimConn, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.NORTHWEST));
+        pnlW.add(overlapPanelSimConn, GBC.eol().fill(GBC.HORIZONTAL));
 
         allowRemoteControl = Main.pref.getBoolean("wmsplugin.remotecontrol", true);
         remoteCheckBox = new JCheckBox(tr("Allow remote control (reqires remotecontrol plugin)"), allowRemoteControl);
-        JPanel remotePanel = new JPanel(new FlowLayout());
+        JPanel remotePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
         remotePanel.add(remoteCheckBox);
 
-        p.add(remotePanel,GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.NORTHWEST));
+        pnlW.add(remotePanel,GBC.eol().fill(GBC.HORIZONTAL));
+        return pnlW;
+    }
+
+    private JPanel buildTMSSettingsPanel() {
+        JPanel tmsTab = new JPanel(new GridBagLayout());
+        minZoomLvl = new JSpinner(new SpinnerNumberModel(TMSPreferences.DEFAULT_MIN_ZOOM, TMSPreferences.MIN_ZOOM, TMSPreferences.MAX_ZOOM, 1));
+        maxZoomLvl = new JSpinner(new SpinnerNumberModel(TMSPreferences.DEFAULT_MAX_ZOOM, TMSPreferences.MIN_ZOOM, TMSPreferences.MAX_ZOOM, 1));
+
+        tmsTab.add(new JLabel(tr("Auto zoom by default: ")), GBC.std());
+        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
+        tmsTab.add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL));
+
+        tmsTab.add(new JLabel(tr("Autoload tiles by default: ")), GBC.std());
+        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
+        tmsTab.add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL));
+
+        tmsTab.add(new JLabel(tr("Min zoom lvl: ")), GBC.std());
+        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
+        tmsTab.add(this.minZoomLvl, GBC.eol().fill(GBC.HORIZONTAL));
+
+        tmsTab.add(new JLabel(tr("Max zoom lvl: ")), GBC.std());
+        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
+        tmsTab.add(this.maxZoomLvl, GBC.eol().fill(GBC.HORIZONTAL));
+
+        tmsTab.add(new JLabel(tr("Fade background: ")), GBC.std());
+        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
+        tmsTab.add(this.fadeBackground, GBC.eol().fill(GBC.HORIZONTAL));
+
+        tmsTab.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
+
+        this.autozoomActive.setSelected(TMSPreferences.PROP_DEFAULT_AUTOZOOM.get());
+        this.autoloadTiles.setSelected(TMSPreferences.PROP_DEFAULT_AUTOLOAD.get());
+        this.maxZoomLvl.setValue(TMSPreferences.getMaxZoomLvl(null));
+        this.minZoomLvl.setValue(TMSPreferences.getMinZoomLvl(null));
+        this.fadeBackground.setValue(TMSPreferences.PROP_FADE_BACKGROUND.get());
+        return tmsTab;
+    }
+
+    private Component buildSettingsPanel() {
+        // TODO: make some settings common for WMS and TMS
+        final JPanel p = new JPanel(new GridBagLayout());
+        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+
+        final JLabel lblW = new JLabel(tr("WMS Settings"));
+        lblW.setFont(lblW.getFont().deriveFont(Font.BOLD));
+        p.add(lblW);
+        p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0));
+        p.add(buildWMSSettingsPanel(),GBC.eol().insets(20,5,0,0));
+
+        final JLabel lblT = new JLabel(tr("TMS Settings"));
+        lblT.setFont(lblT.getFont().deriveFont(Font.BOLD));
+        p.add(lblT);
+        p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0));
+        p.add(buildTMSSettingsPanel(),GBC.eol().insets(20,5,0,0));
 
         p.add(new JPanel(),GBC.eol().fill(GBC.BOTH));
@@ -250,4 +314,11 @@
 
         Main.pref.put("wmsplugin.remotecontrol", String.valueOf(allowRemoteControl));
+
+        TMSPreferences.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected());
+        TMSPreferences.PROP_DEFAULT_AUTOLOAD.put(this.autoloadTiles.isSelected());
+        TMSPreferences.setMaxZoomLvl((Integer)this.maxZoomLvl.getValue());
+        TMSPreferences.setMinZoomLvl((Integer)this.minZoomLvl.getValue());
+        TMSPreferences.PROP_FADE_BACKGROUND.put(this.fadeBackground.getValue());
+
         return false;
     }
Index: applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java
===================================================================
--- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java	(revision 24520)
+++ applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java	(revision 24521)
@@ -109,4 +109,5 @@
     private JPopupMenu tileOptionMenu;
     JCheckBoxMenuItem autoZoomPopup;
+    JCheckBoxMenuItem autoLoadPopup;
     Tile showMetadataTile;
     private Image attrImage;
@@ -116,6 +117,6 @@
     private static Font ATTR_LINK_FONT = Font.decode("Arial Underline 10");
 
-    protected boolean autoZoom = true;
-    protected boolean autoLoad = true;
+    protected boolean autoZoom;
+    protected boolean autoLoad;
 
     void redraw()
@@ -170,5 +171,6 @@
         this.setVisible(true);
 
-        currentZoomLevel = 0; //FIXME: detect current zoom level
+        currentZoomLevel = TMSPreferences.getMinZoomLvl(null); //FIXME: detect current zoom level
+
         if (info.getImageryType() == ImageryType.TMS) {
             setTileStorage(new TMSTileSource(info.getName(),info.getURL()));
@@ -179,4 +181,6 @@
         tileOptionMenu = new JPopupMenu();
 
+
+        autoZoom = TMSPreferences.PROP_DEFAULT_AUTOZOOM.get();
         autoZoomPopup = new JCheckBoxMenuItem();
         autoZoomPopup.setAction(new AbstractAction(tr("Auto Zoom")) {
@@ -188,4 +192,15 @@
         autoZoomPopup.setSelected(autoZoom);
         tileOptionMenu.add(autoZoomPopup);
+
+        autoLoad = TMSPreferences.PROP_DEFAULT_AUTOLOAD.get();
+        autoLoadPopup = new JCheckBoxMenuItem();
+        autoLoadPopup.setAction(new AbstractAction(tr("Auto load tiles")) {
+            @Override
+            public void actionPerformed(ActionEvent ae) {
+                autoLoad= !autoLoad;
+            }
+        });
+        autoLoadPopup.setSelected(autoLoad);
+        tileOptionMenu.add(autoLoadPopup);
 
         tileOptionMenu.add(new JMenuItem(new AbstractAction(tr("Load Tile")) {
@@ -348,10 +363,10 @@
     int getMaxZoomLvl()
     {
-        return tileSource.getMaxZoom();
+        return TMSPreferences.getMaxZoomLvl(tileSource);
     }
 
     int getMinZoomLvl()
     {
-        return tileSource.getMinZoom();
+        return TMSPreferences.getMinZoomLvl(tileSource);
     }
 
@@ -659,4 +674,12 @@
                         img_x_end, img_y_end,
                         this);
+        float fadeBackground = TMSPreferences.getFadeBackground();
+        if (fadeBackground != 0f) {
+            // dimm by painting opaque rect...
+            // TODO: make fade color configurable and implement same feature for WMS layers
+            g.setColor(new Color(1f, 1f, 1f, fadeBackground));
+            g.fillRect(target.x, target.y,
+                       target.width, target.height);
+        }
     }
     Double lastImageScale = null;
@@ -703,4 +726,13 @@
         int texty = p.y + 2 + fontHeight;
 
+        if (TMSPreferences.PROP_DRAW_DEBUG.get()) {
+            g.drawString("x=" + t.getXtile() + " y=" + t.getYtile() + " z=" + zoom + "", p.x + 2, texty);
+            texty += 1 + fontHeight;
+            if ((t.getXtile() % 32 == 0) && (t.getYtile() % 32 == 0)) {
+                g.drawString("x=" + t.getXtile() / 32 + " y=" + t.getYtile() / 32 + " z=7", p.x + 2, texty);
+                texty += 1 + fontHeight;
+            }
+        }// end of if draw debug
+
         if (tile == showMetadataTile) {
             String md = tile.toString();
@@ -715,4 +747,29 @@
             g.drawString(tr("image " + tileStatus), p.x + 2, texty);
             texty += 1 + fontHeight;
+        }
+
+        int xCursor = -1;
+        int yCursor = -1;
+        if (TMSPreferences.PROP_DRAW_DEBUG.get()) {
+            if (yCursor < t.getYtile()) {
+                if (t.getYtile() % 32 == 31) {
+                    g.fillRect(0, p.y - 1, mv.getWidth(), 3);
+                } else {
+                    g.drawLine(0, p.y, mv.getWidth(), p.y);
+                }
+                yCursor = t.getYtile();
+            }
+            // This draws the vertical lines for the entire
+            // column. Only draw them for the top tile in
+            // the column.
+            if (xCursor < t.getXtile()) {
+                if (t.getXtile() % 32 == 0) {
+                    // level 7 tile boundary
+                    g.fillRect(p.x - 1, 0, 3, mv.getHeight());
+                } else {
+                    g.drawLine(p.x, 0, p.x, mv.getHeight());
+                }
+                xCursor = t.getXtile();
+            }
         }
     }
Index: applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSPreferences.java
===================================================================
--- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSPreferences.java	(revision 24521)
+++ applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSPreferences.java	(revision 24521)
@@ -0,0 +1,104 @@
+package org.openstreetmap.josm.plugins.imagery.tms;
+
+import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
+import org.openstreetmap.josm.data.preferences.BooleanProperty;
+import org.openstreetmap.josm.data.preferences.IntegerProperty;
+
+/**
+ * Preferences for Slippy Map Tiles
+ *
+ * @author Hakan Tandogan <hakan@gurkensalat.com>
+ * @author LuVar <lubomir.varga@freemap.sk>
+ * @author Upliner <upliner@gmail.com>
+ *
+ */
+public class TMSPreferences
+{
+    public static final String PREFERENCE_PREFIX   = "imagery.tms";
+
+    public static final int MAX_ZOOM = 30;
+    public static final int MIN_ZOOM = 2;
+    public static final int DEFAULT_MAX_ZOOM = 20;
+    public static final int DEFAULT_MIN_ZOOM = 2;
+
+    public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty(PREFERENCE_PREFIX + ".default_autozoom", true);
+    public static final BooleanProperty PROP_DEFAULT_AUTOLOAD = new BooleanProperty(PREFERENCE_PREFIX + ".default_autoload", true);
+    public static final IntegerProperty PROP_MIN_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".min_zoom_lvl", DEFAULT_MIN_ZOOM);
+    public static final IntegerProperty PROP_MAX_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".max_zoom_lvl", DEFAULT_MAX_ZOOM);
+    public static final IntegerProperty PROP_FADE_BACKGROUND = new IntegerProperty(PREFERENCE_PREFIX + ".fade_background", 0);
+    public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false);
+
+    public static void setFadeBackground(float fadeBackground) {
+        PROP_FADE_BACKGROUND.put(Math.round(fadeBackground*100));
+    }
+
+    /**
+     *
+     * @return  number between 0 and 1, inclusive
+     */
+    public static float getFadeBackground() {
+        float parsed = (PROP_FADE_BACKGROUND.get())/100.0f;
+        if(parsed < 0f) {
+            parsed = 0f;
+        } else {
+            if(parsed > 1f) {
+                parsed = 1f;
+            }
+        }
+        return parsed;
+    }
+
+    static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts)
+    {
+        if(maxZoomLvl > MAX_ZOOM) {
+            System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30.");
+            maxZoomLvl = MAX_ZOOM;
+        }
+        if(maxZoomLvl < PROP_MIN_ZOOM_LVL.get()) {
+            System.err.println("maxZoomLvl shouldnt be more than minZoomLvl! Setting to minZoomLvl.");
+            maxZoomLvl = PROP_MIN_ZOOM_LVL.get();
+        }
+        if (ts != null && ts.getMaxZoom() < PROP_MIN_ZOOM_LVL.get()) {
+            System.err.println("decreasing maxZoomLvl to match new tile source");
+            maxZoomLvl = ts.getMaxZoom();
+        }
+        return maxZoomLvl;
+    }
+
+    public static int getMaxZoomLvl(TileSource ts)
+    {
+        return checkMaxZoomLvl(PROP_MAX_ZOOM_LVL.get(), ts);
+    }
+
+    public static void setMaxZoomLvl(int maxZoomLvl) {
+        maxZoomLvl = checkMaxZoomLvl(maxZoomLvl, null);
+        PROP_MAX_ZOOM_LVL.put(maxZoomLvl);
+    }
+
+    static int checkMinZoomLvl(int minZoomLvl, TileSource ts)
+    {
+        if(minZoomLvl < MIN_ZOOM) {
+            System.err.println("minZoomLvl shouldnt be lees than "+MIN_ZOOM+"! Setting to that.");
+            minZoomLvl = MIN_ZOOM;
+        }
+        if(minZoomLvl > PROP_MAX_ZOOM_LVL.get()) {
+            System.err.println("minZoomLvl shouldnt be more than maxZoomLvl! Setting to maxZoomLvl.");
+            minZoomLvl = getMaxZoomLvl(ts);
+        }
+        if (ts != null && ts.getMinZoom() > PROP_MIN_ZOOM_LVL.get()) {
+            System.err.println("increasomg minZoomLvl to match new tile source");
+            minZoomLvl = ts.getMinZoom();
+        }
+        return minZoomLvl;
+    }
+
+    public static int getMinZoomLvl(TileSource ts)
+    {
+        return checkMinZoomLvl(PROP_MIN_ZOOM_LVL.get(), ts);
+    }
+
+    public static void setMinZoomLvl(int minZoomLvl) {
+        minZoomLvl = checkMinZoomLvl(minZoomLvl, null);
+        PROP_MIN_ZOOM_LVL.put(minZoomLvl);
+    }
+}
