Index: /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fckdialog.js
===================================================================
--- /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fckdialog.js	(revision 1215)
+++ /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fckdialog.js	(revision 1216)
@@ -108,124 +108,6 @@
 	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.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.TopDialog.contentWindow.SetEnabled( false ) ;
+	// Keep record of the dialog's parent/child relationships.
 	dialog._ParentDialog = this.TopDialog ;
 	this.TopDialog = dialog ;
-
-	// Register drag handlers.
-	this.InitDragHandlers( ownerWindow ) ;
 }
-
-;(function()
-{
-	var _dragDialog = null ;
-	var _ownerWindow = null ;
-	var _lastCoords = null ;
-
-	FCKDialog._GetMouseCoordinates = function( evt )
-	{
-		var element = evt.srcElement || evt.target ;
-		var doc = FCKTools.GetElementDocument( element ) ;
-		var view = doc.parentWindow || evt.view ;
-		var retval = { 'x': evt.clientX, 'y': evt.clientY };
-
-		if ( view != _ownerWindow )
-		{
-			var offset = FCKTools.GetDocumentPosition( _ownerWindow, doc.documentElement ) ;
-			retval.x += offset.x ;
-			retval.y += offset.y ;
-		}
-
-		return retval ;
-	}
-
-	FCKDialog._DragMouseDownHandler = function( evt )
-	{
-		var view = null ;
-		if ( !evt )
-		{
-			view = FCKTools.GetElementDocument( this ).parentWindow ;
-			evt = view.event ;
-		}
-		else
-			view = evt.view ;
-
-		_dragDialog = view.frameElement ;
-		_lastCoords = FCKDialog._GetMouseCoordinates( evt ) ;
-
-		if ( evt.preventDefault )
-			evt.preventDefault() ;
-		else
-			evt.returnValue = false ;
-	}
-
-	FCKDialog._DragMouseMoveHandler = function( evt )
-	{
-		if ( !_dragDialog )
-			return ;
-		if ( !evt )
-			evt = FCKTools.GetElementDocument( this ).parentWindow.event ;
-
-		var currentCoords = FCKDialog._GetMouseCoordinates( evt );
-		var dx = currentCoords.x - _lastCoords.x;
-		var dy = currentCoords.y - _lastCoords.y;
-		_lastCoords = currentCoords;
-
-		var x = parseInt( FCKDomTools.GetCurrentElementStyle( _ownerWindow, _dragDialog, 'left' ) ) + dx ;
-		var y = parseInt( FCKDomTools.GetCurrentElementStyle( _ownerWindow, _dragDialog, 'top' ) ) + dy ;
-		FCKDomTools.SetElementStyles( _dragDialog,
-			{
-				'left' : x + 'px',
-				'top' : y + 'px'
-			} ) ;
-
-		if ( evt.preventDefault )
-			evt.preventDefault() ;
-		else
-			evt.returnValue = false ;
-	}
-
-	FCKDialog._DragMouseUpHandler = function( evt )
-	{
-		if ( !_dragDialog )
-			return ;
-		if ( !evt )
-			evt = FCKTools.GetElementDocument( this ).parentWindow.event ;
-		_dragDialog = null ;
-		_lastCoords = null ;
-	}
-
-	FCKDialog.RegisterDragHandlers = function( w )
-	{
-		if ( w._FCKDialogHandlersRegistered )
-			return ;
-
-		FCKTools.AddEventListener( w.document.documentElement, 'mousemove', this._DragMouseMoveHandler ) ;
-		FCKTools.AddEventListener( w.document.documentElement, 'mouseup', this._DragMouseUpHandler ) ;
-		w._FCKDialogHandlersRegistered = true ;
-	}
-
-	FCKDialog.InitDragHandlers = function( w )
-	{
-		if ( _ownerWindow )
-			return ;
-		_ownerWindow = w ;
-		this.RegisterDragHandlers( w ) ;
-	}
-})() ;
Index: /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html
===================================================================
--- /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html	(revision 1215)
+++ /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html	(revision 1216)
@@ -32,4 +32,9 @@
 var args		= window.dialogArguments = dialogFrame._DialogArguments ;
 var editor		= args.Editor ;
+var eventId		= Math.random() ;
+var FCKTools		= editor.FCKTools ;
+var FCKDomTools		= editor.FCKDomTools ;
+var FCKDialog		= editor.FCKDialog ;
+var FCK			= editor.FCK ;
 
 // Automatically detect the correct document.domain (#123).
@@ -90,5 +95,5 @@
 
 	var titleElement = document.getElementById( 'TitleArea' ) ;
-	titleElement.onmousedown = editor.FCKDialog._DragMouseDownHandler ;
+	titleElement.onmousedown = DragMouseDownHandler ;
 
 	if ( FCKBrowserInfo.IsIE )
@@ -100,5 +105,60 @@
 	else
 		titleElement.style.userSelect = 'none' ;
-	editor.FCKDialog.RegisterDragHandlers( window ) ;
+	RegisterDragHandlers( window ) ;
+	RegisterDragHandlers( window.parent ) ;
+
+	if ( !frameElement._ParentDialog )
+		FCK.ToolbarSet.CurrentInstance.SetDialogMode( true ) ;
+	else
+	{
+		frameElement._ParentDialog.contentWindow.SetEnabled( false ) ;
+		if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 )
+		{
+			var currentParent = frameElement._ParentDialog ;
+			while ( currentParent )
+			{
+				var blockerFrame = currentParent.contentWindow.document.getElementById( 'blocker' ) ;
+				if ( blockerFrame._Loaded )
+					RegisterDragHandlers( blockerFrame.contentWindow ) ;
+				else
+				{
+					blockerFrame.onreadystatechange = function()
+					{
+						if ( this.readyState != 'complete' )
+							return ;
+						RegisterDragHandlers( this.contentWindow ) ;
+						this._Loaded = true ;
+					}
+				}
+				currentParent = currentParent._ParentDialog ;
+			}
+		}
+		else
+		{
+			var currentParent = frameElement._ParentDialog ;
+			while ( currentParent )
+			{
+				RegisterDragHandlers( currentParent.contentWindow ) ;
+				currentParent = currentParent._ParentDialog ;
+			}
+		}
+	}
+
+	if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 )
+	{
+		var blockerFrame = FCK.ToolbarSet.CurrentInstance.BackgroundBlocker.firstChild ;
+		if ( blockerFrame._Loaded )
+			RegisterDragHandlers( blockerFrame.contentWindow ) ;
+		else
+		{
+			blockerFrame.onreadystatechange = function()
+			{
+				if ( this.readyState != 'complete' )
+					return ;
+				RegisterDragHandlers( this.contentWindow ) ;
+				this._Loaded = true ;
+			}
+		}
+	}
 }
 
@@ -120,5 +180,5 @@
 	throbberParent.innerHTML = html ;
 
-	var frmCoords = editor.FCKTools.GetDocumentPosition( window, frm ) ;
+	var frmCoords = FCKTools.GetDocumentPosition( window, frm ) ;
 	var x = frmCoords.x + ( frm.offsetWidth - throbberParent.offsetWidth ) / 2 ;
 	var y = frmCoords.y + ( frm.offsetHeight - throbberParent.offsetHeight ) / 2 ;
@@ -159,5 +219,5 @@
 	RefreshContainerSize();
 
-	editor.FCKDialog.RegisterDragHandlers( document.getElementById('frmMain').contentWindow ) ;
+	RegisterDragHandlers( document.getElementById('frmMain').contentWindow ) ;
 	return editor ;
 }
@@ -197,5 +257,5 @@
 function ResizeDialog(width, height)
 {
-	editor.FCKDomTools.SetElementStyles( window.frameElement,
+	FCKDomTools.SetElementStyles( window.frameElement,
 			{
 				'width' : width + 'px',
@@ -265,22 +325,22 @@
 	document.getElementById( 'frmMain' ).src = 'javascript: void(0);' ;
 
-	if ( !dontFireChange && !editor.FCK.EditMode )
+	if ( !dontFireChange && !FCK.EditMode )
 	{
 		// All dialog windows, by default, will fire the "OnSelectionChange"
 		// event, no matter the Ok or Cancel button has been pressed.
-		editor.FCK.Events.FireEvent( 'OnSelectionChange' ) ;
-	}
-
-	editor.FCKDialog._BaseZIndex -= 100 ;
+		FCK.Events.FireEvent( 'OnSelectionChange' ) ;
+	}
+
+	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 ;
+		FCK.ToolbarSet.CurrentInstance.SetDialogMode( false ) ;
+		FCKDialog.TopDialog = null ;
 	}
 	else
 	{
-		editor.FCKDialog.TopDialog = frameElement._ParentDialog ;
+		FCKDialog.TopDialog = frameElement._ParentDialog ;
 		frameElement._ParentDialog.contentWindow.SetEnabled( true ) ;
 	}
@@ -450,4 +510,5 @@
 function Window_OnClose()
 {
+	CleanUpDragHandlers() ;
 	editor.FCKFocusManager.Unlock() ;
 }
@@ -456,4 +517,100 @@
 	window.addEventListener( 'unload', Window_OnClose, false ) ;
 
+// drag and move handlers
+LastCoords = null ;
+GetMouseCoordinates = function( evt )
+{
+	var element = evt.srcElement || evt.target ;
+	var doc = FCKTools.GetElementDocument( element ) ;
+	var view = doc.parentWindow || evt.view ;
+	var retval = { 'x': evt.clientX, 'y': evt.clientY };
+
+	if ( view != window.parent )
+	{
+		var offset = FCKTools.GetDocumentPosition( window.parent, doc.documentElement ) ;
+		retval.x += offset.x ;
+		retval.y += offset.y ;
+	}
+
+	return retval ;
+}
+
+DragMouseDownHandler = function( evt )
+{
+	var view = null ;
+	if ( !evt )
+	{
+		view = FCKTools.GetElementDocument( this ).parentWindow ;
+		evt = view.event ;
+	}
+	else
+		view = evt.view ;
+
+	LastCoords = GetMouseCoordinates( evt ) ;
+
+	if ( evt.preventDefault )
+		evt.preventDefault() ;
+	else
+		evt.returnValue = false ;
+}
+
+DragMouseMoveHandler = function( evt )
+{
+	if ( !LastCoords)
+		return ;
+	if ( !evt )
+		evt = FCKTools.GetElementDocument( this ).parentWindow.event ;
+
+	var currentCoords = GetMouseCoordinates( evt );
+	var dx = currentCoords.x - LastCoords.x;
+	var dy = currentCoords.y - LastCoords.y;
+	LastCoords = currentCoords;
+
+	var x = parseInt( FCKDomTools.GetCurrentElementStyle( window.parent, frameElement, 'left' ) ) + dx ;
+	var y = parseInt( FCKDomTools.GetCurrentElementStyle( window.parent, frameElement, 'top' ) ) + dy ;
+	FCKDomTools.SetElementStyles( frameElement,
+			{
+			'left' : x + 'px',
+			'top' : y + 'px'
+			} ) ;
+
+	if ( evt.preventDefault )
+		evt.preventDefault() ;
+	else
+		evt.returnValue = false ;
+}
+
+DragMouseUpHandler = function( evt )
+{
+	if ( !LastCoords )
+		return ;
+	if ( !evt )
+		evt = FCKTools.GetElementDocument( this ).parentWindow.event ;
+	LastCoords = null ;
+}
+
+var RegisteredWindows = [] ;
+RegisterDragHandlers = function( w )
+{
+	if ( w['_FCKDialogHandlersRegistered_' + eventId] )
+		return ;
+
+	FCKTools.AddEventListener( w.document.documentElement, 'mousemove', DragMouseMoveHandler ) ;
+	FCKTools.AddEventListener( w.document.documentElement, 'mouseup', DragMouseUpHandler ) ;
+	w['_FCKDialogHandlersRegistered_' + eventId] = true ;
+	RegisteredWindows.push( w ) ;
+}
+
+
+CleanUpDragHandlers = function()
+{
+	while ( RegisteredWindows.length > 0 )
+	{
+		var item = RegisteredWindows.shift() ;
+		FCKTools.RemoveEventListener( item.document.documentElement, 'mousemove', DragMouseMoveHandler ) ;
+		FCKTools.RemoveEventListener( item.document.documentElement, 'mouseup', DragMouseMoveHandler ) ;
+		item['_FCKDialogHandlersRegistered_' + eventId] = undefined;
+	}
+}
 		</script>
 	</head>
@@ -516,5 +673,5 @@
 			var cover = document.getElementById( 'cover' ) ;
 			cover.style.backgroundColor = FCKConfig.BackgroundBlockerColor ;
-			editor.FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ;
+			FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ;
 		</script>
 	</body>
