	var map, layer;
	OpenLayers.Util.onImageLoadErrorColor = 'transparent';
    OpenLayers.IMAGE_RELOAD_ATTEMPTS = 8;
	OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;
	
	//DEFINE LAYERS
	var sections = new OpenLayers.Layer.WMS("Township Sections", "http://maps2.k3gis.com/geoserver/wms", 
	{layers: 'K3GIS:plss_sections', format: 'image/png8', transparent: 'true'},{singleTile: 'true', transitionEffect: 'resize'});
			
	var base = new OpenLayers.Layer("",{isBaseLayer: true});
	
    //Cached
	var urlArray = ["http://www.k3gis.com/geoserver/gwc/service/wms"];	
    var basenoorthos = new OpenLayers.Layer.WMS("Base without Aerial Photos", urlArray, 
	{layers: 'BaseNoOrtho', format: 'image/png', transparent: 'true'}, {transitionEffect: 'resize', 'buffer': 2, isBaseLayer: false}, {gutter: 30});
	
	//Uncached
	//var basenoorthos = new OpenLayers.Layer.WMS("Base without Aerial Photos", "http://www.k3gis.com/geoserver/gwc/service/wms", 
	//{layers: 'BaseNoOrtho', format: 'image/png8', transparent: 'true'}, {'buffer': 2, isBaseLayer: false}, {gutter: 30});
	
    //var baseorthos = new OpenLayers.Layer.WMS("Base with 2006 Aerial Photos", "http://www.k3gis.com/geoserver/wms", 
    //{layers: 'BaseOrtho', format: 'image/jpeg', transparent: 'true'});
	
    var centerlines = new OpenLayers.Layer.WMS("Road Centerlines","http://www.k3gis.com/geoserver/wms",
	{layers: 'K3GIS:Centerlines', format: 'image/gif', transparent:'true'});
	
	var mapbook400 = new OpenLayers.Layer.WMS("400 Scale Mapbook Pages", "http://www.k3gis.com/geoserver/wms", 
	{layers: 'K3GIS:mapbook_400_scale_pages', format: 'image/png8', transparent: 'true'}, {singleTile: 'true', transitionEffect: 'resize'});
		
    var mapbook100 = new OpenLayers.Layer.WMS("100 Scale Mapbook Pages", "http://www.k3gis.com/geoserver/wms", 
	{layers: 'K3GIS:mapbook_100_scale_pages', format: 'image/png8', transparent: 'true'}, {singleTile: 'true', transitionEffect: 'resize'});
	
	var parcels_identify = new OpenLayers.Layer.WMS("Parcels","http://www.k3gis.com/geoserver/wms",
	{layers: 'K3GIS:parcels', format: 'image/png8', transparent:'true', maxScale: 20000}, {singleTile: 'true'});
	
	var anno = new OpenLayers.Layer.WMS(
	"Tax Map Annotation","http://maps2.k3gis.com/geoserver/wms",
	{layers: 'K3GIS:anno', format: 'image/png8', transparent:'true'}, {'buffer': 0});
	
	
	//UNCACHED
	//var urlArray2 = ["http://maps1.k3gis.com/geoserver/wms"];
	//var cadastral = new OpenLayers.Layer.WMS("Cadastral", urlArray2,
	//{layers: 'Cadastral', format: 'image/png8', transparent: 'true', maxScale: 20000}, {singleTile: 'true', transitionEffect: 'resize'});
	
	//CACHED
	var urlArray2 = ["http://maps1.k3gis.com/geoserver/gwc/service/wms"];
	var cadastral = new OpenLayers.Layer.WMS("Cadastral", urlArray2,
	{layers: 'Cadastral', format: 'image/png', transparent: 'true', maxScale: 20000}, {'buffer': 4});	
	
	var municipality_labels = new OpenLayers.Layer.WMS("Municipality Labels", "http://www.k3gis.com/geoserver/wms",
	{layers: 'K3GIS:municipality_labels', format: 'image/png8', transparent: 'true'}, {singleTile: 'true'});

	var political_township_labels = new OpenLayers.Layer.WMS("Political Township Labels", "http://maps1.k3gis.com/geoserver/wms",
	{layers: 'K3GIS:political_township_labels', format: 'image/png8', transparent: 'true'}, {singleTile: 'true'});
	
    var subdivision_labels = new OpenLayers.Layer.WMS("Subdivision Labels", "http://www.k3gis.com/geoserver/wms",
	{layers: 'K3GIS:subdivision_labels', format: 'image/png8', transparent: 'true'}, {singleTile: 'true', transitionEffect: 'resize'});
	
	var pins = new OpenLayers.Layer.WMS("Parcel Numbers", "http://maps3.k3gis.com/geoserver/wms",
	{layers: 'K3GIS:pins', format: 'image/png8', transparent: 'true'},{singleTile: 'true', transitionEffect: 'resize'});
	
	var municipalities = new OpenLayers.Layer.WMS("Municipalities","http://www.k3gis.com/geoserver/wms",
	{layers: 'K3GIS:municipalities', format: 'image/gif', transparent:'true'});
	
	//Cached
	var urlArray3 = ["http://maps3.k3gis.com/geoserver/gwc/service/wms",
	                 "http://maps4.k3gis.com/geoserver/gwc/service/wms"];			 
	var orthos = new OpenLayers.Layer.WMS("2010 Aerial Photos", urlArray3,
	{layers: 'K3GIS:Orthos2010', format: 'image/jpeg', maxResolution: 3}, {isBaseLayer: false}, {'buffer': 2});
	
	//Uncached
	//var orthos = new OpenLayers.Layer.WMS("Orthos 2010","http://www.k3gis.com/geoserver/wms",
	//{layers: 'K3GIS:Orthos2010', format: 'image/jpeg', maxResolution: 3}, {'buffer': 0, isBaseLayer: false});
		
	//Variables for markers for address location
	var markers = new OpenLayers.Layer.Markers("Markers");
	var icon = new OpenLayers.Icon('http://www.k3gis.com/public/marker-red.png');
	
	function init(){
		
	//Works in 2.8
	var mapOptions = { 
	maxResolution: 152.874056549072265625,
	numZoomLevels: 13,
	projection: new OpenLayers.Projection("EPSG:900913"),
	displayProjection: new OpenLayers.Projection("EPSG:4326"),
	units: 'm',
	maxExtent: new OpenLayers.Bounds(-2.003750834E7,-2.003750834E7,2.003750834E7,2.003750834E7),
	restrictedExtent: new OpenLayers.Bounds(-9824129.899367314,5011126.435868879,-9742976.888553629,5056818.513556269),	
	tileSize: new OpenLayers.Size(256,256),
	controls: []
    };

    //2.8
	map = new OpenLayers.Map('map', mapOptions);		
	map.addLayer(base);
	base.displayInLayerSwitcher = false;
	map.addLayer(basenoorthos);
	basenoorthos.alwaysInRange = false;
	basenoorthos.minResolution = 5;
	basenoorthos.displayInLayerSwitcher = false;
	map.addLayer(orthos);
    orthos.alwaysInRange = false;
	orthos.maxResolution = 5;
	orthos.displayInLayerSwitcher = true;
	map.addLayer(cadastral);
	cadastral.alwaysInRange = false;
	cadastral.maxResolution = 5;
	cadastral.displayInLayerSwitcher = false;
	map.addLayer(municipality_labels);
	map.addLayer(political_township_labels);
	political_township_labels.alwaysInRange = false;
	political_township_labels.minResolution = 5;
    map.addLayer(subdivision_labels);
	subdivision_labels.alwaysInRange = false;
	subdivision_labels.maxResolution = 5;
	subdivision_labels.setVisibility(false);
    map.addLayer(pins);
	pins.alwaysInRange = false;
	pins.maxResolution = 5;
	pins.setVisibility(false);
	map.addLayer(anno);
	anno.alwaysInRange = false;
	anno.maxResolution = 5;
	anno.setVisibility(false);
    map.addLayer(parcels_identify);
	parcels_identify.displayInLayerSwitcher = false;
	parcels_identify.setVisibility(false);
	map.addLayer(mapbook100);
	mapbook100.setVisibility(false);
	map.addLayer(mapbook400);
	mapbook400.setVisibility(false);
	map.addLayer(sections);
	sections.setVisibility(false);	
    map.addLayer(markers);
	markers.displayInLayerSwitcher = false;
	
		info = new OpenLayers.Control.WMSGetFeatureInfo({
			url: 'http://www.k3gis.com/geoserver/wms',
			title: 'Identify features by clicking',
			queryVisible: false,
			layers: [parcels_identify],
			eventListeners: {
				getfeatureinfo: function(event){
					map.addPopup(new OpenLayers.Popup.FramedCloud("chicken", map.getLonLatFromPixel(event.xy), null, event.text, null, true));
				}
			}
		});
		map.addControl(info);

	//ACTIVATE & DEACTIVATE WMS POPUPS BASED ON SCALE	
	map.events.register("zoomend", map, function(e){
	  scale = map.getScale();
		if (scale <= 20000) {
		    info.activate();
		} else {
			info.deactivate();
			}	
	});
		
	//scalebar = new OpenLayers.Control.ScaleLine({geodesic: true});
    //map.addControl(scalebar); 
	//map.addControl(new OpenLayers.Control.Scale());
	//map.addControl(new OpenLayers.Control.MousePosition());
	//map.addControl(new OpenLayers.Control.LayerSwitcher());
    //panzoombar = new OpenLayers.Control.PanZoomBar()
	//map.addControl(panzoombar);
	
   var nc = new OpenLayers.Control.Navigation();
   map.addControl(nc); 
   nc.zoomBox.deactivate();
   
   map.zoomToExtent(new OpenLayers.Bounds(-9824129.899367314,5011126.435868879,-9742976.888553629,5056818.513556269));
   	scalebar = new OpenLayers.Control.ScaleLine();
    map.addControl(scalebar);
	scalebar.geodesic = true; 
	scaletext = new OpenLayers.Control.Scale();
	map.addControl(scaletext);
	scaletext.geodesic = true;
	map.addControl(new OpenLayers.Control.MousePosition());
	map.addControl(new OpenLayers.Control.LayerSwitcher());
    panzoombar = new OpenLayers.Control.PanZoomBar()
	map.addControl(panzoombar);
    }
	

	//ZOOM TO ADDRESS FROM GEOCODER
	function ZoomToAddress(x,y)
	
	{   if (markers) { markers.clearMarkers(); }
		map.setCenter(new OpenLayers.LonLat(x,y),7);	
		markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(x,y),icon));
	}
	
  	//ZOOM TO 400 SCALE PAGE
	function zoomMapbookPage(extent)
		{
			//alert(extent);
			extentsplit = extent.split(",");
			//pageextent = new OpenLayers.Bounds(extent);
			map.zoomToExtent(new OpenLayers.Bounds(extentsplit[0],extentsplit[1],extentsplit[2],extentsplit[3]), {closest: true});
			return false;
		}	
		
	//ZOOM TO PARCEL
	function ZoomToParcel(minx,miny,maxx,maxy)
		{
			map.zoomToExtent(new OpenLayers.Bounds(minx,miny,maxx,maxy), {closest: false});
		}	
		
//PRINT FUNCTION	
	function print(){
		var layers  = map.layers;
		//alert(layers[1].getFullRequestString());		
        var extent = map.getExtent();
		extent  = [extent.left,extent.bottom,extent.right,extent.top].join(',');
		var width   = map.getSize().w;
        var height  = map.getSize().h;
		var activelayers = [];
        for (i=1;i<=layers.length-2;i++) {
            if (!layers[i].getVisibility()) continue;
            if (!layers[i].calculateInRange()) continue;
            activelayers[activelayers.length] = layers[i].params['LAYERS'];
            }
		 activelayers = activelayers.join(',');
		var url= 'http://www.k3gis.com/geoserver/wms?LAYERS=';
		url += activelayers;
		url += '&FORMAT=image/jpeg&TRANSPARENT=true&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX='; 
		url += extent;
		url += '&WIDTH='
		url += width;
		url += '&HEIGHT='
		url += height;
		url += '&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A900913&format_options=layout:public';
		
		myWin=window.open("","myWin","menubar,resizable,left=30px,top=40px"); 
		myWin.document.open();
		myWin.document.write('<html><head><title>Kankakee County Public GIS</title></head><body><div id="printimage"><table border=1><td><img src ="' + url + '"></td></table></div></body></html>');
		myWin.document.close();
	}
		
