Index: /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fckdialog.js
===================================================================
--- /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fckdialog.js	(revision 1214)
+++ /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fckdialog.js	(revision 1215)
@@ -25,5 +25,5 @@
 {
 	_BaseZIndex : FCKConfig.FloatingPanelsZIndex + 1,
-	_DialogStack : [],
+	TopDialog : null,
 	LastSelectionData : null
 } ;
@@ -68,9 +68,4 @@
 
 	var url = FCKConfig.BasePath + 'fckdialog.html' ;
-	this.Show( dialogInfo, dialogName, url, width, height, parentWindow, resizable ) ;
-}
-
-FCKDialog.Show = function( dialogInfo, dialogName, pageUrl, dialogWidth, dialogHeight, parentWindow, resizable )
-{
 	var ownerWindow = FCK.ToolbarSet.CurrentInstance.Window.parent ;
 	var ownerDocument = ownerWindow.document ;
@@ -80,11 +75,11 @@
 
 	// Calculate the dialog position, centering it on the screen.
-	var iTop  = Math.max( scrollPosition.Y + ( viewSize.Height - dialogHeight - 20 ) / 2, 0 ) ;
-	var iLeft = Math.max( scrollPosition.X + ( viewSize.Width - dialogWidth - 20 )  / 2, 0 ) ;
-
-	var frame = ownerDocument.createElement( 'iframe' ) ;
-	frame.frameBorder = 0 ;
-	frame.allowTransparency = true ;
-	FCKDomTools.SetElementStyles( frame,
+	var iTop  = Math.max( scrollPosition.Y + ( viewSize.Height - height - 20 ) / 2, 0 ) ;
+	var iLeft = Math.max( scrollPosition.X + ( viewSize.Width - width - 20 )  / 2, 0 ) ;
+
+	var dialog = ownerDocument.createElement( 'iframe' ) ;
+	dialog.frameBorder = 0 ;
+	dialog.allowTransparency = true ;
+	FCKDomTools.SetElementStyles( dialog,
 			{
 				'position' : 'absolute',
@@ -95,83 +90,45 @@
 
 	// Save the dialog info to be used by the dialog page once loaded.
-	frame._DialogArguments = dialogInfo ;
-
-	ownerDocument.body.appendChild( frame ) ;
-	this.ResizeDialog( frame, dialogWidth, dialogHeight ) ;
-	
-	// Assigning frame.src directly does not work in Opera 9.5, need to use a timeout trick
+	dialog._DialogArguments = dialogInfo ;
+
+	ownerDocument.body.appendChild( dialog ) ;
+	FCKDomTools.SetElementStyles( dialog,
+			{
+				'width' : width + 'px',
+				'height' : height + 'px'
+			} ) ;
+
+	// Assigning dialog.src directly does not work in Opera 9.5, need to use a timeout trick
 	setTimeout( function()
 		{
-			frame.src = pageUrl ;
+			dialog.src = url ;
 		}, 0 ) ;
 
-	var oWindow = this.Window = frame.contentWindow ;
+	var oWindow = dialog.contentWindow ;
 	oWindow.focus() ;
 
 	// Keep record of the current dialog in the dialog stack, and enable dialog mode
 	// if this is the first dialog in the dialog stack.
-	if ( this._DialogStack.length == 0 )
+	if ( !this.TopDialog )
+	{
 		FCK.ToolbarSet.CurrentInstance.SetDialogMode( true ) ;
+		if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 && !FCK.ToolbarSet.CurrentInstance._BackgroundBlockDragHandlerRegistered )
+		{
+			var backgroundFrame = FCK.ToolbarSet.CurrentInstance.BackgroundBlocker.firstChild ;
+			backgroundFrame.onreadystatechange = function()
+			{
+				if ( this.readyState != 'complete' )
+					return ;
+				FCKDialog.RegisterDragHandlers( this.contentWindow ) ;
+			}
+		}
+	}
 	else
-		this.SetEnabled( this._DialogStack[ this._DialogStack.length - 1 ], false );
-	this._DialogStack.push( frame ) ;
+		this.TopDialog.contentWindow.SetEnabled( false ) ;
+	dialog._ParentDialog = this.TopDialog ;
+	this.TopDialog = dialog ;
 
 	// Register drag handlers.
 	this.InitDragHandlers( ownerWindow ) ;
-}
-
-// The following member functions should be called with a dialog frame element as subject.
-FCKDialog.ResizeDialog = function( frame, width, height )
-{
-	FCKDomTools.SetElementStyles( frame,
-		{
-			'width' : width + 'px',
-			'height' : height + 'px'
-		} ) ;
-}
-
-FCKDialog.CloseDialog = function( frame )
-{
-	frame.parentNode.removeChild( frame ) ;
-	
-	this._BaseZIndex -= 100 ;
-
-	// Pop the dialog from the dialog stack, and disable dialog mode if the stack is empty.
-	this._DialogStack.pop() ;
-	if ( this._DialogStack.length == 0)
-		FCK.ToolbarSet.CurrentInstance.SetDialogMode( false ) ;
-	else
-		this.SetEnabled( this._DialogStack[ this._DialogStack.length - 1 ], true ) ;
-
-}
-
-FCKDialog.SetEnabled = function( frame, isEnabled )
-{
-	var doc = frame.contentWindow.document ;
-	var cover = doc.getElementById( 'cover' ) ;
-	cover.style.display = isEnabled ? 'none' : '' ;
-
-	var isIE6 = FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7;
-
-	if ( isIE6 )
-	{
-		if ( !isEnabled )
-		{
-			// Insert the blocker IFRAME before the cover.
-			var blocker = doc.createElement( 'iframe' ) ;
-			blocker.src = 'javascript:void(0)' ;
-			blocker.hideFocus = true ;
-			blocker.frameBorder = 0 ;
-			blocker.id = blocker.className = 'blocker' ;
-
-			doc.body.insertBefore( blocker, cover ) ;
-		}
-		else
-		{
-			var blocker = doc.getElementById( 'blocker' ) ;
-			if ( blocker && blocker.parentNode )
-				blocker.parentNode.removeChild( blocker ) ;
-		}
-	}
 }
 
Index: /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html
===================================================================
--- /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html	(revision 1214)
+++ /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html	(revision 1215)
@@ -176,4 +176,5 @@
 }
 
+// Fit the dialog container's layout to the inner iframe's external size.
 function RefreshContainerSize()
 {
@@ -192,4 +193,17 @@
 }
 
+// Resize and re-layout the dialog.
+// Triggers the onresize event for the layout logic.
+function ResizeDialog(width, height)
+{
+	editor.FCKDomTools.SetElementStyles( window.frameElement,
+			{
+				'width' : width + 'px',
+				'height' : height + 'px'
+			} ) ;
+}
+
+// if bAutoSize is true, automatically fit the dialog size and layout to accomodate the inner iframe's internal height.
+// if bAutoSize is false, then only the layout logic for the dialog decorations is run to accomodate the inner iframe's external height.
 function RefreshSize()
 {
@@ -211,5 +225,5 @@
 
 		if ( iDiff > 0 )
-			editor.FCKDialog.ResizeDialog( window.frameElement, dialogFrame.offsetWidth, dialogFrame.offsetHeight + iDiff ) ;
+			ResizeDialog( dialogFrame.offsetWidth, dialogFrame.offsetHeight + iDiff ) ;
 	}
 	RefreshContainerSize() ;
@@ -257,5 +271,46 @@
 		editor.FCK.Events.FireEvent( 'OnSelectionChange' ) ;
 	}
-	editor.FCKDialog.CloseDialog( window.frameElement ) ;
+
+	editor.FCKDialog._BaseZIndex -= 100 ;
+
+	// Pop the dialog from the dialog stack, and disable dialog mode if the stack is empty.
+	if ( frameElement._ParentDialog == null )
+	{
+		editor.FCK.ToolbarSet.CurrentInstance.SetDialogMode( false ) ;
+		editor.FCKDialog.TopDialog = null ;
+	}
+	else
+	{
+		editor.FCKDialog.TopDialog = frameElement._ParentDialog ;
+		frameElement._ParentDialog.contentWindow.SetEnabled( true ) ;
+	}
+	
+	frameElement.parentNode.removeChild( frameElement ) ;
+}
+
+function SetEnabled( isEnabled )
+{
+	var cover = document.getElementById( 'cover' ) ;
+	cover.style.display = isEnabled ? 'none' : '' ;
+
+	if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 )
+	{
+		if ( !isEnabled )
+		{
+			// Inser the blocker IFRAME before the cover.
+			var blocker = document.createElement( 'iframe' ) ;
+			blocker.src = 'javascript: void(0);' ;
+			blocker.hideFocus = true ;
+			blocker.frameBorder = 0 ;
+			blocker.id = blocker.className = 'blocker' ;
+			cover.appendChild( blocker ) ;
+		}
+		else
+		{
+			var blocker = document.getElementById( 'blocker' ) ;
+			if ( blocker && blocker.parentNode )
+				blocker.parentNode.removeChild( blocker ) ;
+		}
+	}
 }
 
