Index: /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js	(revision 2505)
+++ /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js	(revision 2506)
@@ -228,8 +228,17 @@
 		this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
 
-		// Add self to global dialog stack, and display dialog cover if first in line.
-		CKEDITOR.dialog._.dialogStack.push( this );
-		if ( CKEDITOR.dialog._.dialogStack.length == 1 )
+		// Maintain the dialog ordering and dialog cover.
+		if ( CKEDITOR.dialog._.currentTop == null )
+		{
 			CKEDITOR.dialog._.addCover();
+			this._.parentDialog = null;
+		}
+		else
+		{
+			this._.parentDialog = CKEDITOR.dialog._.currentTop;
+			var parentElement = this._.parentDialog.getElement().getFirst();
+			parentElement.$.style.zIndex  -= Math.floor( CKEDITOR.config.basePopupZIndex / 2 );
+			CKEditor.dialog._.currentTop = this;
+		}
 		
 		// Execute onLoad for the first show.
@@ -245,8 +254,13 @@
 		element.remove();
 
-		// Remove self from global dialog stack, and remove dialog cover if nothing is left.
-		CKEDITOR.dialog._.dialogStack.pop();
-		if ( CKEDITOR.dialog._.dialogStack.length < 1 )
+		// Maintain dialog ordering and remove cover if needed.
+		if ( this._.parentDialog == null )
 			CKEDITOR.dialog._.removeCover();
+		else
+		{
+			var parentElement = this._.parentDialog.getElement().getFirst();
+			parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex ) + Math.floor( CKEDITOR.config.basePopupZIndex / 2 ) );
+		}
+		CKEDITOR.dialog._.currentTop = this._.parentDialog;
 
 		// Deduct the z-index.
@@ -558,5 +572,6 @@
 				'background-color: ', CKEDITOR.config.backgroundCoverColor,
 				'" id="cke_dialog_background_cover">'
-			];
+			],
+			win = CKEDITOR.document.getWindow();
 		if ( CKEDITOR.env.ie )
 		{
@@ -573,5 +588,5 @@
 			resizeFunc = function()
 			{
-				var size = CKEDITOR.document.getWindow().getViewPaneSize();
+				var size = win.getViewPaneSize();
 				element.setStyles( 
 						{
@@ -579,8 +594,33 @@
 							height : size.height + 'px'
 						});
+			},
+			scrollFunc = function()
+			{
+				var pos = win.getScrollPosition();
+				element.setStyles(
+						{
+							left : pos.x + 'px',
+							top : pos.y + 'px'
+						});
 			};
 		CKEDITOR.dialog._.resizeCover = resizeFunc;
-		CKEDITOR.document.getWindow().on( 'resize', resizeFunc );
+		win.on( 'resize', resizeFunc );
 		resizeFunc();
+		if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )
+		{
+			// IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
+			// So we need to invent a really funny way to make it work.
+			var myScrollHandler = function()
+				{
+					scrollFunc();
+					arguments.callee.prevScrollHandler.apply( this, arguments );
+				};
+			win.$.setTimeout( function()
+				{
+					myScrollHandler.prevScrollHandler = window.onscroll || function(){};
+					window.onscroll = myScrollHandler;
+				}, 0 );
+			scrollFunc();
+		}
 		element.setOpacity( CKEDITOR.config.backgroundCoverOpacity );
 		element.appendTo( CKEDITOR.document.getBody() );
@@ -589,14 +629,24 @@
 	removeCover : function()
 	{
-		var element = CKEDITOR.document.getById( 'cke_dialog_background_cover' );
+		var element = CKEDITOR.document.getById( 'cke_dialog_background_cover' ),
+			win = CKEDITOR.document.getWindow();
 		if ( element )
 		{
 			element.remove();
-			CKEDITOR.document.getWindow().removeListener( 'resize', CKEDITOR.dialog._.resizeCover );
+			win.removeListener( 'resize', CKEDITOR.dialog._.resizeCover );
+
+			if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )
+			{
+				win.$.setTimeout( function()
+					{
+						var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
+						window.onscroll = prevScrollHandler || null;
+					}, 0 );
+			}
 			CKEDITOR.dialog._.resizeCover = null;
 		}
 	},
 
-	dialogStack : [],
+	currentTop : null,
 
 	currentZIndex : CKEDITOR.config.basePopupZIndex
