var map;
var wms;
var placeholder;
var wCounties;
var wCountiesL;
var wMCDs;
var wMCDsL;
var wSchools;
var wSchoolsL;
var wTracts;
var wTractsL;
var wBGs;
var wBGsL;
var wTribal;
var wTribalL;
var wZips;
var wZipsL;
var wWic;
var WSms;
var wFp;
var wFsr;
var wFsa;
var wSmp;
var thethematic;
var gnormal;
var myLayerswitcher;
var theserver = 'http://aplmapserver.apl.wisc.edu/FoodMaps/';
//var theserver = 'http://localhost/walk/'
var thecgi = 'http://foodsecurity.apl.wisc.edu/cgi/';

function addtheLayer(name, dname, vis){
var test
	    test = new OpenLayers.Layer.WMS(name, theserver + "wms.ashx",
        	{layers: eval("'" + name + "'"),
		tilesOrigin : "0,0",
		transparent: "true",
		P_LAYER: eval("'" + name + "'"),
		P_NAME: eval("'" + dname + "'"),
        	format: "image/png", request: "GetMap", CRS: new OpenLayers.Projection("EPSG:900913"),
        	version: "1.3.0"}, {isBaseLayer: false, opacity: .8, 'displayOutsideMaxExtent': true, 'visibility': vis, 'displayInLayerSwitcher': false});
			map.addLayer(test)
}

function addLayers(){
	addtheLayer("wBGs", "fs_bgs", false)
	addtheLayer("wTracts", "fs_tracts", false)
	addtheLayer("wTractsL", "fs_tracts", false)
	addtheLayer("wMCDs", "fs_mcds", false)
	addtheLayer("wMCDsL", "fs_mcds", false)
	addtheLayer("wTribal", "fs_tribal", false)
	addtheLayer("wZips", "fs_zips", false)
	addtheLayer("wZipsL", "fs_zips", false)
	addtheLayer("wSchoolsL", "fs_schools", false)
	addtheLayer("wSchools", "fs_schools", false)
	addtheLayer("wCounties", "fs_counties", true)
	addtheLayer("wCountiesL", "fs_counties", false)
	addtheLayer("wWic", "wic", false)
	addtheLayer("WSms", "snr_meal", false)
	addtheLayer("wFp", "pantries", false)
	addtheLayer("wFsr", "fs_ret", false)
	addtheLayer("wFsa", "fs_app", false)
	addtheLayer("wSmp", "summermeal", false)
	            // create Google layer
            var gnormal = new OpenLayers.Layer.Google(
                "Google Map",
                {type: G_NORMAL_MAP, 'sphericalMercator': true}
            );
			map.addLayer(gnormal)
}

        function init(){

            var options = {
                // the "community" epsg code for spherical mercator
                projection: "EPSG:900913",
                // map horizontal units are meters
                units: "m",
                // this resolution displays the globe in one 256x256 pixel tile
                maxResolution: 156543.0339,
                // these are the bounds of the globe in sperical mercator
                maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
                                                 20037508, 20037508),		
		    controls: []

            };
            map = new OpenLayers.Map('map', options);

                        // create WMS layer
		addLayers()
            var usBounds = new OpenLayers.Bounds(
                mapExtent[0], mapExtent[1], mapExtent[2], mapExtent[3]);
 		         
 		var controlID = new OpenLayers.Control.Identify(myIdentify); 
            zb = new OpenLayers.Control.ZoomBox(
                {title:"Zoom box: Selecting it you can zoom on an area by clicking and dragging."});
		var panner = new OpenLayers.Control.Navigation({title:'You can use the default mouse configuration'})
            var panel = new OpenLayers.Control.Panel({defaultControl: panner});
            panel.addControls([
                panner, 
                zb,
		    new OpenLayers.Control.ZoomToMaxExtent({title:"Zoom to the max extent"}),
		    controlID,
		new OpenLayers.Control.PanZoomBar()
            ]);
            map.addControl(panel);
		map.addControl(new OpenLayers.Control.MousePosition())
		map.zoomToExtent(usBounds);

	StartAjaxRequest("updateDataDrops")
	vargeolist = ''
	ajaxRequest.open("GET", thecgi + "fs_createvarlist.py?which=createSelect&thegeo=n", true);
	ajaxRequest.send(null); 	
        }
