Index: /FCKeditor/branches/developers/martinkou/editor/plugins/dragresizetable/fckplugin.js
===================================================================
--- /FCKeditor/branches/developers/martinkou/editor/plugins/dragresizetable/fckplugin.js	(revision 470)
+++ /FCKeditor/branches/developers/martinkou/editor/plugins/dragresizetable/fckplugin.js	(revision 471)
@@ -7,4 +7,7 @@
 	"_ResizeBar" : null,
 	"_OriginalX" : null,
+	"_MinimumX" : null,
+	"_MaximumX" : null,
+	"_LastX" : null,
 	"_GetWindowScrollX" : function( w )
 	{
@@ -110,4 +113,17 @@
 		return { "leftCell" : rbCell, "rightCell" : lbCell } ;
 	},
+	"_GetResizeBarPosition" : function()
+	{
+		var row = FCKTools.GetElementAscensor( this._LeftCell, "tr" ) ;
+		var colIndex = 0 ;
+		for ( var i = 0 ; i <= this._LeftCell.cellIndex ; i++ )
+		{
+			var colSpan = parseInt( row.cells.item( i ).colSpan ) ;
+			if ( colSpan != colSpan )
+				colSpan = 1 ;
+			colIndex += colSpan ;
+		}
+		return colIndex ;
+	},
 	"_ResizeBarMouseDownListener" : function( evt )
 	{
@@ -121,4 +137,38 @@
 			FCKDragTableHandler._ResizeBar.style.opacity = 0.5 ;
 		FCKDragTableHandler._OriginalX = evt.clientX ;
+
+		// TODO: calculate maximum and minimum x-coordinate delta.
+		var borderIndex = FCKDragTableHandler._GetResizeBarPosition() ;
+		var offset = FCKDragTableHandler._GetDocumentPosition( window, FCK.EditingArea.IFrame ) ;
+		var table = FCKTools.GetElementAscensor( FCKDragTableHandler._LeftCell, "table" );
+		var minX = null ;
+		var maxX = null ;
+		for ( var r = 0 ; r < table.rows.length ; r++ )
+		{
+			var row = table.rows.item( r ) ;
+			var colIndex = 0 ;
+			for ( var c = 0 ; c < row.cells.length ; c++ )
+			{
+				var cell = row.cells.item( c ) ;
+				var cellPosition = FCKDragTableHandler._GetWindowPosition( FCK.EditorWindow, cell ) ;
+				var cellPadding = FCKDragTableHandler._GetCellPadding( table, cell ) ;
+				var cellMinX = cellPosition.x + cellPadding ;
+				var cellMaxX = cellPosition.x + cell.clientWidth - cellPadding ;
+				if ( colIndex < borderIndex )
+				{
+					if ( minX == null || cellMinX > minX )
+						minX = cellMinX ;
+				}
+				else
+				{
+					if ( maxX == null || cellMaxX < maxX )
+						maxX = cellMaxX ;
+				}
+				colIndex += cell.colSpan ;
+			}
+		}
+		FCKDragTableHandler._MinimumX = minX + offset.x ;
+		FCKDragTableHandler._MaximumX = maxX + offset.x ;
+		FCKDragTableHandler._LastX = null ;
 	},
 	"_ResizeBarMouseUpListener" : function( evt )
@@ -127,21 +177,11 @@
 			evt = window.event ;
 		FCKDragTableHandler._MouseMoveMode = 0 ;
-		FCKDragTableHandler._HideResizeBar.apply( FCKDragTableHandler, [] ) ;
+		FCKDragTableHandler._HideResizeBar() ;
 		
-		if ( ! FCKDragTableHandler._LeftCell )
+		if ( FCKDragTableHandler._LastX == null )
 			return ;
 		
-		// First, get the mouse coordiantes relative to the outer window, and calculate the delta value.
-		var mouse = { "x" : evt.clientX, "y" : evt.clientY } ;
-		var mouseNode = evt.srcElement || evt.originalTarget ;
-		var mouseDocument = mouseNode.ownerDocument ;
-		if ( mouseDocument == FCK.EditorDocument )
-		{
-			var offset = FCKDragTableHandler._GetDocumentPosition.apply( FCKDragTableHandler, 
-					[ window, FCK.EditingArea.IFrame ] ) ;
-			mouse.x += offset.x ;
-			mouse.y += offset.y ;
-		}
-		var deltaX = mouse.x - FCKDragTableHandler._OriginalX ;
+		// Calculate the delta value.
+		var deltaX = FCKDragTableHandler._LastX - FCKDragTableHandler._OriginalX ;
 
 		// Then, build an array of current column width values.
@@ -156,5 +196,5 @@
 			{
 				var cell = row.cells.item( c ) ;
-				var width = FCKDragTableHandler._GetCellWidth.apply( FCKDragTableHandler, [ table, cell ] ) ;
+				var width = FCKDragTableHandler._GetCellWidth( table, cell ) ;
 				var colSpan = parseInt( cell.colSpan ) ;
 				if ( colSpan != colSpan )
@@ -182,13 +222,5 @@
 
 		// Find out the equivalent column index of the two cells selected for resizing.
-		var row = FCKTools.GetElementAscensor( FCKDragTableHandler._LeftCell, "tr" ) ;
-		var colIndex = 0 ;
-		for ( var i = 0 ; i <= FCKDragTableHandler._LeftCell.cellIndex ; i++ )
-		{
-			var colSpan = parseInt( row.cells.item( i ).colSpan ) ;
-			if ( colSpan != colSpan )
-				colSpan = 1 ;
-			colIndex += colSpan ;
-		}
+		colIndex = FCKDragTableHandler._GetResizeBarPosition() ;
 
 		// Note that colIndex must be at least 1 here, so it's safe to subtract 1 from it.
@@ -228,8 +260,16 @@
 				for ( var i = colIndex ; i < colIndex + colSpan ; i++ )
 					cellWidth += colArray[i].width ;
-				cell.width = cellWidth ;
+				try
+				{
+					cell.width = cellWidth ;
+				}
+				catch(e)	
+				{				
+				}
 				colIndex += colSpan ;
 			}
 		}
+
+		FCKDragTableHandler._LastX = null ;
 	},
 	"_ResizeBarMouseMoveListener" : function( evt )
@@ -238,7 +278,7 @@
 			evt = window.event ;		
 		if ( FCKDragTableHandler._MouseMoveMode == 0 )
-			return FCKDragTableHandler._MouseFindHandler.apply( FCKDragTableHandler, [ FCK, evt ] ) ;
-		else
-			return FCKDragTableHandler._MouseDragHandler.apply( FCKDragTableHandler, [ FCK, evt ] ) ;
+			return FCKDragTableHandler._MouseFindHandler( FCK, evt ) ;
+		else
+			return FCKDragTableHandler._MouseDragHandler( FCK, evt ) ;
 	},
 	// Calculate the padding of a table cell.
@@ -298,6 +338,4 @@
 		if ( FCKDragTableHandler._MouseMoveMode == 0 )
 			return FCKDragTableHandler._MouseFindHandler( FCK, evt ) ;
-		else
-			return FCKDragTableHandler._MouseDragHandler( FCK, evt ) ;
 	},
 	"_MouseFindHandler" : function( FCK, evt )
@@ -383,17 +421,13 @@
 		var mouse = { "x" : evt.clientX, "y" : evt.clientY } ;
 
-		// Check if the mouse cursor is still inside the table's area.
-		var table = FCKTools.GetElementAscensor( this._LeftCell, "table" );
-		var offset = this._GetDocumentPosition( window, FCK.EditingArea.IFrame ) ;
-		var innerMouse = { "x" : mouse.x - offset.x, "y" : mouse.y - offset.y } ;
-		if ( ! this._IsInsideNode( FCK.EditorWindow, table, innerMouse ) ) 
-		{
-			this._MouseMoveMode = 0 ;
-			this._HideResizeBar() ;
-			return ;
-		}
+		// TODO: calculate the mouse position delta and see if we've gone out of range.
+		if ( mouse.x >= this._MaximumX - 5 )
+			mouse.x = this._MaximumX - 5 ;
+		if ( mouse.x <= this._MinimumX + 5 ) 
+			mouse.x = this._MinimumX + 5 ;
 
 		var docX = mouse.x + this._GetWindowScrollX( window ) ;
 		this._ResizeBar.style.left = ( docX - this._ResizeBar.offsetWidth / 2 ) + "px" ;
+		this._LastX = mouse.x ;
 	},
 	"_ShowResizeBar" : function( w, table, mouse )
