﻿var geocoder = null;

function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		    map.addControl(new GLargeMapControl());
    	map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());	
		
		

	// Section 1 Map Code
	// ============================================================
      var copyright = new GCopyright(1,
          new GLatLngBounds(new GLatLng(38.37281827769632, -85.76348304748535),new GLatLng(38.32765244536364, -85.68297386169434) ),
          14, "CTSGEC");

      // ====== Create a copyright collection =====
      // ====== and add the copyright to it   =====
      var copyrightCollection = new GCopyrightCollection('Map Data:');
      copyrightCollection.addCopyright(copyright);
      
      // == This is the getTileUrl function for Section 1 all zoom levels========
      // In this case the tiles are names like  8053_5274_3.jpg      
        
		// Section 6a
		rdsUrl=function(a,b){
	      //return "http://www.ctsgec.net:75/images/tiles/1/orb"+"rds"+"z"+(b)+"/"+a.x+"_"+a.y+"_"+b+".gif"
	      return "/maps-features/TileData.ashx?op=rds&b1="+(b)+"&x="+a.x+"&y="+a.y+"&b2="+b
      }
      	rowUrl=function(a,b){
	      // return "http://www.ctsgec.net:75/images/tiles/1/orb"+"roweop"+"z"+(b)+"/"+a.x+"_"+a.y+"_"+b+".gif"
	      return "/maps-features/TileData.ashx?op=roweop&b1="+(b)+"&x="+a.x+"&y="+a.y+"&b2="+b
      }
	  
	  // ============================================================
      // ===== Create the GTileLayers =====
      // ===== and apply the CustomGetTileUrl to it
     	  
	  // Section tiles
	  var rdstile = [new GTileLayer(copyrightCollection,14,14)];
      rdstile[0].getTileUrl = rdsUrl;
	  //var eoptile = [new GTileLayer(copyrightCollection,14,14)];
      //eoptile[0].getTileUrl = eopUrl;     
      var rowtile = [new GTileLayer(copyrightCollection,14,14)];
      rowtile[0].getTileUrl = rowUrl;     	  
	  
      // ============================================================
      // ===== Create the GMapTypes =====
      // ===== and add it to the map =====

		// Roads
		var tilelayers = [
			G_HYBRID_MAP.getTileLayers()[0], // Gets the satellite tiles
			G_HYBRID_MAP.getTileLayers()[1], // a reference to the upper tile layer of the hybrid map
			rdstile[0]
		];

		var custommap = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "Roads",{errorMessage:"Not Available"});
		map.addMapType(custommap);

		// Row
		var tilelayers3 = [
			G_HYBRID_MAP.getTileLayers()[0], // Gets the satellite tiles
			G_HYBRID_MAP.getTileLayers()[1], // a reference to the upper tile layer of the hybrid map
			rowtile[0]
		];

		var custommap3 = new GMapType(tilelayers3, G_SATELLITE_MAP.getProjection(), "Rt. of Way",{errorMessage:"Not Available", alt:"View Right Of Way and Edge of Pavement designations"});
		map.addMapType(custommap3);

		// Zoom Control
		  map.addControl(new GZoomControl(
		// first set of options is for the visual overlay.
		{
			nOpacity:.2,
			sBorder:"2px solid red"
		},
		// second set of optionis is for everything else
		{
			sButtonHTML:"<img src='/images/zoom-button.gif' />",
			sButtonZoomingHTML:"<img src='/images/zoom-button-activated.gif' />",
			oButtonStartingStyle:{width:'24px',height:'24px'}
		},
		// third set of options specifies callbacks
		{
			buttonClick:function(){display("Looks like you activated GZoom!")},
			dragStart:function(){display("Started to Drag . . .")},
			dragging:function(x1,y1,x2,y2){display("Dragging, currently x="+x2+",y="+y2)},
			dragEnd:function(nw,ne,se,sw,nwpx,nepx,sepx,swpx){display("Zoom! NE="+ne+";SW="+sw)}
		}
	    ));
		map.enableDoubleClickZoom();
		// End of Zoom App



		// ============================================================
		// Check for querystring map values
		// ============================================================
		var ml = 0;
		var QStr = new Querystring();
		ml = QStr.get("ml");
		
			//-------------------------------------
			// Map Location Data
			// Format[ Name; Lat, Lon values; Map Type; Zoom Level ]
			// Map type options: G_NORMAL_MAP, G_SATELLITE_MAP, G_HYBRID_MAP, custommap (roads), custommap2 (eop), custommap3 (row)
			//-------------------------------------
				
				// Downtown Kennedy Interchange; 38.260626, -85.735588; custommap; 16
				// Downtown Bridge; 38.264754, -85.743763; custommap; 16
				// Downtown IN Approach; 38.274895, -85.748849; custommap; 16
				// East End KY Approach; 38.322400, -85.615940; custommap; 16
				// East End Bridge; 38.342767, -85.643449; custommap; 16
				// East End IN Approach; 38.348758, -85.666666; custommap; 16
				// Default map; 38.265546, -85.744214; custommap; 15
		
		
		// ============================================================
		// Call Map Center function
		// ============================================================
		switch (ml) {
			case "1": // DT Kennedy Int.
				map.setCenter(new GLatLng(38.260626, -85.735588), 14, custommap);
				break;
			case "2": // DT Bridge
				map.setCenter(new GLatLng(38.264754, -85.743763), 16, custommap);
				break;
			case "3": // DT IN Appr.
				map.setCenter(new GLatLng(38.274895, -85.748849), 15, custommap);
				break;
			case "4": // EE KY Appr.
				map.setCenter(new GLatLng(38.322400, -85.615940), 14, custommap);
				break;
			case "5": // EE Bridge
				map.setCenter(new GLatLng(38.342767, -85.643449), 16, custommap);
				break;
			case "6": // EE IN Appr.
				map.setCenter(new GLatLng(38.348758, -85.666666), 15, custommap);
				break;
			case "a":
				var ga = QStr.get("ga");
				
				//$.get("http://maps.google.com/maps/geo?q="+ga+"&key=ABQIAAAArRigbvLK674Q21Jw-JFIDRRRQqmoa-CnMbGfsQfa03ny5c65BBQj3EleyswLBQLQ-B0WvXS6Fhrnng&output=csv", 
					//function(data){
						//alert("Data Loaded: " + data);
				//});
				
				$.get("http://www.google.com", 
					function(data){
						alert("Data Loaded: " + data);
				});
				
				break;
			default:
				map.setCenter(new GLatLng(38.265546, -85.744214), 15, custommap);
		}
          
		// wire up EOP/ROW button action 
		$("#map .gmnoprint div div:contains('Rt. of Way')").click(function() {
			showEopRowWarning();
		});
						
		// hide it when clicking anywhere on the map
		$("#map").click(function() {
			removeEopRowWarning();
		});
		
		// hide it when escape is pressed
		$(document).keyup(function(event){
			if (event.keyCode == 27) {
				removeEopRowWarning();
			}
		});		
		
    }
    
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
		
		}
    }
    

function showEopRowWarning()
{
	$("#map").append($("#divEopRow")[0]);
}

function removeEopRowWarning()
{
	$("#divEopRowHolder").append($("#divEopRow")[0]);
}

