+\r
+/**\r
+ * Create a two-dimension array that reflects the actual layout of table cells,\r
+ * with cell spans, with mappings to the original td elements.\r
+ * @param table {CKEDITOR.dom.element}\r
+ */\r
+CKEDITOR.tools.buildTableMap = function ( table )\r
+{\r
+ var aRows = table.$.rows ;\r
+\r
+ // Row and Column counters.\r
+ var r = -1 ;\r
+\r
+ var aMap = [];\r
+\r
+ for ( var i = 0 ; i < aRows.length ; i++ )\r
+ {\r
+ r++ ;\r
+ !aMap[r] && ( aMap[r] = [] );\r
+\r
+ var c = -1 ;\r
+\r
+ for ( var j = 0 ; j < aRows[i].cells.length ; j++ )\r
+ {\r
+ var oCell = aRows[i].cells[j] ;\r
+\r
+ c++ ;\r
+ while ( aMap[r][c] )\r
+ c++ ;\r
+\r
+ var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ;\r
+ var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ;\r
+\r
+ for ( var rs = 0 ; rs < iRowSpan ; rs++ )\r
+ {\r
+ if ( !aMap[r + rs] )\r
+ aMap[r + rs] = [];\r
+\r
+ for ( var cs = 0 ; cs < iColSpan ; cs++ )\r
+ {\r
+ aMap[r + rs][c + cs] = aRows[i].cells[j] ;\r
+ }\r
+ }\r
+\r
+ c += iColSpan - 1 ;\r
+ }\r
+ }\r
+ return aMap ;\r
+};\r