Index: /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fcktools.js
===================================================================
--- /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fcktools.js	(revision 1250)
+++ /FCKeditor/branches/features/floating_dialog/editor/_source/internals/fcktools.js	(revision 1251)
@@ -618,5 +618,5 @@
 FCKTools.Hitch = function( obj, methodName )
 {
-  return function() { obj[methodName].apply(obj, arguments); } ;
+  return function() { return obj[methodName].apply(obj, arguments); } ;
 }
 
Index: /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html
===================================================================
--- /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html	(revision 1250)
+++ /FCKeditor/branches/features/floating_dialog/editor/fckdialog.html	(revision 1251)
@@ -40,4 +40,12 @@
 }
 
+function ParentDialog( dialog )
+{
+	if ( !dialog )
+		return frameElement._ParentDialog ;
+	else
+		return dialog._ParentDialog ;
+}
+
 var FCK			= Editor().FCK ;
 var FCKTools		= Editor().FCKTools ;
@@ -48,5 +56,5 @@
 
 // Domain relaxation logic.
-(function()
+(function RelaxDomain()
 {
 	var d = document.domain ;
@@ -94,4 +102,314 @@
 }
 
+function $( id )
+{
+	return document.getElementById( id ) ;
+}
+
+// Resize related functions.
+var Sizer = (function()
+{
+	var bAutoSize = false ;
+	var retval = {
+		// Sets whether the dialog should auto-resize according to its content's height.
+		SetAutoSize : function( autoSize )
+		{
+			bAutoSize = autoSize ;
+			this.RefreshSize() ;
+		},
+
+		// Fit the dialog container's layout to the inner iframe's external size.
+		RefreshContainerSize : function()
+		{
+			var frmMain = $( 'frmMain' ) ;
+			
+			if ( frmMain )
+			{
+				// Get the container size.
+				var height = $( 'contents' ).offsetHeight ;
+				
+				// Subtract the size of other elements.
+				height -= $( 'TitleArea' ).offsetHeight ;
+				height -= $( 'TabsRow' ).offsetHeight ;
+				height -= $( 'DialogButtons' ).offsetHeight ;
+				
+				frmMain.style.height = Math.max( height, 0 ) + 'px' ;
+			}
+		},
+
+		// Fit the dialog container's layout to the inner iframe's external size.
+		RefreshContainerSize : function()
+		{
+			var frmMain = $( 'frmMain' ) ;
+			
+			if ( frmMain )
+			{
+				// Get the container size.
+				var height = $( 'contents' ).offsetHeight ;
+				
+				// Subtract the size of other elements.
+				height -= $( 'TitleArea' ).offsetHeight ;
+				height -= $( 'TabsRow' ).offsetHeight ;
+				height -= $( 'DialogButtons' ).offsetHeight ;
+				
+				frmMain.style.height = Math.max( height, 0 ) + 'px' ;
+			}
+		},
+
+		// Resize and re-layout the dialog.
+		// Triggers the onresize event for the layout logic.
+		ResizeDialog : function( width, height )
+		{
+			FCKDomTools.SetElementStyles( window.frameElement,
+					{
+						'width' : width + 'px',
+						'height' : height + 'px'
+					} ) ;
+
+			// If the skin have defined a function for resize fixes, call it now.
+			if ( typeof window.DoResizeFixes == 'function' )
+				window.DoResizeFixes() ;
+		},
+
+		// 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.
+		RefreshSize : function()
+		{
+			if ( bAutoSize )
+			{
+				var frmMain		= $( 'frmMain' ) ;
+				var innerDoc	= frmMain.contentWindow.document ;
+				var isStrict	= FCKTools.IsStrictMode( innerDoc ) ;
+
+				// Get the size of the frame contents.
+				var innerWidth	= isStrict ? innerDoc.documentElement.scrollWidth : innerDoc.body.scrollWidth ;
+				var innerHeight	= isStrict ? innerDoc.documentElement.scrollHeight : innerDoc.body.scrollHeight ;
+
+				// Get the current frame size.
+				var frameSize = FCKTools.GetViewPaneSize( frmMain.contentWindow ) ;
+				
+				var deltaWidth	= innerWidth - frameSize.Width ;
+				var deltaHeight	= innerHeight - frameSize.Height ;
+
+				// If the contents fits the current size.		
+				if ( deltaWidth <= 0 && deltaHeight <= 0 )
+					return ;
+				
+				var dialogWidth		= frameElement.offsetWidth + Math.max( deltaWidth, 0 ) ;
+				var dialogHeight	= frameElement.offsetHeight + Math.max( deltaHeight, 0 ) ;
+
+				this.ResizeDialog( dialogWidth, dialogHeight ) ;
+			}
+			this.RefreshContainerSize() ;
+		}
+	}
+
+	// Safari seems to have a bug with the time when RefreshSize() is executed - it
+	// thinks frmMain's innerHeight is 0 if we query the value too soon after the
+	// page is loaded in some circumstances. (#1316)
+	// TODO : Maybe this is not needed anymore after #35.
+	if ( FCKBrowserInfo.IsSafari )
+	{
+		var originalRefreshSize = retval.RefreshSize ;
+
+		retval.RefreshSize = function()
+		{
+			window.setTimeout( originalRefreshSize, 1 ) ;
+		}
+	}
+
+	window.onresize = function()
+	{
+		retval.RefreshContainerSize() ;
+	}
+
+	return retval ;
+})() ;
+
+// Manages the throbber image that appears if the inner part of dialog is taking too long to load.
+var Throbber = (function()
+{
+	var retval = {
+		Show : function( waitMilliseconds )
+		{
+			if ( waitMilliseconds && waitMilliseconds > 0 )
+			{
+				this.Timer = FCKTools.SetTimeout( this.Show, waitMilliseconds, this, null, window ) ;
+				return ;
+			}
+
+			var throbberParent = $( 'throbberBlock' ) ;
+			throbberParent.innerHTML = '<img src="%%images/loading.gif" width="28" height="28" border="0" />'.replace( '%%', FCKConfig.SkinPath ) ; ;
+
+			var frm = $( 'contents' ) ;
+			var frmCoords = FCKTools.GetDocumentPosition( window, frm ) ;
+			var x = frmCoords.x + ( frm.offsetWidth - throbberParent.offsetWidth ) / 2 ;
+			var y = frmCoords.y + ( frm.offsetHeight - throbberParent.offsetHeight ) / 2 ;
+			throbberParent.style.left = parseInt( x, 10 ) + 'px' ;
+			throbberParent.style.top = parseInt( y, 10 ) + 'px' ;
+
+			this.Timer = null ;
+		},
+
+		Hide : function()
+		{
+			if ( this.Timer )
+				clearTimeout( this.Timer ) ;
+
+			var throbberParent = document.getElementById( 'throbberBlock' ) ;
+			if ( throbberParent )
+				FCKDomTools.RemoveNode( throbberParent ) ;
+		}
+	}
+	
+	FCKTools.AddEventListener( window, 'beforeunload', function()
+		{
+			if ( retval.Timer )
+				clearTimeout( retval.Timer ) ;
+		} ) ;
+	return retval ;
+})() ;
+
+// The business logic of the dialog, dealing with operational things like dialog open/dialog close/enable/disable/etc.
+var Main = (function()
+{
+	var retval = {
+		// Program entry point.
+		Init : function()
+		{
+			// Start the throbber timer.
+			Throbber.Show( 1000 ) ;
+
+			Sizer.RefreshContainerSize() ;
+			this.LoadInnerDialog() ;
+
+			FCKTools.DisableSelection( document.body ) ;
+
+			// Make the title area draggable.
+			var titleElement = $( 'header' ) ;
+			// titleElement.onmousedown = DnD.MouseDownHandler ;
+
+			// Connect mousemove and mouseup events from dialog frame and outer window to dialog dragging logic.
+			// DnD.RegisterHandlers( window ) ;
+			// DnD.RegisterHandlers( args.TopWindow ) ;
+
+			// Disable the previous dialog if it exists.
+			if ( ParentDialog() )
+			{
+				ParentDialog().contentWindow.SetEnabled( false ) ;
+				if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 )
+				{
+					var currentParent = ParentDialog() ;
+					while ( currentParent )
+					{
+						var blockerFrame = currentParent.contentWindow.$( 'blocker' ) ;
+						/*
+						if ( blockerFrame.readyState == 'complete' )
+							DnD.RegisterHandlers( blockerFrame.contentWindow ) ;
+						else
+						{
+							blockerFrame.onreadystatechange = function()
+							{
+								if ( this.readyState != 'complete' )
+									return ;
+								DnD.RegisterHandlers( this.contentWindow ) ;
+							}
+						}
+						*/
+						currentParent = ParentDialog( currentParent ) ;
+					}
+				}
+				else
+				{
+					var currentParent = ParentDialog() ;
+					while ( currentParent )
+					{
+						// DnD.RegisterHandlers( currentParent.contentWindow ) ;
+						currentParent = ParentDialog( currentParent ) ;
+					}
+				}
+			}
+
+			// If this is the only dialog on screen, enable the background cover.
+			/*
+			if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 )
+			{
+				var blockerFrame = FCKDialog.GetCover().firstChild ;
+				if ( blockerFrame.readyState == 'complete' )
+					DnD.RegisterHandlers( blockerFrame.contentWindow ) ;
+				else
+				{
+					blockerFrame.onreadystatechange = function()
+					{
+						if ( this.readyState != 'complete' )
+							return ;
+						DnD.RegisterHandlers( this.contentWindow ) ;
+					}
+				}
+			}
+			*/
+		},
+
+		LoadInnerDialog : function()
+		{
+			if ( window.onresize )
+				window.onresize() ;
+
+			// First of all, translate the dialog box contents.
+			Editor().FCKLanguageManager.TranslatePage( document ) ;
+			
+			// Create the IFRAME that holds the dialog contents.
+			$( 'innerContents' ).innerHTML = '<iframe id="frmMain" src="' + Args().Page + '" name="frmMain" frameborder="0" width="100%" height="100%" scrolling="auto" style="visibility: hidden;" allowtransparency="true"></iframe>' ;
+		},
+		
+		InnerDialogLoaded : function()
+		{
+			// If the dialog has been closed before the iframe is loaded, do nothing.
+			if ( !frameElement.parentNode )
+				return ;
+
+			Throbber.Hide() ;
+
+			var frmMain = $('frmMain') ;
+			var innerWindow = frmMain.contentWindow ;
+			var innerDoc = innerWindow.document ;
+
+			// Show the loaded iframe.
+			frmMain.style.visibility = '' ;
+
+			// Set the language direction.
+			innerDoc.dir = Editor().FCKLang.Dir ;
+
+			// Sets the Skin CSS.
+			innerDoc.write( '<link href="' + FCKConfig.SkinPath + 'fck_dialog.css" type="text/css" rel="stylesheet">' ) ;
+
+			// SetOnKeyDown( innerDoc ) ;
+			// DisableContextMenu( innerDoc ) ;
+
+			Sizer.RefreshContainerSize();
+
+			// DnD.RegisterHandlers( innerWindow ) ;
+			
+			innerWindow.focus() ;
+
+			return Editor() ;
+		}
+	}
+
+	return retval ;
+})() ;
+
+// Export some packaged functions for use in the inner dialog code.
+(function ExportAPI()
+{	
+	var APIs = [
+		[ Main, 'InnerDialogLoaded' ],
+		[ Sizer, 'SetAutoSize' ]
+	] ;
+	for ( var i = 0 ; i < APIs.length ; i++ )
+		window[APIs[i][1]] = FCKTools.Hitch( APIs[i][0], APIs[i][1] ) ;
+})() ;
 		</script>
 		<!-- script type="text/javascript">
@@ -763,10 +1081,10 @@
 		</script -->
 	</head>
-	<body onload="" class="DialogBody">
+	<body onload="Main.Init();" class="DialogBody">
 		<div class="contents" id="contents">
 			<div id="header">
 				<div id="TitleArea" class="DialogTitle DialogTitleBorder">
 					<script type="text/javascript">
-// document.write( args.Title ) ;
+document.write( Args().Title ) ;
 					</script>
 					<div id="closeButton" onclick="Cancel();"></div>
@@ -805,13 +1123,12 @@
 		<div class="cover" id="cover" style="display:none"></div>
 		<div id="throbberBlock" style="position: absolute; z-index: 10; text-align: center; font-size: 9px;"></div>
-		<!-- script type="text/javascript">
+		<script type="text/javascript">
 			// Set the class name for language direction.
-			document.body.className += ' ' + editor.FCKLang.Dir ;
-
-			var cover = document.getElementById( 'cover' ) ;
+			document.body.className += ' ' + Editor().FCKLang.Dir ;
+
+			var cover = $( 'cover' ) ;
 			cover.style.backgroundColor = FCKConfig.BackgroundBlockerColor ;
 			FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ;
-			alert( 'I am not running this!' ) ;
-		</script -->
+		</script>
 	</body>
 </html>
Index: /FCKeditor/branches/features/floating_dialog/test_results
===================================================================
--- /FCKeditor/branches/features/floating_dialog/test_results	(revision 1250)
+++ /FCKeditor/branches/features/floating_dialog/test_results	(revision 1251)
@@ -1,3 +1,3 @@
-Methodology: Open the FCKDialog leak test for at least 3 minutes, see if the memory usage plataus or increases.
+Methodology: Open the FCKDialog leak test for at least 3 minutes in IE6, see if the memory usage plataus or increases.
 
 Tests:
@@ -7,2 +7,4 @@
 4. Added window.focus(), fck_dialog.css, and language direction/No noticeable increase after 10 minutes.
 5. Added fck_dialog_ie6.js/Steadily increasing memory usage
+6. Added Init(), Throbber(), ResizeContainerSize()/No noticeable increase after 10 minutes. 
+7. Added all resize logic, LoadInnerDialog() and InnerDialogLoaded(), created the Sizer and Main modules/No noticeable increase after 10 minutes.
