Index: trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 5216)
+++ trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 5217)
@@ -28,5 +28,5 @@
 /**
  * <p>A map renderer which renders a map according to style rules in a set of style sheets.</p>
- * 
+ *
  */
 public class StyledMapRenderer extends AbstractMapRenderer{
@@ -39,6 +39,6 @@
     private static int FLAG_NORMAL = 0;
     private static int FLAG_DISABLED = 1;
-    private static int FLAG_SELECTED = 2;
-    private static int FLAG_MEMBER_OF_SELECTED = 4;
+    private static int FLAG_MEMBER_OF_SELECTED = 2;
+    private static int FLAG_SELECTED = 4;
 
     private static class StyleRecord implements Comparable<StyleRecord> {
@@ -59,20 +59,19 @@
             if ((this.flags & FLAG_DISABLED) == 0 && (other.flags & FLAG_DISABLED) != 0)
                 return 1;
-            float z_index1 = this.style.z_index;
-            if ((this.flags & FLAG_SELECTED) != 0) {
-                z_index1 += 700f;
-            } else if ((this.flags & FLAG_MEMBER_OF_SELECTED) != 0) {
-                z_index1 += 600f;
-            }
-            float z_index2 = other.style.z_index;
-            if ((other.flags & FLAG_SELECTED) != 0) {
-                z_index2 += 700f;
-            } else if ((other.flags & FLAG_MEMBER_OF_SELECTED) != 0) {
-                z_index2 += 600f;
-            }
-
-            int d1 = Float.compare(z_index1, z_index2);
-            if (d1 != 0)
-                return d1;
+
+            int d0 = Float.compare(this.style.major_z_index, other.style.major_z_index);
+            if (d0 != 0)
+                return d0;
+
+            // selected on top of member of selected on top of unselected
+            // FLAG_DISABLED bit is the same at this point
+            if (this.flags > other.flags)
+                return 1;
+            if (this.flags < other.flags)
+                return -1;
+
+            int dz = Float.compare(this.style.z_index, other.style.z_index);
+            if (dz != 0)
+                return dz;
 
             // simple node on top of icons and shapes
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 5216)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 5217)
@@ -28,5 +28,5 @@
 
     protected AreaElemStyle(Cascade c, Color color, MapImage fillImage, TextElement text) {
-        super(c, -1000f);
+        super(c, 1f);
         CheckParameterUtil.ensureParameterNotNull(color);
         this.color = color;
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java	(revision 5216)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java	(revision 5217)
@@ -90,5 +90,5 @@
 
     public BoxTextElemStyle(Cascade c, TextElement text, BoxProvider boxProvider, Rectangle box, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign) {
-        super(c, 2000f);
+        super(c, 5f);
         CheckParameterUtil.ensureParameterNotNull(text);
         CheckParameterUtil.ensureParameterNotNull(hAlign);
@@ -197,7 +197,7 @@
         if (boxProvider != null) {
             if (!boxProvider.equals(other.boxProvider)) return false;
-        } else if (other.boxProvider != null) {
+        } else if (other.boxProvider != null)
             return false;
-        } else {
+        else {
             if (!box.equals(other.box)) return false;
         }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java	(revision 5216)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java	(revision 5217)
@@ -16,4 +16,5 @@
 abstract public class ElemStyle {
 
+    public float major_z_index;
     public float z_index;
     public float object_z_index;
@@ -21,5 +22,6 @@
     // primitive; true, if it is a highlight or modifier
 
-    public ElemStyle(float z_index, float object_z_index, boolean isModifier) {
+    public ElemStyle(float major_z_index, float z_index, float object_z_index, boolean isModifier) {
+        this.major_z_index = major_z_index;
         this.z_index = z_index;
         this.object_z_index = object_z_index;
@@ -27,6 +29,7 @@
     }
 
-    protected ElemStyle(Cascade c, float default_z_index) {
-        z_index = c.get("z-index", default_z_index, Float.class);
+    protected ElemStyle(Cascade c, float default_major_z_index) {
+        major_z_index = c.get("major-z-index", default_major_z_index, Float.class);
+        z_index = c.get("z-index", 0f, Float.class);
         object_z_index = c.get("object-z-index", 0f, Float.class);
         isModifier = c.get("modifier", false, Boolean.class);
@@ -81,5 +84,5 @@
      * expensive lookups and to avoid too many font objects
      * (in analogy to flyweight pattern).
-     * 
+     *
      * FIXME: cached preference values are not updated if the user changes them during
      * a JOSM session. Should have a listener listening to preference changes.
@@ -170,5 +173,8 @@
             return false;
         ElemStyle s = (ElemStyle) o;
-        return z_index == s.z_index && object_z_index == s.object_z_index && isModifier == s.isModifier;
+        return major_z_index == s.major_z_index &&
+                z_index == s.z_index &&
+                object_z_index == s.object_z_index &&
+                isModifier == s.isModifier;
     }
 
@@ -176,4 +182,5 @@
     public int hashCode() {
         int hash = 5;
+        hash = 41 * hash + Float.floatToIntBits(this.major_z_index);
         hash = 41 * hash + Float.floatToIntBits(this.z_index);
         hash = 41 * hash + Float.floatToIntBits(this.object_z_index);
@@ -184,7 +191,5 @@
     @Override
     public String toString() {
-        if (z_index != 0f || object_z_index != 0f)
-            return String.format("z_idx=%s/%s ", z_index, object_z_index) + (isModifier ? "modifier " : "");
-        return "";
+        return String.format("z_idx=[%s/%s/%s] ", major_z_index, z_index, object_z_index) + (isModifier ? "modifier " : "");
     }
 }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java	(revision 5216)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java	(revision 5217)
@@ -40,18 +40,20 @@
 
     protected enum LineType {
-        NORMAL(""),
-        CASING("casing-"),
-        LEFT_CASING("left-casing-"),
-        RIGHT_CASING("right-casing-");
-
-        public String prefix;
-
-        LineType(String prefix) {
+        NORMAL("", 3f),
+        CASING("casing-", 2f),
+        LEFT_CASING("left-casing-", 2.1f),
+        RIGHT_CASING("right-casing-", 2.1f);
+
+        public final String prefix;
+        public final float default_major_z_index;
+
+        LineType(String prefix, float default_major_z_index) {
             this.prefix = prefix;
-        }
-    }
-
-    protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float offset, float realWidth) {
-        super(c, 0f);
+            this.default_major_z_index = default_major_z_index;
+        }
+    }
+
+    protected LineElemStyle(Cascade c, float default_major_z_index, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float offset, float realWidth) {
+        super(c, default_major_z_index);
         this.line = line;
         this.color = color;
@@ -69,5 +71,4 @@
         LineElemStyle leftCasing = createImpl(env, LineType.LEFT_CASING);
         if (leftCasing != null) {
-            leftCasing.z_index += -90;
             leftCasing.isModifier = true;
         }
@@ -78,5 +79,4 @@
         LineElemStyle rightCasing = createImpl(env, LineType.RIGHT_CASING);
         if (rightCasing != null) {
-            rightCasing.z_index += -90;
             rightCasing.isModifier = true;
         }
@@ -87,5 +87,4 @@
         LineElemStyle casing = createImpl(env, LineType.CASING);
         if (casing != null) {
-            casing.z_index += -100;
             casing.isModifier = true;
         }
@@ -263,5 +262,5 @@
         }
 
-        return new LineElemStyle(c, line, color, dashesLine, dashesBackground, offset, realWidth);
+        return new LineElemStyle(c, type.default_major_z_index, line, color, dashesLine, dashesBackground, offset, realWidth);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java	(revision 5216)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java	(revision 5217)
@@ -16,5 +16,5 @@
 
     public LinePatternElemStyle(Cascade c, MapImage pattern) {
-        super(c, -1f);
+        super(c, 2.9f);
         this.pattern = pattern;
     }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java	(revision 5216)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java	(revision 5217)
@@ -10,9 +10,9 @@
 
 public class LineTextElemStyle extends ElemStyle {
-    
+
     private TextElement text;
 
     protected LineTextElemStyle(Cascade c, TextElement text) {
-        super(c, 2f);
+        super(c, 4.9f);
         this.text = text;
     }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 5216)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 5217)
@@ -15,9 +15,8 @@
 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
+import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProvider;
+import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.SimpleBoxProvider;
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
-import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProvider;
-import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.SimpleBoxProvider;
-import org.openstreetmap.josm.tools.Pair;
 import org.openstreetmap.josm.tools.Utils;
 
@@ -85,5 +84,5 @@
         MultiCascade mc = new MultiCascade();
         Cascade c = mc.getOrCreateCascade("default");
-        SIMPLE_NODE_ELEMSTYLE = create(new Environment(null, mc, "default", null), true);
+        SIMPLE_NODE_ELEMSTYLE = create(new Environment(null, mc, "default", null), 4.1f, true);
         if (SIMPLE_NODE_ELEMSTYLE == null) throw new AssertionError();
     }
@@ -92,6 +91,6 @@
     public static final StyleList DEFAULT_NODE_STYLELIST_TEXT = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE);
 
-    protected NodeElemStyle(Cascade c, MapImage mapImage, Symbol symbol) {
-        super(c, 1000f);
+    protected NodeElemStyle(Cascade c, MapImage mapImage, Symbol symbol, float default_major_z_index) {
+        super(c, default_major_z_index);
         this.mapImage = mapImage;
         this.symbol = symbol;
@@ -99,8 +98,8 @@
 
     public static NodeElemStyle create(Environment env) {
-        return create(env, false);
-    }
-
-    private static NodeElemStyle create(Environment env, boolean allowDefault) {
+        return create(env, 4f, false);
+    }
+
+    private static NodeElemStyle create(Environment env, float default_major_z_index, boolean allowDefault) {
         Cascade c = env.mc.getCascade(env.layer);
 
@@ -116,5 +115,5 @@
         if (!allowDefault && symbol == null && mapImage == null) return null;
 
-        return new NodeElemStyle(c, mapImage, symbol);
+        return new NodeElemStyle(c, mapImage, symbol, default_major_z_index);
     }
 
@@ -302,9 +301,9 @@
 
     public BoxProvider getBoxProvider() {
-        if (mapImage != null) {
+        if (mapImage != null)
             return mapImage.getBoxProvider();
-        } else if (symbol != null) {
+        else if (symbol != null)
             return new SimpleBoxProvider(new Rectangle(-symbol.size/2, -symbol.size/2, symbol.size, symbol.size));
-        } else {
+        else {
             // This is only executed once, so no performance concerns.
             // However, it would be better, if the settings could be changed at runtime.
