 package spark.components.supportClasses
 {
 import flash.desktop.NativeApplication;
+import flash.display.InteractiveObject;
 import flash.display.StageOrientation;
 import flash.events.Event;
 import flash.events.InvokeEvent;
 import flash.events.KeyboardEvent;
+import flash.events.MouseEvent;
 import flash.events.StageOrientationEvent;
 import flash.system.Capabilities;
 import flash.ui.Keyboard;
 
+import mx.core.IFactory;
 import mx.core.mx_internal;
 import mx.events.FlexEvent;
+import mx.events.FlexMouseEvent;
+import mx.managers.PopUpManager;
 
 import spark.components.Application;
 import spark.components.View;
+import spark.components.ViewMenu;
 import spark.core.managers.IPersistenceManager;
 import spark.core.managers.PersistenceManager;
 

    }
    
    /**
     *  @private
     */
    // FIXME (chiedozi): Maybe use a singleton for persistence, PARB (GLENN)

        // deviceKeyDownHandler method and so doesn't need to be reset.
        if (key == Keyboard.BACK && !backKeyEventPreventDefaulted && canCancelBackKeyBehavior)
            backKeyHandler();
        else if (key == Keyboard.MENU && !menuKeyEventPreventDefaulted)
            menuKeyHandler(event);
    }
    
    private function viewMenu_clickHandler(event:MouseEvent):void
    {
        viewMenuOpen = false;
    }
    
    private function viewMenu_mouseDownOutsideHandler(event:FlexMouseEvent):void
    {
        viewMenuOpen = false;
    }
    
    private function openViewMenu():void
    {
        currentViewMenu = ViewMenu(viewMenu.newInstance());
        currentViewMenu.items = activeView.viewMenuItems;
        currentViewMenu.owner = this;
        currentViewMenu.addEventListener(MouseEvent.CLICK, viewMenu_clickHandler);
        currentViewMenu.width = getLayoutBoundsWidth();
        
        PopUpManager.addPopUp(currentViewMenu, this, true);     
        currentViewMenu.validateNow();
        
        currentViewMenu.x = 0;
        currentViewMenu.y = Math.ceil(getLayoutBoundsHeight() - currentViewMenu.getLayoutBoundsHeight());
        
        lastFocus = getFocus();
        
        currentViewMenu.setFocus();
        currentViewMenu.addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, viewMenu_mouseDownOutsideHandler);
    }
    
    private function closeViewMenu():void
    {
        currentViewMenu.removeEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, viewMenu_mouseDownOutsideHandler);
        PopUpManager.removePopUp(currentViewMenu);
        currentViewMenu.caretIndex = -1;
        currentViewMenu.validateProperties();
        currentViewMenu.removeEventListener(MouseEvent.CLICK, viewMenu_clickHandler);
        currentViewMenu.items = null;
        currentViewMenu = null;
        
        systemManager.stage.focus = lastFocus;
    }
    
    //--------------------------------------------------------------------------
