Index: /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js	(revision 2511)
+++ /CKEditor/branches/prototype/_source/plugins/dialog/plugin.js	(revision 2512)
@@ -94,4 +94,6 @@
 	// Make the dialog an event hub.
 	CKEDITOR.event.implementOn( this );
+
+	// Initialize load, ok and cancel events.
 	if ( definition.onLoad )
 		this.on( 'load', definition.onLoad, this, null, CKEDITOR.tools.getNextNumber() );
@@ -138,4 +140,6 @@
 					this.hide();
 			}, this );
+
+	CKEDITOR.dialog._.initDragAndDrop( this );
 
 	// Insert the title.
@@ -207,24 +211,34 @@
 	})(),
 
-	move : function( x, y )
-	{
-		// The dialog may be fixed positioned or absolute positioned. Ask the
-		// browser what is the current situation first.
-		var isFixed = this._.element.getFirst().getComputedStyle( 'position' ) == 'fixed';
-
-		// If not fixed positioned, add scroll position to the coordinates.
-		if ( !isFixed )
-		{
-			var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
-			x += scrollPosition.x;
-			y += scrollPosition.y;
-		}
-
-		this._.element.getFirst().setStyles(
-				{
-					'left' : x + 'px',
-					'top' : y + 'px'
-				});
-	},
+	move : (function()
+	{
+		var isFixed;
+		return function( x, y )
+		{
+			// The dialog may be fixed positioned or absolute positioned. Ask the
+			// browser what is the current situation first.
+			if ( isFixed === undefined )
+				isFixed = this._.element.getFirst().getComputedStyle( 'position' ) == 'fixed';
+
+			// Save the current position.
+			this._.position = { x : x, y : y };
+
+			// If not fixed positioned, add scroll position to the coordinates.
+			if ( !isFixed )
+			{
+				var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
+				x += scrollPosition.x;
+				y += scrollPosition.y;
+			}
+
+			this._.element.getFirst().setStyles(
+					{
+						'left' : x + 'px',
+						'top' : y + 'px'
+					});
+		}
+	})(),
+
+	getScreenPosition : function(){ return this._.position; },
 
 	show : function()
@@ -262,6 +276,7 @@
 		if ( CKEDITOR.dialog._.currentTop == null )
 		{
+			CKEDITOR.dialog._.currentTop = this;
+			this._.parentDialog = null;
 			CKEDITOR.dialog._.addCover();
-			this._.parentDialog = null;
 		}
 		else
@@ -592,5 +607,5 @@
 		if ( CKEDITOR.env.ie )
 		{
-			html.push( '<iframe hidefocus="true" frameborder="0" ' );
+			html.push( '<iframe hidefocus="true" frameborder="0" name="cke_dialog_background_iframe" ' );
 			if ( Math.floor( CKEDITOR.env.version ) == 6 )
 				html.push( 'src="javascript: " ' );
@@ -613,5 +628,6 @@
 			scrollFunc = function()
 			{
-				var pos = win.getScrollPosition();
+				var pos = win.getScrollPosition(),
+					cursor = CKEDITOR.dialog._.currentTop;
 				element.setStyles(
 						{
@@ -619,4 +635,10 @@
 							top : pos.y + 'px'
 						});
+
+				do
+				{
+					var dialogPos = cursor.getScreenPosition();
+					cursor.move( dialogPos.x, dialogPos.y );
+				} while( cursor = cursor._.parentDialog );
 			};
 		CKEDITOR.dialog._.resizeCover = resizeFunc;
@@ -662,4 +684,45 @@
 			CKEDITOR.dialog._.resizeCover = null;
 		}
+	},
+
+	initDragAndDrop : function( dialog )
+	{
+		var lastCoords = null,
+			element = dialog.getElement().getFirst(),
+			mouseMoveHandler = function( evt )
+			{
+				var dialogCoords = dialog.getScreenPosition(),
+					dx = evt.data.$.screenX - lastCoords.x,
+					dy = evt.data.$.screenY - lastCoords.y;
+				lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
+				dialog.move( dialogCoords.x + dx, dialogCoords.y + dy );
+			},
+			mouseUpHandler = function( evt )
+			{
+				CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
+				CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
+
+				if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )
+				{
+					var coverDoc = new CKEDITOR.dom.document( frames( 'cke_dialog_background_iframe' ).document );
+					coverDoc.removeListener( 'mousemove', mouseMoveHandler );
+					coverDoc.removeListener( 'mouseup', mouseUpHandler );
+				}
+			};
+
+		dialog._.parts.title.on( 'mousedown', function( evt )
+				{
+					lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
+
+					CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
+					CKEDITOR.document.on( 'mouseup', mouseUpHandler );
+
+					if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )
+					{
+						var coverDoc = new CKEDITOR.dom.document( frames( 'cke_dialog_background_iframe' ).document );
+						coverDoc.on( 'mousemove', mouseMoveHandler );
+						coverDoc.on( 'mouseup', mouseUpHandler );
+					}
+				}, dialog );
 	},
 
