var map;
var wms;
var placeholder;
var thethematic;
var myLayerswitcher;
var theserver = 'http://aplmapserver.apl.wisc.edu/GetFacts/';
var thecgi = 'http://www.getfacts.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",
            format: eval('"' + imagetypeformaps + '"'), request: "GetMap", CRS: new OpenLayers.Projection("EPSG:900913"),
			P_LAYER: eval('"' + name + '"'),
			P_NAME: eval('"' + dname + '"'),
            version: "1.3.0"}, {isBaseLayer: false, opacity: .8, 'displayOutsideMaxExtent': true, 'visibility': vis, 'displayInLayerSwitcher': false});
			map.addLayer(test);
}

function addLayers(){
	addtheLayer("wZips", "gf_zips", false)
	addtheLayer("wZipsL", "gf_zips", false)
	addtheLayer("wTribal", "gf_tribal", false)
	addtheLayer("wBasins", "gf_basin", false)
	addtheLayer("wWatersheds", "gf_watershed_12", false)
	addtheLayer("wBGs", "gf_bgs", false)
	addtheLayer("wBGsL", "gf_bgs", false)
	addtheLayer("wTracts", "gf_tracts", false)
	addtheLayer("wTractsL", "gf_tracts", false)
	addtheLayer("wMCDs", "gf_mcds", false)
	addtheLayer("wMCDsL", "gf_mcds", false)
	addtheLayer("wCounties", "gf_counties", true)
	addtheLayer("wCountiesL", "gf_counties", 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.zoomToExtent(usBounds);

	StartAjaxRequest("updateDataDrops")
	vargeolist = ''
	ajaxRequest.open("GET", thecgi + "createvarlist.py?which=createSelect&thegeo=n", true);
	ajaxRequest.send(null); 	
}
