Upgrade TinyMCE to v3.4.5
[citadel.git] / webcit / tiny_mce / plugins / inlinepopups / editor_plugin_src.js
index 2aa231cdb25019aad52dbcf3c1229f8b7805015e..67123ca3142ec46384858fda1a641ed6d2401700 100644 (file)
 /**\r
- * $RCSfile: editor_plugin_src.js,v $\r
- * $Revision: 1.2 $\r
- * $Date: 2005/09/26 18:00:52 $\r
+ * editor_plugin_src.js\r
  *\r
- * Moxiecode DHTML Windows script.\r
+ * Copyright 2009, Moxiecode Systems AB\r
+ * Released under LGPL License.\r
  *\r
- * @author Moxiecode\r
- * @copyright Copyright © 2004, Moxiecode Systems AB, All rights reserved.\r
+ * License: http://tinymce.moxiecode.com/license\r
+ * Contributing: http://tinymce.moxiecode.com/contributing\r
  */\r
 \r
-// Patch openWindow, closeWindow TinyMCE functions\r
-\r
-function TinyMCE_inlinepopups_getInfo() {\r
-       return {\r
-               longname : 'Inline Popups',\r
-               author : 'Moxiecode Systems',\r
-               authorurl : 'http://tinymce.moxiecode.com',\r
-               infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_inlinepopups.html',\r
-               version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
-       };\r
-};\r
-\r
-TinyMCE.prototype.orgOpenWindow = TinyMCE.prototype.openWindow;\r
-\r
-TinyMCE.prototype.openWindow = function(template, args) {\r
-       // Does the caller support inline\r
-       if (args['inline'] != "yes") {\r
-               mcWindows.selectedWindow = null;\r
-               args['mce_inside_iframe'] = false;\r
-               this.orgOpenWindow(template, args);\r
-               return;\r
-       }\r
-\r
-       var url, resizable, scrollbars;\r
-\r
-       args['mce_inside_iframe'] = true;\r
-       tinyMCE.windowArgs = args;\r
-\r
-       if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)\r
-               url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];\r
-       else\r
-               url = template['file'];\r
-\r
-       if (!(width = parseInt(template['width'])))\r
-               width = 320;\r
-\r
-       if (!(height = parseInt(template['height'])))\r
-               height = 200;\r
-\r
-       resizable = (args && args['resizable']) ? args['resizable'] : "no";\r
-       scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";\r
-\r
-       height += 18;\r
-\r
-       // Replace all args as variables in URL\r
-       for (var name in args) {\r
-               if (typeof(args[name]) == 'function')\r
-                       continue;\r
-\r
-               url = tinyMCE.replaceVar(url, name, escape(args[name]));\r
-       }\r
-\r
-       var elm = document.getElementById(this.selectedInstance.editorId + '_parent');\r
-       var pos = tinyMCE.getAbsPosition(elm);\r
-\r
-       // Center div in editor area\r
-       pos.absLeft += Math.round((elm.firstChild.clientWidth / 2) - (width / 2));\r
-       pos.absTop += Math.round((elm.firstChild.clientHeight / 2) - (height / 2));\r
-\r
-       mcWindows.open(url, mcWindows.idCounter++, "modal=yes,width=" + width+ ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",statusbar=" + resizable + ",left=" + pos.absLeft + ",top=" + pos.absTop);\r
-};\r
-\r
-TinyMCE.prototype.orgCloseWindow = TinyMCE.prototype.closeWindow;\r
-\r
-TinyMCE.prototype.closeWindow = function(win) {\r
-       if (mcWindows.selectedWindow != null)\r
-               mcWindows.selectedWindow.close();\r
-       else\r
-               this.orgCloseWindow(win);\r
-};\r
-\r
-TinyMCE.prototype.setWindowTitle = function(win_ref, title) {\r
-       for (var n in mcWindows.windows) {\r
-               var win = mcWindows.windows[n];\r
-               if (typeof(win) == 'function')\r
-                       continue;\r
-\r
-               if (win_ref.name == win.id + "_iframe")\r
-                       window.frames[win.id + "_iframe"].document.getElementById(win.id + '_title').innerHTML = title;\r
-       }\r
-};\r
-\r
-// * * * * * MCWindows classes below\r
-\r
-// Windows handler\r
-function MCWindows() {\r
-       this.settings = new Array();\r
-       this.windows = new Array();\r
-       this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");\r
-       this.isGecko = navigator.userAgent.indexOf('Gecko') != -1;\r
-       this.isSafari = navigator.userAgent.indexOf('Safari') != -1;\r
-       this.isMac = navigator.userAgent.indexOf('Mac') != -1;\r
-       this.isMSIE5_0 = this.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1);\r
-       this.action = "none";\r
-       this.selectedWindow = null;\r
-       this.lastSelectedWindow = null;\r
-       this.zindex = 100;\r
-       this.mouseDownScreenX = 0;\r
-       this.mouseDownScreenY = 0;\r
-       this.mouseDownLayerX = 0;\r
-       this.mouseDownLayerY = 0;\r
-       this.mouseDownWidth = 0;\r
-       this.mouseDownHeight = 0;\r
-       this.idCounter = 0;\r
-};\r
-\r
-MCWindows.prototype.init = function(settings) {\r
-       this.settings = settings;\r
-\r
-       if (this.isMSIE)\r
-               this.addEvent(document, "mousemove", mcWindows.eventDispatcher);\r
-       else\r
-               this.addEvent(window, "mousemove", mcWindows.eventDispatcher);\r
-\r
-       this.addEvent(document, "mouseup", mcWindows.eventDispatcher);\r
-\r
-       this.doc = document;\r
-};\r
-\r
-MCWindows.prototype.getParam = function(name, default_value) {\r
-       var value = null;\r
-\r
-       value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];\r
-\r
-       // Fix bool values\r
-       if (value == "true" || value == "false")\r
-               return (value == "true");\r
-\r
-       return value;\r
-};\r
-\r
-MCWindows.prototype.eventDispatcher = function(e) {\r
-       e = typeof(e) == "undefined" ? window.event : e;\r
-\r
-       if (mcWindows.selectedWindow == null)\r
-               return;\r
-\r
-       // Switch focus\r
-       if (mcWindows.isGecko && e.type == "mousedown") {\r
-               var elm = e.currentTarget;\r
-\r
-               for (var n in mcWindows.windows) {\r
-                       var win = mcWindows.windows[n];\r
-\r
-                       if (win.headElement == elm || win.resizeElement == elm) {\r
-                               win.focus();\r
-                               break;\r
-                       }\r
+(function() {\r
+       var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;\r
+\r
+       tinymce.create('tinymce.plugins.InlinePopups', {\r
+               init : function(ed, url) {\r
+                       // Replace window manager\r
+                       ed.onBeforeRenderUI.add(function() {\r
+                               ed.windowManager = new tinymce.InlineWindowManager(ed);\r
+                               DOM.loadCSS(url + '/skins/' + (ed.settings.inlinepopups_skin || 'clearlooks2') + "/window.css");\r
+                       });\r
+               },\r
+\r
+               getInfo : function() {\r
+                       return {\r
+                               longname : 'InlinePopups',\r
+                               author : 'Moxiecode Systems AB',\r
+                               authorurl : 'http://tinymce.moxiecode.com',\r
+                               infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',\r
+                               version : tinymce.majorVersion + "." + tinymce.minorVersion\r
+                       };\r
                }\r
-       }\r
-\r
-       switch (e.type) {\r
-               case "mousemove":\r
-                       mcWindows.selectedWindow.onMouseMove(e);\r
-                       break;\r
-\r
-               case "mouseup":\r
-                       mcWindows.selectedWindow.onMouseUp(e);\r
-                       break;\r
-\r
-               case "mousedown":\r
-                       mcWindows.selectedWindow.onMouseDown(e);\r
-                       break;\r
-\r
-               case "focus":\r
-                       mcWindows.selectedWindow.onFocus(e);\r
-                       break;\r
-       }\r
-};\r
-\r
-MCWindows.prototype.addEvent = function(obj, name, handler) {\r
-       if (this.isMSIE)\r
-               obj.attachEvent("on" + name, handler);\r
-       else\r
-               obj.addEventListener(name, handler, true);\r
-};\r
-\r
-MCWindows.prototype.cancelEvent = function(e) {\r
-       if (this.isMSIE) {\r
-               e.returnValue = false;\r
-               e.cancelBubble = true;\r
-       } else\r
-               e.preventDefault();\r
-};\r
-\r
-MCWindows.prototype.parseFeatures = function(opts) {\r
-       // Cleanup the options\r
-       opts = opts.toLowerCase();\r
-       opts = opts.replace(/;/g, ",");\r
-       opts = opts.replace(/[^0-9a-z=,]/g, "");\r
-\r
-       var optionChunks = opts.split(',');\r
-       var options = new Array();\r
-\r
-       options['left'] = "10";\r
-       options['top'] = "10";\r
-       options['width'] = "300";\r
-       options['height'] = "300";\r
-       options['resizable'] = "yes";\r
-       options['minimizable'] = "yes";\r
-       options['maximizable'] = "yes";\r
-       options['close'] = "yes";\r
-       options['movable'] = "yes";\r
-       options['statusbar'] = "yes";\r
-       options['scrollbars'] = "auto";\r
-       options['modal'] = "no";\r
-\r
-       if (opts == "")\r
-               return options;\r
-\r
-       for (var i=0; i<optionChunks.length; i++) {\r
-               var parts = optionChunks[i].split('=');\r
-\r
-               if (parts.length == 2)\r
-                       options[parts[0]] = parts[1];\r
-       }\r
-\r
-       options['left'] = parseInt(options['left']);\r
-       options['top'] = parseInt(options['top']);\r
-       options['width'] = parseInt(options['width']);\r
-       options['height'] = parseInt(options['height']);\r
-\r
-       return options;\r
-};\r
-\r
-MCWindows.prototype.open = function(url, name, features) {\r
-       this.lastSelectedWindow = this.selectedWindow;\r
-\r
-       var win = new MCWindow();\r
-       var winDiv, html = "", id;\r
-       var imgPath = this.getParam("images_path");\r
-\r
-       features = this.parseFeatures(features);\r
-\r
-       // Create div\r
-       id = "mcWindow_" + name;\r
-       win.deltaHeight = 18;\r
-\r
-       if (features['statusbar'] == "yes") {\r
-               win.deltaHeight += 13;\r
-\r
-               if (this.isMSIE)\r
-                       win.deltaHeight += 1;\r
-       }\r
-\r
-       width = parseInt(features['width']);\r
-       height = parseInt(features['height'])-win.deltaHeight;\r
-\r
-       if (this.isMSIE)\r
-               width -= 2;\r
-\r
-       // Setup first part of window\r
-       win.id = id;\r
-       win.url = url;\r
-       win.name = name;\r
-       win.features = features;\r
-       this.windows[name] = win;\r
-\r
-       iframeWidth = width;\r
-       iframeHeight = height;\r
-\r
-       // Create inner content\r
-       html += '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';\r
-       html += '<html>';\r
-       html += '<head>';\r
-       html += '<title>Wrapper iframe</title>';\r
-       html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';\r
-       html += '<link href="' + this.getParam("css_file") + '" rel="stylesheet" type="text/css" />';\r
-       html += '</head>';\r
-       html += '<body onload="parent.mcWindows.onLoad(\'' + name + '\');">';\r
-\r
-       html += '<div id="' + id + '_container" class="mceWindow">';\r
-       html += '<div id="' + id + '_head" class="mceWindowHead" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';\r
-       html += '  <div id="' + id + '_title" class="mceWindowTitle"';\r
-       html += '  onselectstart="return false;" unselectable="on" style="-moz-user-select: none !important;"></div>';\r
-       html += '    <div class="mceWindowHeadTools">';\r
-       html += '      <a href="javascript:parent.mcWindows.windows[\'' + name + '\'].close();" target="_self" onmousedown="return false;" class="mceWindowClose"><img border="0" src="' + imgPath + '/window_close.gif" /></a>';\r
-//     html += '      <a href="javascript:mcWindows.windows[\'' + name + '\'].maximize();" target="_self" onmousedown="return false;" class="mceWindowMaximize"></a>';\r
-//     html += '      <a href="javascript:mcWindows.windows[\'' + name + '\'].minimize();" target="_self" onmousedown="return false;" class="mceWindowMinimize"></a>';\r
-       html += '    </div>';\r
-       html += '</div><div id="' + id + '_body" class="mceWindowBody" style="width: ' + width + 'px; height: ' + height + 'px;">';\r
-       html += '<iframe id="' + id + '_iframe" name="' + id + '_iframe" frameborder="0" width="' + iframeWidth + '" height="' + iframeHeight + '" src="' + url + '" class="mceWindowBodyIframe" scrolling="' + features['scrollbars'] + '"></iframe></div>';\r
-\r
-       if (features['statusbar'] == "yes") {\r
-               html += '<div id="' + id + '_statusbar" class="mceWindowStatusbar" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';\r
-\r
-               if (features['resizable'] == "yes") {\r
-                       if (this.isGecko)\r
-                               html += '<div id="' + id + '_resize" class="mceWindowResize"><div style="background-image: url(\'' + imgPath + '/window_resize.gif\'); width: 12px; height: 12px;"></div></div>';\r
-                       else\r
-                               html += '<div id="' + id + '_resize" class="mceWindowResize"><img onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();" border="0" src="' + imgPath + '/window_resize.gif" /></div>';\r
-               }\r
-\r
-               html += '</div>';\r
-       }\r
+       });\r
 \r
-       html += '</div>';\r
+       tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {\r
+               InlineWindowManager : function(ed) {\r
+                       var t = this;\r
 \r
-       html += '</body>';\r
-       html += '</html>';\r
+                       t.parent(ed);\r
+                       t.zIndex = 300000;\r
+                       t.count = 0;\r
+                       t.windows = {};\r
+               },\r
 \r
-       // Create iframe\r
-       this.createFloatingIFrame(id, features['left'], features['top'], features['width'], features['height'], html);\r
-};\r
+               open : function(f, p) {\r
+                       var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u, parentWindow;\r
 \r
-// Blocks the document events by placing a image over the whole document\r
-MCWindows.prototype.setDocumentLock = function(state) {\r
-       if (state) {\r
-               var elm = document.getElementById('mcWindowEventBlocker');\r
-               if (elm == null) {\r
-                       elm = document.createElement("div");\r
+                       f = f || {};\r
+                       p = p || {};\r
 \r
-                       elm.id = "mcWindowEventBlocker";\r
-                       elm.style.position = "absolute";\r
-                       elm.style.left = "0px";\r
-                       elm.style.top = "0px";\r
+                       // Run native windows\r
+                       if (!f.inline)\r
+                               return t.parent(f, p);\r
 \r
-                       document.body.appendChild(elm);\r
-               }\r
-\r
-               elm.style.display = "none";\r
-\r
-               var imgPath = this.getParam("images_path");\r
-               var width = document.body.clientWidth;\r
-               var height = document.body.clientHeight;\r
-\r
-               elm.style.width = width;\r
-               elm.style.height = height;\r
-               elm.innerHTML = '<img src="' + imgPath + '/spacer.gif" width="' + width + '" height="' + height + '" />';\r
-\r
-               elm.style.zIndex = mcWindows.zindex-1;\r
-               elm.style.display = "block";\r
-       } else {\r
-               var elm = document.getElementById('mcWindowEventBlocker');\r
-\r
-               if (mcWindows.windows.length == 0)\r
-                       elm.parentNode.removeChild(elm);\r
-               else\r
-                       elm.style.zIndex = mcWindows.zindex-1;\r
-       }\r
-};\r
-\r
-// Gets called when wrapper iframe is initialized\r
-MCWindows.prototype.onLoad = function(name) {\r
-       var win = mcWindows.windows[name];\r
-       var id = "mcWindow_" + name;\r
-       var wrapperIframe = window.frames[id + "_iframe"].frames[0];\r
-       var wrapperDoc = window.frames[id + "_iframe"].document;\r
-       var doc = window.frames[id + "_iframe"].document;\r
-       var winDiv = document.getElementById("mcWindow_" + name + "_div");\r
-       var realIframe = window.frames[id + "_iframe"].frames[0];\r
-\r
-       // Set window data\r
-       win.id = "mcWindow_" + name;\r
-       win.winElement = winDiv;\r
-       win.bodyElement = doc.getElementById(id + '_body');\r
-       win.iframeElement = doc.getElementById(id + '_iframe');\r
-       win.headElement = doc.getElementById(id + '_head');\r
-       win.titleElement = doc.getElementById(id + '_title');\r
-       win.resizeElement = doc.getElementById(id + '_resize');\r
-       win.containerElement = doc.getElementById(id + '_container');\r
-       win.left = win.features['left'];\r
-       win.top = win.features['top'];\r
-       win.frame = window.frames[id + '_iframe'].frames[0];\r
-       win.wrapperFrame = window.frames[id + '_iframe'];\r
-       win.wrapperIFrameElement = document.getElementById(id + "_iframe");\r
-\r
-       // Add event handlers\r
-       mcWindows.addEvent(win.headElement, "mousedown", mcWindows.eventDispatcher);\r
-\r
-       if (win.resizeElement != null)\r
-               mcWindows.addEvent(win.resizeElement, "mousedown", mcWindows.eventDispatcher);\r
-\r
-       if (mcWindows.isMSIE) {\r
-               mcWindows.addEvent(realIframe.document, "mousemove", mcWindows.eventDispatcher);\r
-               mcWindows.addEvent(realIframe.document, "mouseup", mcWindows.eventDispatcher);\r
-       } else {\r
-               mcWindows.addEvent(realIframe, "mousemove", mcWindows.eventDispatcher);\r
-               mcWindows.addEvent(realIframe, "mouseup", mcWindows.eventDispatcher);\r
-               mcWindows.addEvent(realIframe, "focus", mcWindows.eventDispatcher);\r
-       }\r
-\r
-       for (var i=0; i<window.frames.length; i++) {\r
-               if (!window.frames[i]._hasMouseHandlers) {\r
-                       if (mcWindows.isMSIE) {\r
-                               mcWindows.addEvent(window.frames[i].document, "mousemove", mcWindows.eventDispatcher);\r
-                               mcWindows.addEvent(window.frames[i].document, "mouseup", mcWindows.eventDispatcher);\r
-                       } else {\r
-                               mcWindows.addEvent(window.frames[i], "mousemove", mcWindows.eventDispatcher);\r
-                               mcWindows.addEvent(window.frames[i], "mouseup", mcWindows.eventDispatcher);\r
+                       parentWindow = t._frontWindow();\r
+                       if (parentWindow && DOM.get(parentWindow.id + '_ifr')) {\r
+                               parentWindow.focussedElement = DOM.get(parentWindow.id + '_ifr').contentWindow.document.activeElement;\r
+                       }\r
+                       \r
+                       // Only store selection if the type is a normal window\r
+                       if (!f.type)\r
+                               t.bookmark = ed.selection.getBookmark(1);\r
+\r
+                       id = DOM.uniqueId();\r
+                       vp = DOM.getViewPort();\r
+                       f.width = parseInt(f.width || 320);\r
+                       f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);\r
+                       f.min_width = parseInt(f.min_width || 150);\r
+                       f.min_height = parseInt(f.min_height || 100);\r
+                       f.max_width = parseInt(f.max_width || 2000);\r
+                       f.max_height = parseInt(f.max_height || 2000);\r
+                       f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0)));\r
+                       f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0)));\r
+                       f.movable = f.resizable = true;\r
+                       p.mce_width = f.width;\r
+                       p.mce_height = f.height;\r
+                       p.mce_inline = true;\r
+                       p.mce_window_id = id;\r
+                       p.mce_auto_focus = f.auto_focus;\r
+\r
+                       // Transpose\r
+//                     po = DOM.getPos(ed.getContainer());\r
+//                     f.left -= po.x;\r
+//                     f.top -= po.y;\r
+\r
+                       t.features = f;\r
+                       t.params = p;\r
+                       t.onOpen.dispatch(t, f, p);\r
+\r
+                       if (f.type) {\r
+                               opt += ' mceModal';\r
+\r
+                               if (f.type)\r
+                                       opt += ' mce' + f.type.substring(0, 1).toUpperCase() + f.type.substring(1);\r
+\r
+                               f.resizable = false;\r
                        }\r
 \r
-                       window.frames[i]._hasMouseHandlers = true;\r
-               }\r
-       }\r
-\r
-       if (mcWindows.isMSIE) {\r
-               mcWindows.addEvent(win.frame.document, "mousemove", mcWindows.eventDispatcher);\r
-               mcWindows.addEvent(win.frame.document, "mouseup", mcWindows.eventDispatcher);\r
-       } else {\r
-               mcWindows.addEvent(win.frame, "mousemove", mcWindows.eventDispatcher);\r
-               mcWindows.addEvent(win.frame, "mouseup", mcWindows.eventDispatcher);\r
-               mcWindows.addEvent(win.frame, "focus", mcWindows.eventDispatcher);\r
-       }\r
-\r
-       // Dispatch open window event\r
-       var func = this.getParam("on_open_window", "");\r
-       if (func != "")\r
-               eval(func + "(win);");\r
-\r
-       win.focus();\r
-\r
-       if (win.features['modal'] == "yes")\r
-               mcWindows.setDocumentLock(true);\r
-};\r
-\r
-MCWindows.prototype.createFloatingIFrame = function(id_prefix, left, top, width, height, html) {\r
-       var iframe = document.createElement("iframe");\r
-       var div = document.createElement("div");\r
-\r
-       width = parseInt(width);\r
-       height = parseInt(height)+1;\r
-\r
-       // Create wrapper div\r
-       div.setAttribute("id", id_prefix + "_div");\r
-       div.setAttribute("width", width);\r
-       div.setAttribute("height", (height));\r
-       div.style.position = "absolute";\r
-       div.style.left = left + "px";\r
-       div.style.top = top + "px";\r
-       div.style.width = width + "px";\r
-       div.style.height = (height) + "px";\r
-       div.style.backgroundColor = "white";\r
-       div.style.display = "none";\r
-\r
-       if (this.isGecko) {\r
-               iframeWidth = width + 2;\r
-               iframeHeight = height + 2;\r
-       } else {\r
-               iframeWidth = width;\r
-               iframeHeight = height + 1;\r
-       }\r
-\r
-       // Create iframe\r
-       iframe.setAttribute("id", id_prefix + "_iframe");\r
-       iframe.setAttribute("name", id_prefix + "_iframe");\r
-       iframe.setAttribute("border", "0");\r
-       iframe.setAttribute("frameBorder", "0");\r
-       iframe.setAttribute("marginWidth", "0");\r
-       iframe.setAttribute("marginHeight", "0");\r
-       iframe.setAttribute("leftMargin", "0");\r
-       iframe.setAttribute("topMargin", "0");\r
-       iframe.setAttribute("width", iframeWidth);\r
-       iframe.setAttribute("height", iframeHeight);\r
-//     iframe.setAttribute("src", "../jscripts/tiny_mce/blank.htm");\r
-       // iframe.setAttribute("allowtransparency", "false");\r
-       iframe.setAttribute("scrolling", "no");\r
-       iframe.style.width = iframeWidth + "px";\r
-       iframe.style.height = iframeHeight + "px";\r
-       iframe.style.backgroundColor = "white";\r
-       div.appendChild(iframe);\r
-\r
-       document.body.appendChild(div);\r
-\r
-       // Fixed MSIE 5.0 issue\r
-       div.innerHTML = div.innerHTML;\r
-\r
-       if (this.isSafari) {\r
-               // Give Safari some time to setup\r
-               window.setTimeout(function() {\r
-                       doc = window.frames[id_prefix + '_iframe'].document;\r
-                       doc.open();\r
-                       doc.write(html);\r
-                       doc.close();\r
-               }, 10);\r
-       } else {\r
-               doc = window.frames[id_prefix + '_iframe'].window.document;\r
-               doc.open();\r
-               doc.write(html);\r
-               doc.close();\r
-       }\r
-\r
-       div.style.display = "block";\r
-\r
-       return div;\r
-};\r
-\r
-// Window instance\r
-function MCWindow() {\r
-};\r
-\r
-MCWindow.prototype.focus = function() {\r
-       if (this != mcWindows.selectedWindow) {\r
-               this.winElement.style.zIndex = ++mcWindows.zindex;\r
-               mcWindows.lastSelectedWindow = mcWindows.selectedWindow;\r
-               mcWindows.selectedWindow = this;\r
-       }\r
-};\r
-\r
-MCWindow.prototype.minimize = function() {\r
-};\r
-\r
-MCWindow.prototype.maximize = function() {\r
-       \r
-};\r
-\r
-MCWindow.prototype.startResize = function() {\r
-       mcWindows.action = "resize";\r
-};\r
+                       if (f.statusbar)\r
+                               opt += ' mceStatusbar';\r
+\r
+                       if (f.resizable)\r
+                               opt += ' mceResizable';\r
+\r
+                       if (f.minimizable)\r
+                               opt += ' mceMinimizable';\r
+\r
+                       if (f.maximizable)\r
+                               opt += ' mceMaximizable';\r
+\r
+                       if (f.movable)\r
+                               opt += ' mceMovable';\r
+\r
+                       // Create DOM objects\r
+                       t._addAll(DOM.doc.body, \r
+                               ['div', {id : id, role : 'dialog', 'aria-labelledby': f.type ? id + '_content' : id + '_title', 'class' : (ed.settings.inlinepopups_skin || 'clearlooks2') + (tinymce.isIE && window.getSelection ? ' ie9' : ''), style : 'width:100px;height:100px'}, \r
+                                       ['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt},\r
+                                               ['div', {id : id + '_top', 'class' : 'mceTop'}, \r
+                                                       ['div', {'class' : 'mceLeft'}],\r
+                                                       ['div', {'class' : 'mceCenter'}],\r
+                                                       ['div', {'class' : 'mceRight'}],\r
+                                                       ['span', {id : id + '_title'}, f.title || '']\r
+                                               ],\r
+\r
+                                               ['div', {id : id + '_middle', 'class' : 'mceMiddle'}, \r
+                                                       ['div', {id : id + '_left', 'class' : 'mceLeft', tabindex : '0'}],\r
+                                                       ['span', {id : id + '_content'}],\r
+                                                       ['div', {id : id + '_right', 'class' : 'mceRight', tabindex : '0'}]\r
+                                               ],\r
+\r
+                                               ['div', {id : id + '_bottom', 'class' : 'mceBottom'},\r
+                                                       ['div', {'class' : 'mceLeft'}],\r
+                                                       ['div', {'class' : 'mceCenter'}],\r
+                                                       ['div', {'class' : 'mceRight'}],\r
+                                                       ['span', {id : id + '_status'}, 'Content']\r
+                                               ],\r
+\r
+                                               ['a', {'class' : 'mceMove', tabindex : '-1', href : 'javascript:;'}],\r
+                                               ['a', {'class' : 'mceMin', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],\r
+                                               ['a', {'class' : 'mceMax', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],\r
+                                               ['a', {'class' : 'mceMed', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],\r
+                                               ['a', {'class' : 'mceClose', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],\r
+                                               ['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', tabindex : '-1', href : 'javascript:;'}],\r
+                                               ['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', tabindex : '-1', href : 'javascript:;'}],\r
+                                               ['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', tabindex : '-1', href : 'javascript:;'}],\r
+                                               ['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', tabindex : '-1', href : 'javascript:;'}],\r
+                                               ['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', tabindex : '-1', href : 'javascript:;'}],\r
+                                               ['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', tabindex : '-1', href : 'javascript:;'}],\r
+                                               ['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', tabindex : '-1', href : 'javascript:;'}],\r
+                                               ['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', tabindex : '-1', href : 'javascript:;'}]\r
+                                       ]\r
+                               ]\r
+                       );\r
+\r
+                       DOM.setStyles(id, {top : -10000, left : -10000});\r
+\r
+                       // Fix gecko rendering bug, where the editors iframe messed with window contents\r
+                       if (tinymce.isGecko)\r
+                               DOM.setStyle(id, 'overflow', 'auto');\r
+\r
+                       // Measure borders\r
+                       if (!f.type) {\r
+                               dw += DOM.get(id + '_left').clientWidth;\r
+                               dw += DOM.get(id + '_right').clientWidth;\r
+                               dh += DOM.get(id + '_top').clientHeight;\r
+                               dh += DOM.get(id + '_bottom').clientHeight;\r
+                       }\r
 \r
-MCWindow.prototype.startMove = function(e) {\r
-       mcWindows.action = "move";\r
-};\r
+                       // Resize window\r
+                       DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});\r
 \r
-MCWindow.prototype.close = function() {\r
-       if (mcWindows.lastSelectedWindow != null)\r
-               mcWindows.lastSelectedWindow.focus();\r
+                       u = f.url || f.file;\r
+                       if (u) {\r
+                               if (tinymce.relaxedDomain)\r
+                                       u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain;\r
 \r
-       var mcWindowsNew = new Array();\r
-       for (var n in mcWindows.windows) {\r
-               var win = mcWindows.windows[n];\r
-               if (typeof(win) == 'function')\r
-                       continue;\r
+                               u = tinymce._addVer(u);\r
+                       }\r
 \r
-               if (win.name != this.name)\r
-                       mcWindowsNew[n] = win;\r
-       }\r
+                       if (!f.type) {\r
+                               DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});\r
+                               DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});\r
+                               DOM.setAttrib(id + '_ifr', 'src', u);\r
+                       } else {\r
+                               DOM.add(id + '_wrapper', 'a', {id : id + '_ok', 'class' : 'mceButton mceOk', href : 'javascript:;', onmousedown : 'return false;'}, 'Ok');\r
+\r
+                               if (f.type == 'confirm')\r
+                                       DOM.add(id + '_wrapper', 'a', {'class' : 'mceButton mceCancel', href : 'javascript:;', onmousedown : 'return false;'}, 'Cancel');\r
+\r
+                               DOM.add(id + '_middle', 'div', {'class' : 'mceIcon'});\r
+                               DOM.setHTML(id + '_content', f.content.replace('\n', '<br />'));\r
+                               \r
+                               Event.add(id, 'keyup', function(evt) {\r
+                                       var VK_ESCAPE = 27;\r
+                                       if (evt.keyCode === VK_ESCAPE) {\r
+                                               f.button_func(false);\r
+                                               return Event.cancel(evt);\r
+                                       }\r
+                               });\r
+\r
+                               Event.add(id, 'keydown', function(evt) {\r
+                                       var cancelButton, VK_TAB = 9;\r
+                                       if (evt.keyCode === VK_TAB) {\r
+                                               cancelButton = DOM.select('a.mceCancel', id + '_wrapper')[0];\r
+                                               if (cancelButton && cancelButton !== evt.target) {\r
+                                                       cancelButton.focus();\r
+                                               } else {\r
+                                                       DOM.get(id + '_ok').focus();\r
+                                               }\r
+                                               return Event.cancel(evt);\r
+                                       }\r
+                               });\r
+                       }\r
 \r
-       mcWindows.windows = mcWindowsNew;\r
+                       // Register events\r
+                       mdf = Event.add(id, 'mousedown', function(e) {\r
+                               var n = e.target, w, vp;\r
+\r
+                               w = t.windows[id];\r
+                               t.focus(id);\r
+\r
+                               if (n.nodeName == 'A' || n.nodeName == 'a') {\r
+                                       if (n.className == 'mceClose') {\r
+                                               t.close(null, id);\r
+                                               return Event.cancel(e);\r
+                                       } else if (n.className == 'mceMax') {\r
+                                               w.oldPos = w.element.getXY();\r
+                                               w.oldSize = w.element.getSize();\r
+\r
+                                               vp = DOM.getViewPort();\r
+\r
+                                               // Reduce viewport size to avoid scrollbars\r
+                                               vp.w -= 2;\r
+                                               vp.h -= 2;\r
+\r
+                                               w.element.moveTo(vp.x, vp.y);\r
+                                               w.element.resizeTo(vp.w, vp.h);\r
+                                               DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight});\r
+                                               DOM.addClass(id + '_wrapper', 'mceMaximized');\r
+                                       } else if (n.className == 'mceMed') {\r
+                                               // Reset to old size\r
+                                               w.element.moveTo(w.oldPos.x, w.oldPos.y);\r
+                                               w.element.resizeTo(w.oldSize.w, w.oldSize.h);\r
+                                               w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight);\r
+\r
+                                               DOM.removeClass(id + '_wrapper', 'mceMaximized');\r
+                                       } else if (n.className == 'mceMove')\r
+                                               return t._startDrag(id, e, n.className);\r
+                                       else if (DOM.hasClass(n, 'mceResize'))\r
+                                               return t._startDrag(id, e, n.className.substring(13));\r
+                               }\r
+                       });\r
+\r
+                       clf = Event.add(id, 'click', function(e) {\r
+                               var n = e.target;\r
+\r
+                               t.focus(id);\r
+\r
+                               if (n.nodeName == 'A' || n.nodeName == 'a') {\r
+                                       switch (n.className) {\r
+                                               case 'mceClose':\r
+                                                       t.close(null, id);\r
+                                                       return Event.cancel(e);\r
+\r
+                                               case 'mceButton mceOk':\r
+                                               case 'mceButton mceCancel':\r
+                                                       f.button_func(n.className == 'mceButton mceOk');\r
+                                                       return Event.cancel(e);\r
+                                       }\r
+                               }\r
+                       });\r
+                       \r
+                       // Make sure the tab order loops within the dialog.\r
+                       Event.add([id + '_left', id + '_right'], 'focus', function(evt) {\r
+                               var iframe = DOM.get(id + '_ifr');\r
+                               if (iframe) {\r
+                                       var body = iframe.contentWindow.document.body;\r
+                                       var focusable = DOM.select(':input:enabled,*[tabindex=0]', body);\r
+                                       if (evt.target.id === (id + '_left')) {\r
+                                               focusable[focusable.length - 1].focus();\r
+                                       } else {\r
+                                               focusable[0].focus();\r
+                                       }\r
+                               } else {\r
+                                       DOM.get(id + '_ok').focus();\r
+                               }\r
+                       });\r
+                       \r
+                       // Add window\r
+                       w = t.windows[id] = {\r
+                               id : id,\r
+                               mousedown_func : mdf,\r
+                               click_func : clf,\r
+                               element : new Element(id, {blocker : 1, container : ed.getContainer()}),\r
+                               iframeElement : new Element(id + '_ifr'),\r
+                               features : f,\r
+                               deltaWidth : dw,\r
+                               deltaHeight : dh\r
+                       };\r
+\r
+                       w.iframeElement.on('focus', function() {\r
+                               t.focus(id);\r
+                       });\r
+\r
+                       // Setup blocker\r
+                       if (t.count == 0 && t.editor.getParam('dialog_type', 'modal') == 'modal') {\r
+                               DOM.add(DOM.doc.body, 'div', {\r
+                                       id : 'mceModalBlocker',\r
+                                       'class' : (t.editor.settings.inlinepopups_skin || 'clearlooks2') + '_modalBlocker',\r
+                                       style : {zIndex : t.zIndex - 1}\r
+                               });\r
+\r
+                               DOM.show('mceModalBlocker'); // Reduces flicker in IE\r
+                               DOM.setAttrib(DOM.doc.body, 'aria-hidden', 'true');\r
+                       } else\r
+                               DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1);\r
+\r
+                       if (tinymce.isIE6 || /Firefox\/2\./.test(navigator.userAgent) || (tinymce.isIE && !DOM.boxModel))\r
+                               DOM.setStyles('mceModalBlocker', {position : 'absolute', left : vp.x, top : vp.y, width : vp.w - 2, height : vp.h - 2});\r
+\r
+                       DOM.setAttrib(id, 'aria-hidden', 'false');\r
+                       t.focus(id);\r
+                       t._fixIELayout(id, 1);\r
+\r
+                       // Focus ok button\r
+                       if (DOM.get(id + '_ok'))\r
+                               DOM.get(id + '_ok').focus();\r
+                       t.count++;\r
+\r
+                       return w;\r
+               },\r
+\r
+               focus : function(id) {\r
+                       var t = this, w;\r
+\r
+                       if (w = t.windows[id]) {\r
+                               w.zIndex = this.zIndex++;\r
+                               w.element.setStyle('zIndex', w.zIndex);\r
+                               w.element.update();\r
+\r
+                               id = id + '_wrapper';\r
+                               DOM.removeClass(t.lastId, 'mceFocus');\r
+                               DOM.addClass(id, 'mceFocus');\r
+                               t.lastId = id;\r
+                               \r
+                               if (w.focussedElement) {\r
+                                       w.focussedElement.focus();\r
+                               } else if (DOM.get(id + '_ok')) {\r
+                                       DOM.get(w.id + '_ok').focus();\r
+                               } else if (DOM.get(w.id + '_ifr')) {\r
+                                       DOM.get(w.id + '_ifr').focus();\r
+                               }\r
+                       }\r
+               },\r
 \r
-//     alert(mcWindows.doc.getElementById(this.id + "_iframe"));\r
+               _addAll : function(te, ne) {\r
+                       var i, n, t = this, dom = tinymce.DOM;\r
 \r
-       var e = mcWindows.doc.getElementById(this.id + "_iframe");\r
-       e.parentNode.removeChild(e);\r
+                       if (is(ne, 'string'))\r
+                               te.appendChild(dom.doc.createTextNode(ne));\r
+                       else if (ne.length) {\r
+                               te = te.appendChild(dom.create(ne[0], ne[1]));\r
 \r
-       var e = mcWindows.doc.getElementById(this.id + "_div");\r
-       e.parentNode.removeChild(e);\r
+                               for (i=2; i<ne.length; i++)\r
+                                       t._addAll(te, ne[i]);\r
+                       }\r
+               },\r
+\r
+               _startDrag : function(id, se, ac) {\r
+                       var t = this, mu, mm, d = DOM.doc, eb, w = t.windows[id], we = w.element, sp = we.getXY(), p, sz, ph, cp, vp, sx, sy, sex, sey, dx, dy, dw, dh;\r
+\r
+                       // Get positons and sizes\r
+//                     cp = DOM.getPos(t.editor.getContainer());\r
+                       cp = {x : 0, y : 0};\r
+                       vp = DOM.getViewPort();\r
+\r
+                       // Reduce viewport size to avoid scrollbars while dragging\r
+                       vp.w -= 2;\r
+                       vp.h -= 2;\r
+\r
+                       sex = se.screenX;\r
+                       sey = se.screenY;\r
+                       dx = dy = dw = dh = 0;\r
+\r
+                       // Handle mouse up\r
+                       mu = Event.add(d, 'mouseup', function(e) {\r
+                               Event.remove(d, 'mouseup', mu);\r
+                               Event.remove(d, 'mousemove', mm);\r
+\r
+                               if (eb)\r
+                                       eb.remove();\r
+\r
+                               we.moveBy(dx, dy);\r
+                               we.resizeBy(dw, dh);\r
+                               sz = we.getSize();\r
+                               DOM.setStyles(id + '_ifr', {width : sz.w - w.deltaWidth, height : sz.h - w.deltaHeight});\r
+                               t._fixIELayout(id, 1);\r
+\r
+                               return Event.cancel(e);\r
+                       });\r
+\r
+                       if (ac != 'Move')\r
+                               startMove();\r
+\r
+                       function startMove() {\r
+                               if (eb)\r
+                                       return;\r
+\r
+                               t._fixIELayout(id, 0);\r
+\r
+                               // Setup event blocker\r
+                               DOM.add(d.body, 'div', {\r
+                                       id : 'mceEventBlocker',\r
+                                       'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),\r
+                                       style : {zIndex : t.zIndex + 1}\r
+                               });\r
+\r
+                               if (tinymce.isIE6 || (tinymce.isIE && !DOM.boxModel))\r
+                                       DOM.setStyles('mceEventBlocker', {position : 'absolute', left : vp.x, top : vp.y, width : vp.w - 2, height : vp.h - 2});\r
+\r
+                               eb = new Element('mceEventBlocker');\r
+                               eb.update();\r
+\r
+                               // Setup placeholder\r
+                               p = we.getXY();\r
+                               sz = we.getSize();\r
+                               sx = cp.x + p.x - vp.x;\r
+                               sy = cp.y + p.y - vp.y;\r
+                               DOM.add(eb.get(), 'div', {id : 'mcePlaceHolder', 'class' : 'mcePlaceHolder', style : {left : sx, top : sy, width : sz.w, height : sz.h}});\r
+                               ph = new Element('mcePlaceHolder');\r
+                       };\r
+\r
+                       // Handle mouse move/drag\r
+                       mm = Event.add(d, 'mousemove', function(e) {\r
+                               var x, y, v;\r
+\r
+                               startMove();\r
+\r
+                               x = e.screenX - sex;\r
+                               y = e.screenY - sey;\r
+\r
+                               switch (ac) {\r
+                                       case 'ResizeW':\r
+                                               dx = x;\r
+                                               dw = 0 - x;\r
+                                               break;\r
+\r
+                                       case 'ResizeE':\r
+                                               dw = x;\r
+                                               break;\r
+\r
+                                       case 'ResizeN':\r
+                                       case 'ResizeNW':\r
+                                       case 'ResizeNE':\r
+                                               if (ac == "ResizeNW") {\r
+                                                       dx = x;\r
+                                                       dw = 0 - x;\r
+                                               } else if (ac == "ResizeNE")\r
+                                                       dw = x;\r
+\r
+                                               dy = y;\r
+                                               dh = 0 - y;\r
+                                               break;\r
+\r
+                                       case 'ResizeS':\r
+                                       case 'ResizeSW':\r
+                                       case 'ResizeSE':\r
+                                               if (ac == "ResizeSW") {\r
+                                                       dx = x;\r
+                                                       dw = 0 - x;\r
+                                               } else if (ac == "ResizeSE")\r
+                                                       dw = x;\r
+\r
+                                               dh = y;\r
+                                               break;\r
+\r
+                                       case 'mceMove':\r
+                                               dx = x;\r
+                                               dy = y;\r
+                                               break;\r
+                               }\r
+\r
+                               // Boundary check\r
+                               if (dw < (v = w.features.min_width - sz.w)) {\r
+                                       if (dx !== 0)\r
+                                               dx += dw - v;\r
+\r
+                                       dw = v;\r
+                               }\r
+       \r
+                               if (dh < (v = w.features.min_height - sz.h)) {\r
+                                       if (dy !== 0)\r
+                                               dy += dh - v;\r
+\r
+                                       dh = v;\r
+                               }\r
+\r
+                               dw = Math.min(dw, w.features.max_width - sz.w);\r
+                               dh = Math.min(dh, w.features.max_height - sz.h);\r
+                               dx = Math.max(dx, vp.x - (sx + vp.x));\r
+                               dy = Math.max(dy, vp.y - (sy + vp.y));\r
+                               dx = Math.min(dx, (vp.w + vp.x) - (sx + sz.w + vp.x));\r
+                               dy = Math.min(dy, (vp.h + vp.y) - (sy + sz.h + vp.y));\r
+\r
+                               // Move if needed\r
+                               if (dx + dy !== 0) {\r
+                                       if (sx + dx < 0)\r
+                                               dx = 0;\r
+       \r
+                                       if (sy + dy < 0)\r
+                                               dy = 0;\r
 \r
-       mcWindows.setDocumentLock(false);\r
-};\r
+                                       ph.moveTo(sx + dx, sy + dy);\r
+                               }\r
 \r
-MCWindow.prototype.onMouseMove = function(e) {\r
-       var scrollX = 0;//this.doc.body.scrollLeft;\r
-       var scrollY = 0;//this.doc.body.scrollTop;\r
+                               // Resize if needed\r
+                               if (dw + dh !== 0)\r
+                                       ph.resizeTo(sz.w + dw, sz.h + dh);\r
 \r
-       // Calculate real X, Y\r
-       var dx = e.screenX - mcWindows.mouseDownScreenX;\r
-       var dy = e.screenY - mcWindows.mouseDownScreenY;\r
+                               return Event.cancel(e);\r
+                       });\r
 \r
-       switch (mcWindows.action) {\r
-               case "resize":\r
-                       width = mcWindows.mouseDownWidth + (e.screenX - mcWindows.mouseDownScreenX);\r
-                       height = mcWindows.mouseDownHeight + (e.screenY - mcWindows.mouseDownScreenY);\r
+                       return Event.cancel(se);\r
+               },\r
 \r
-                       width = width < 100 ? 100 : width;\r
-                       height = height < 100 ? 100 : height;\r
+               resizeBy : function(dw, dh, id) {\r
+                       var w = this.windows[id];\r
 \r
-                       this.wrapperIFrameElement.style.width = width+2;\r
-                       this.wrapperIFrameElement.style.height = height+2;\r
-                       this.wrapperIFrameElement.width = width+2;\r
-                       this.wrapperIFrameElement.height = height+2;\r
-                       this.winElement.style.width = width;\r
-                       this.winElement.style.height = height;\r
+                       if (w) {\r
+                               w.element.resizeBy(dw, dh);\r
+                               w.iframeElement.resizeBy(dw, dh);\r
+                       }\r
+               },\r
 \r
-                       height = height - this.deltaHeight;\r
+               close : function(win, id) {\r
+                       var t = this, w, d = DOM.doc, fw, id;\r
 \r
-                       this.containerElement.style.width = width;\r
+                       id = t._findId(id || win);\r
 \r
-                       this.iframeElement.style.width = width;\r
-                       this.iframeElement.style.height = height;\r
-                       this.bodyElement.style.width = width;\r
-                       this.bodyElement.style.height = height;\r
-                       this.headElement.style.width = width;\r
-                       //this.statusElement.style.width = width;\r
+                       // Probably not inline\r
+                       if (!t.windows[id]) {\r
+                               t.parent(win);\r
+                               return;\r
+                       }\r
 \r
-                       mcWindows.cancelEvent(e);\r
-                       break;\r
+                       t.count--;\r
 \r
-               case "move":\r
-                       this.left = mcWindows.mouseDownLayerX + (e.screenX - mcWindows.mouseDownScreenX);\r
-                       this.top = mcWindows.mouseDownLayerY + (e.screenY - mcWindows.mouseDownScreenY);\r
-                       this.winElement.style.left = this.left + "px";\r
-                       this.winElement.style.top = this.top + "px";\r
+                       if (t.count == 0) {\r
+                               DOM.remove('mceModalBlocker');\r
+                               DOM.setAttrib(DOM.doc.body, 'aria-hidden', 'false');\r
+                               t.editor.focus();\r
+                       }\r
 \r
-                       mcWindows.cancelEvent(e);\r
-                       break;\r
-       }\r
-};\r
+                       if (w = t.windows[id]) {\r
+                               t.onClose.dispatch(t);\r
+                               Event.remove(d, 'mousedown', w.mousedownFunc);\r
+                               Event.remove(d, 'click', w.clickFunc);\r
+                               Event.clear(id);\r
+                               Event.clear(id + '_ifr');\r
 \r
-function debug(msg) {\r
-       document.getElementById('debug').value += msg + "\n";\r
-}\r
+                               DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak\r
+                               w.element.remove();\r
+                               delete t.windows[id];\r
 \r
-MCWindow.prototype.onMouseUp = function(e) {\r
-       mcWindows.action = "none";\r
-};\r
+                               fw = t._frontWindow();\r
 \r
-MCWindow.prototype.onFocus = function(e) {\r
-       // Gecko only handler\r
-       var winRef = e.currentTarget;\r
+                               if (fw)\r
+                                       t.focus(fw.id);\r
+                       }\r
+               },\r
+               \r
+               // Find front most window\r
+               _frontWindow : function() {\r
+                       var fw, ix = 0;\r
+                       // Find front most window and focus that\r
+                       each (this.windows, function(w) {\r
+                               if (w.zIndex > ix) {\r
+                                       fw = w;\r
+                                       ix = w.zIndex;\r
+                               }\r
+                       });\r
+                       return fw;\r
+               },\r
+\r
+               setTitle : function(w, ti) {\r
+                       var e;\r
+\r
+                       w = this._findId(w);\r
+\r
+                       if (e = DOM.get(w + '_title'))\r
+                               e.innerHTML = DOM.encode(ti);\r
+               },\r
+\r
+               alert : function(txt, cb, s) {\r
+                       var t = this, w;\r
+\r
+                       w = t.open({\r
+                               title : t,\r
+                               type : 'alert',\r
+                               button_func : function(s) {\r
+                                       if (cb)\r
+                                               cb.call(s || t, s);\r
+\r
+                                       t.close(null, w.id);\r
+                               },\r
+                               content : DOM.encode(t.editor.getLang(txt, txt)),\r
+                               inline : 1,\r
+                               width : 400,\r
+                               height : 130\r
+                       });\r
+               },\r
+\r
+               confirm : function(txt, cb, s) {\r
+                       var t = this, w;\r
+\r
+                       w = t.open({\r
+                               title : t,\r
+                               type : 'confirm',\r
+                               button_func : function(s) {\r
+                                       if (cb)\r
+                                               cb.call(s || t, s);\r
+\r
+                                       t.close(null, w.id);\r
+                               },\r
+                               content : DOM.encode(t.editor.getLang(txt, txt)),\r
+                               inline : 1,\r
+                               width : 400,\r
+                               height : 130\r
+                       });\r
+               },\r
+\r
+               // Internal functions\r
+\r
+               _findId : function(w) {\r
+                       var t = this;\r
+\r
+                       if (typeof(w) == 'string')\r
+                               return w;\r
+\r
+                       each(t.windows, function(wo) {\r
+                               var ifr = DOM.get(wo.id + '_ifr');\r
+\r
+                               if (ifr && w == ifr.contentWindow) {\r
+                                       w = wo.id;\r
+                                       return false;\r
+                               }\r
+                       });\r
+\r
+                       return w;\r
+               },\r
+\r
+               _fixIELayout : function(id, s) {\r
+                       var w, img;\r
+\r
+                       if (!tinymce.isIE6)\r
+                               return;\r
+\r
+                       // Fixes the bug where hover flickers and does odd things in IE6\r
+                       each(['n','s','w','e','nw','ne','sw','se'], function(v) {\r
+                               var e = DOM.get(id + '_resize_' + v);\r
+\r
+                               DOM.setStyles(e, {\r
+                                       width : s ? e.clientWidth : '',\r
+                                       height : s ? e.clientHeight : '',\r
+                                       cursor : DOM.getStyle(e, 'cursor', 1)\r
+                               });\r
+\r
+                               DOM.setStyle(id + "_bottom", 'bottom', '-1px');\r
+\r
+                               e = 0;\r
+                       });\r
+\r
+                       // Fixes graphics glitch\r
+                       if (w = this.windows[id]) {\r
+                               // Fixes rendering bug after resize\r
+                               w.element.hide();\r
+                               w.element.show();\r
+\r
+                               // Forced a repaint of the window\r
+                               //DOM.get(id).style.filter = '';\r
+\r
+                               // IE has a bug where images used in CSS won't get loaded\r
+                               // sometimes when the cache in the browser is disabled\r
+                               // This fix tries to solve it by loading the images using the image object\r
+                               each(DOM.select('div,a', id), function(e, i) {\r
+                                       if (e.currentStyle.backgroundImage != 'none') {\r
+                                               img = new Image();\r
+                                               img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1');\r
+                                       }\r
+                               });\r
+\r
+                               DOM.get(id).style.filter = '';\r
+                       }\r
+               }\r
+       });\r
 \r
-       for (var n in mcWindows.windows) {\r
-               var win = mcWindows.windows[n];\r
-               if (typeof(win) == 'function')\r
-                       continue;\r
+       // Register plugin\r
+       tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups);\r
+})();\r
 \r
-               if (winRef.name == win.id + "_iframe") {\r
-                       win.focus();\r
-                       return;\r
-               }\r
-       }\r
-};\r
-\r
-MCWindow.prototype.onMouseDown = function(e) {\r
-       var elm = mcWindows.isMSIE ? this.wrapperFrame.event.srcElement : e.target;\r
-\r
-       var scrollX = 0;//this.doc.body.scrollLeft;\r
-       var scrollY = 0;//this.doc.body.scrollTop;\r
-\r
-       mcWindows.mouseDownScreenX = e.screenX;\r
-       mcWindows.mouseDownScreenY = e.screenY;\r
-       mcWindows.mouseDownLayerX = this.left;\r
-       mcWindows.mouseDownLayerY = this.top;\r
-       mcWindows.mouseDownWidth = parseInt(this.winElement.style.width);\r
-       mcWindows.mouseDownHeight = parseInt(this.winElement.style.height);\r
-\r
-       if (this.resizeElement != null && elm == this.resizeElement.firstChild)\r
-               this.startResize(e);\r
-       else\r
-               this.startMove(e);\r
-\r
-       mcWindows.cancelEvent(e);\r
-};\r
-\r
-// Global instance\r
-var mcWindows = new MCWindows();\r
-\r
-// Initialize windows\r
-mcWindows.init({\r
-       images_path : tinyMCE.baseURL + "/plugins/inlinepopups/images",\r
-       css_file : tinyMCE.baseURL + "/plugins/inlinepopups/css/inlinepopup.css"\r
-});\r