//$HeadURL$
/*----------------------------------------------------------------------------
 This file is part of deegree, http://deegree.org/
 Copyright (C) 2001-2009 by:
 - Department of Geography, University of Bonn -
 and
 - lat/lon GmbH -

 This library is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free
 Software Foundation; either version 2.1 of the License, or (at your option)
 any later version.
 This library is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 details.
 You should have received a copy of the GNU Lesser General Public License
 along with this library; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 Contact information:

 lat/lon GmbH
 Aennchenstr. 19, 53177 Bonn
 Germany
 http://lat-lon.de/

 Department of Geography, University of Bonn
 Prof. Dr. Klaus Greve
 Postfach 1147, 53001 Bonn
 Germany
 http://www.geographie.uni-bonn.de/deegree/

 e-mail: info@deegree.org
----------------------------------------------------------------------------*/

function ScreenSwitcher() {
		
	this.switchToFullScreen = switchToFullScreen;
        
	function switchToFullScreen( methodName ) {
	
        var req = "<param><value><struct>";
		
		//Layers part
		req += createMember( "layerList", createLayerListStructMember(), "struct" );
		
		//Bounding box part
		var b = getBBox();
        req += createMember( "boundingBox", createBBoxStructMember(b), "struct" );
        
        //Map width and height
        var rect = getMapSize();
       	req += createMember( "mapSize", createMapSizeStructMember(rect), "struct" );
		
		//Finishing part
		req += "</struct></value></param>";
		req = createMethodCall( methodName, req, "UTF-8" );
		return req;
    }
    
    function getBBox(){
        return parent.controller.mapModel.getBoundingBox();
    }
    
    //copied from savecontext.jsp
    //Creates a list of all available layers
    function createLayerListStructMember(){
	    var layerlist = '';
	    var b = parent.controller.mapModel.getLayerList();
	    var lgroup = b.getLayerGroups();
	    
	    var k = 0;
	    for( var i = 0; i < lgroup.length; i++ ){
	        var g = lgroup[i].getLayers();
	        for( var j = 0; j < g.length; j++ ) {
	             // index k is layer order
	             var v = g[j].isVisible() + "|" + k + "|" + lgroup[i].getServiceType() +
	                     "|" + lgroup[i].getServiceName() + "|" + lgroup[i].getServiceURL() +
	                     "|" + g[j].getTitle() + "|" + g[j].isQueryable();
	            
	            // rpc part         
	            layerlist += createMember( g[j].getName(), v, "string" );
	            
	            k++;
	        }
	    }
	    return layerlist;
	}
	
	/*
	* Rectangle struct
	*/
	function Rectangle( width, height ) {
		this.width = width;
		this.height = height;
	}
	
	/*
	* returns a struct contains the length and width of a rectangle
	*/
	function getMapSize() {
		return new Rectangle(parent.controller.mapModel.width, parent.controller.mapModel.height);
	}
	
	/*
	* Creates the 4 members of a struct defining the bbox of a map for a rpc
	*/
	function createBBoxStructMember(b) {
		var bbox = 	createMember( "minx", b.minx, "double" ) +
	                createMember( "miny", b.miny, "double" ) +
                	createMember( "maxx", b.maxx, "double" ) +
                	createMember( "maxy", b.maxy, "double" );
         return bbox;
	}
	
	/*
	* Returns the map length and width for a rpc
	*/
	function createMapSizeStructMember(rect) {
		var rect = 	createMember( "width", rect.width, "double" ) +
        			createMember( "height", rect.height, "double" );
        return rect;
	}
}
	