         return null;
     }
 
+    /**
+     *  @private
+     *  Add mouse out listeners for modal and non-modal windows.
+     */
+    private function addMouseOutEventListeners(o:PopUpData):void
+    {
+        var sbRoot:DisplayObject = o.systemManager.getSandboxRoot();
+        if (o.modalWindow)
+        {
+            o.modalWindow.addEventListener(MouseEvent.MOUSE_DOWN,  o.mouseDownOutsideHandler);
+            o.modalWindow.addEventListener(MouseEvent.MOUSE_WHEEL, o.mouseWheelOutsideHandler, true);
+        }
+        else
+        {
+            sbRoot.addEventListener(MouseEvent.MOUSE_DOWN,  o.mouseDownOutsideHandler);
+            sbRoot.addEventListener(MouseEvent.MOUSE_WHEEL, o.mouseWheelOutsideHandler, true);
+        }
+        
+        sbRoot.addEventListener(MarshalMouseEvent.MOUSE_DOWN,  o.marshalMouseOutsideHandler);
+        sbRoot.addEventListener(MarshalMouseEvent.MOUSE_WHEEL, o.marshalMouseOutsideHandler, true);
+    }
+    
+    /**
+     *  @private
+     *  Remove mouse out listeners for modal and non-modal windows.
+     */
+    private function removeMouseOutEventListeners(o:PopUpData):void
+    {
+        var sbRoot:DisplayObject = o.systemManager.getSandboxRoot();
+        if (o.modalWindow)
+        {
+            o.modalWindow.removeEventListener(MouseEvent.MOUSE_DOWN,  o.mouseDownOutsideHandler);
+            o.modalWindow.removeEventListener(MouseEvent.MOUSE_WHEEL, o.mouseWheelOutsideHandler, true);
+        }
+        else 
+        {
+            sbRoot.removeEventListener(MouseEvent.MOUSE_DOWN,  o.mouseDownOutsideHandler);
+            sbRoot.removeEventListener(MouseEvent.MOUSE_WHEEL, o.mouseWheelOutsideHandler, true);
+        }
+
+        sbRoot.removeEventListener(MarshalMouseEvent.MOUSE_DOWN,  o.marshalMouseOutsideHandler);
+        sbRoot.removeEventListener(MarshalMouseEvent.MOUSE_WHEEL, o.marshalMouseOutsideHandler, true);
+    }
+
     //--------------------------------------------------------------------------
     //
     //  Event handlers
     //
     //--------------------------------------------------------------------------
+
+    /**
+     *  @private
+     *  Set by PopUpManager on modal windows so they show when the parent shows.
+     */
+    private function popupShowHandler(event:FlexEvent):void
+    {
+        const o:PopUpData = findPopupInfoByOwner(event.target);
+        if (o)
+            showModalWindow(o, getTopLevelSystemManager(o.parent));
+    }
+
+    /**
+     *  @private
+     *  Set by PopUpManager on modal windows so they hide when the parent hide
+     */
+    private function popupHideHandler(event:FlexEvent):void
+    {
+        const o:PopUpData = findPopupInfoByOwner(event.target);
+        if (o)
+            hideModalWindow(o);
+    }
+
+    /**
+     *  @private
+     */
+    private function showOwnerHandler(event:FlexEvent):void
+    {
+        const o:PopUpData = findPopupInfoByOwner(event.target);
+        if (o)
+        {
+            // add mouse out listeners.
+            addMouseOutEventListeners(o);            
+        }
+    }
+
+    /**
+     *  @private
+     */
+    private function hideOwnerHandler(event:FlexEvent):void
+    {
+        const o:PopUpData = findPopupInfoByOwner(event.target);
+        if (o)
+        {
+            // remove mouse out listeners
+            removeMouseOutEventListeners(o);
+        }
+    }
 
     /**
      *  @private

                         
    }                                     
    
    /**
     *  @private
     *  Set by PopUpManager on modal windows so they show when the parent shows
     */
    private function popupShowHandler(event:FlexEvent):void
    {
        const o:PopUpData = findPopupInfoByOwner(event.target);
        if (o)
            showModalWindow(o, getTopLevelSystemManager(o.parent));
    }

    /**
     *  @private
     *  Set by PopUpManager on modal windows so they hide when the parent hide
     */
    private function popupHideHandler(event:FlexEvent):void
    {
        const o:PopUpData = findPopupInfoByOwner(event.target);
        if (o)
            hideModalWindow(o);
    }

    /**
     *  @private
     */

            o._mouseDownOutsideHandler  = nonmodalMouseDownOutsideHandler;
            o._mouseWheelOutsideHandler = nonmodalMouseWheelOutsideHandler;

            window.visible = visibleFlag;
        }

        // Add show/hide listener so mouse out listeners can be added when
        // a pop up is shown because applications can be launched and 
        // terminated between the time a pop up is hidden to when it is
        // shown again.         
        o.owner.addEventListener(FlexEvent.SHOW, showOwnerHandler);
        o.owner.addEventListener(FlexEvent.HIDE, hideOwnerHandler);

        addMouseOutEventListeners(o);
        
        // Listen for unload so we know to kill the window (and the modalWindow if modal)
        // this handles _all_ cleanup
        window.addEventListener(Event.REMOVED, popupRemovedHandler);
