Index: /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js	(revision 2529)
+++ /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js	(revision 2530)
@@ -296,4 +296,6 @@
 
 		// Set z-index.
+		if ( CKEDITOR.dialog._.currentZIndex === null )
+			CKEDITOR.dialog._.currentZIndex = this._.editor.config.basePopupZIndex;
 		this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
 
@@ -303,5 +305,5 @@
 			CKEDITOR.dialog._.currentTop = this;
 			this._.parentDialog = null;
-			CKEDITOR.dialog._.addCover();
+			CKEDITOR.dialog._.addCover( this._.editor );
 		}
 		else
@@ -309,5 +311,5 @@
 			this._.parentDialog = CKEDITOR.dialog._.currentTop;
 			var parentElement = this._.parentDialog.getElement().getFirst();
-			parentElement.$.style.zIndex  -= Math.floor( CKEDITOR.config.basePopupZIndex / 2 );
+			parentElement.$.style.zIndex  -= Math.floor( this._.editor.config.basePopupZIndex / 2 );
 			CKEditor.dialog._.currentTop = this;
 		}
@@ -331,10 +333,13 @@
 		{
 			var parentElement = this._.parentDialog.getElement().getFirst();
-			parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex ) + Math.floor( CKEDITOR.config.basePopupZIndex / 2 ) );
+			parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex ) + Math.floor( this._.editor.config.basePopupZIndex / 2 ) );
 		}
 		CKEDITOR.dialog._.currentTop = this._.parentDialog;
 
-		// Deduct the z-index.
-		CKEDITOR.dialog._.currentZIndex -= 10;
+		// Deduct or clear the z-index.
+		if ( this._.parentDialog == null )
+			CKEDITOR.dialog._.currentZIndex = null;
+		else
+			CKEDITOR.dialog._.currentZIndex -= 10;
 	},
 
@@ -625,11 +630,11 @@
 	},
 
-	addCover : function()
+	addCover : function( editor )
 	{
 		var html = [
 				'<div style="position: ', ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 ? 'absolute' : 'fixed' ),
-				'; z-index: ', CKEDITOR.config.basePopupZIndex,
+				'; z-index: ', editor.config.basePopupZIndex,
 				'; top: 0px; left: 0px; ',
-				'background-color: ', CKEDITOR.config.backgroundCoverColor,
+				'background-color: ', editor.config.backgroundCoverColor,
 				'" id="cke_dialog_background_cover">'
 			],
@@ -687,5 +692,5 @@
 			scrollFunc();
 		}
-		element.setOpacity( CKEDITOR.config.backgroundCoverOpacity );
+		element.setOpacity( editor.config.backgroundCoverOpacity );
 		element.appendTo( CKEDITOR.document.getBody() );
 	},
@@ -717,5 +722,5 @@
 			abstractDialogCoords = null,
 			element = dialog.getElement().getFirst(),
-			magnetDistance = CKEDITOR.config.magnetDistance,
+			magnetDistance = dialog._.editor.config.magnetDistance,
 			mouseMoveHandler = function( evt )
 			{
@@ -800,5 +805,5 @@
 			lastCoords = null,
 			abstractDialogCoords = null,
-			magnetDistance = CKEDITOR.config.magnetDistance,
+			magnetDistance = dialog._.editor.config.magnetDistance,
 			parts = [ 'tl', 't', 'tr', 'l', 'r', 'bl', 'b', 'br' ],
 			mouseDownHandler = function( evt )
@@ -898,5 +903,5 @@
 	currentTop : null,
 
-	currentZIndex : CKEDITOR.config.basePopupZIndex,
+	currentZIndex : null,
 
 	margins : [0, 0, 0, 0]
Index: /CKEditor/branches/prototype/_source/plugins/wysiwygarea/plugin.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/wysiwygarea/plugin.js	(revision 2529)
+++ /CKEditor/branches/prototype/_source/plugins/wysiwygarea/plugin.js	(revision 2530)
@@ -222,8 +222,8 @@
 
 								data =
-									CKEDITOR.config.docType +
-									'<html dir="' + CKEDITOR.config.contentsLangDirection + '">' +
+									editor.config.docType +
+									'<html dir="' + editor.config.contentsLangDirection + '">' +
 									'<head>' +
-										'<link href="' + CKEDITOR.config.contentsCss + '" type="text/css" rel="stylesheet" _fcktemp="true"/>' +
+										'<link href="' + editor.config.contentsCss + '" type="text/css" rel="stylesheet" _fcktemp="true"/>' +
 									'</head>' +
 									'<body>' +
