/**************************************************************************
*
*  @@@BUILDINFO@@@ 68windowMenu-2.jsx 2.0.1.68  18-May-2007
*  Copyright 2006-2007 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains the property of
* Adobe Systems Incorporated  and its suppliers,  if any.  The intellectual 
* and technical concepts contained herein are proprietary to  Adobe Systems 
* Incorporated  and its suppliers  and may be  covered by U.S.  and Foreign 
* Patents,patents in process,and are protected by trade secret or copyright 
* law.  Dissemination of this  information or reproduction of this material
* is strictly  forbidden  unless prior written permission is  obtained from 
* Adobe Systems Incorporated.
**************************************************************************/

/////////////////////////////////////////////////////////////////////////////
// The Window menu

menus.window = new MenuElement ("menu", "$$$/ESToolkit/Menu/Window=&Window",
								"at the end of menubar", "window");

// Add this setup to the late startup tasks.
addDelayedTask( setupHelpMenu );

function setupHelpMenu()
{
    menus.updateWindowMenu();
}

// The Window menu is recreated every time a document opens or closes to 
// reflect the list of open documents.
// Note: do not call before 69helpMenu has been loaded.

menus.updateWindowMenu = function()
{
    //
    // remove all menu items of window menu
    //
    for( menuItem in menus.window )
    {
        if( menus.window[menuItem] instanceof MenuElement )
        {
            menus.window[menuItem].remove();
            menus.window[menuItem] = null;
        }
    }
    // remove menu items for documents (separat array, so they don't appear in shortcut prefs)
    if( menus.window.docs )
    {
        for( var i=0; i<menus.window.docs.length; i++ )
            menus.window.docs[i].remove();
            
        menus.window.docs = null;
    }

	for (var i = 0; i < panes.length; i++)
	{
		var paneMenuPropName = "pane"+i;
		menus.window[paneMenuPropName] = new MenuElement ("command", panes[i].menuText, "at the end of window", "window/pane"+i);
		
		menus.window[paneMenuPropName].window = panes[i];
		menus.window[paneMenuPropName].onDisplay = function()
		{
			this.checked = this.window.visible;
		}
		menus.window[paneMenuPropName].onSelect = function()
		{
		    if( this.window.visible )
		    {
			    this.window.visible = false;
		    }
		    else
		    {
			    this.window.visible = true;
			    this.window.active = true;
		    }
		}
	}

	menus.window.menuResetWS = new MenuElement ("command", "$$$/ESToolkit/Menu/Window/ResetPanels=&Reset Panel Locations",
												 "---at the end of window", "window/reset");
												 
	menus.window.menuResetWS.onSelect = function()
	{
	    if( !workspaceVisible )
	    {
	        workspace.togglePalettes();
	        workspaceVisible = !workspaceVisible;
	    }
	        
		workspace.workspace = "default";
	}

	menus.window.menuToggleWS = new MenuElement ("command", "$$$/ESToolkit/Menu/Window/HidePanels=Hide Pane&ls",
												 "at the end of window", "window/toggle");

	if( workspaceVisible )
	    menus.window.menuToggleWS.text = localize( "$$$/ESToolkit/Menu/Window/HidePanels=Hide Pane&ls" );
    else
	    menus.window.menuToggleWS.text = localize( "$$$/ESToolkit/Menu/Window/ShowPanels=Show Pane&ls" );

	menus.window.menuToggleWS.onSelect = function()
	{
		workspace.togglePalettes();
		
		workspaceVisible = !workspaceVisible;
		
		if( workspaceVisible )
		    this.text = localize( "$$$/ESToolkit/Menu/Window/HidePanels=Hide Pane&ls" );
        else
		{
		    this.text = localize( "$$$/ESToolkit/Menu/Window/ShowPanels=Show Pane&ls" );
			if (document)
			{
				document.deactivate();
				document.activate();
			}
		}
	}

	menus.window.nextdoc = new MenuElement ("command", "$$$/ESToolkit/Menu/Window/Next=&Next Document",
							"---at the end of window", "window/next");
	menus.window.nextdoc.onSelect = function()
	{
		workspace.activateNextDocWindow();
	}
	menus.window.prevdoc = new MenuElement ("command", "$$$/ESToolkit/Menu/Window/Prev=&Previous Document",
							"at the end of window", "window/previous");
	menus.window.prevdoc.onSelect = function()
	{
		workspace.activatePreviousDocWindow();
	}
	
	menus.window.casc = new MenuElement ("command", "$$$/ESToolkit/Menu/Window/Cascade=C&ascade",
							"at the end of window", "window/cascade");
	menus.window.casc.onSelect = function()
	{
		Document.cascade();
	}
	
	menus.window.htile = new MenuElement ("command", "$$$/ESToolkit/Menu/Window/HTile=Tile &Horizontally",
							"at the end of window", "window/htile");
	menus.window.htile.onSelect = function()
	{
		Document.tile( "horizontal" );
	}
	
	menus.window.vtile = new MenuElement ("command", "$$$/ESToolkit/Menu/Window/VTile=Tile &Vertically",
							"at the end of window", "window/vtile");
	menus.window.vtile.onSelect = function()
	{
		Document.tile( "vertical" );
	}
	
    menus.window.casc.onDisplay = 
    menus.window.htile.onDisplay = 							
    menus.window.vtile.onDisplay = 
	menus.window.nextdoc.onDisplay  = 
	menus.window.prevdoc.onDisplay  = function()
	{
	    var docwinCount = documents.length;
	    
	    if( docwinCount < 2 )
	        for( i = 0; i < OMV.windows.length; i++ )
	            if( ( OMV.windows[i] instanceof Window ) && OMV.windows[i].visible )
	            docwinCount++;
	    
		this.enabled = (docwinCount > 1);
	}

	var separator = "---";

    menus.window.docs = [];
    
	for (i = 0; i < documents.length; i++)
	{
		var doc = documents [i];
		var win = doc.parent;
		var text = "";
		if (i < 9)
			text = "&" + (i+1) + " ";
		text += doc.paneTitle;
		
		menus.window.docs[i] = new MenuElement ("command", text, separator + "at the end of window");
		separator = "";
		menus.window.docs[i].window = win;
		menus.window.docs[i].onSelect = function()
		{
		    this.window.active = true;
		    this.window.minimized = false;
		}
	}
	
	// Reload all hot keys
	menus.loadKeys();
}
