﻿//Basic Map
	//<![CDATA[
		var map;
	    var gdir;
	    var geocoder = null;
	    var geoCoder = new GClientGeocoder();
	    
	//		 30.217023i, -85.677481
	    
			var arena = new oMapLocation("arena","Cabarrus Arena &amp; Event Center","4751 US Highway 49 North","Concord","NC","28025","(704) 920-3976","http://www.cabarrusarena.com");
	    var airport = new oMapLocation("airport","Concord Regional Airport","9000 Aviation Blvd NW","Concord","NC","28027","(704) 793-9000","http://www.ci.concord.nc.us/Departments/Airport/tabid/89/Default.aspx");
	    var hotels = new Array();
	    //hotels.push(new oMapLocation("hotel","Hilton Garden Inn","363 East Main Street","Tupelo","MS","38801","(662) 718-5500","http://hiltongardeninn.hilton.com/en/gi/hotels/photo_gallery.jhtml?ctyhocn=TUPTUGI"));
	    //hotels.push(new oMapLocation("hotel","Wingate Inn","186 Stone Creek Blvd","Tupelo","MS","38804","(662) 680-8887","http://www.wingateinns.com/Wingate/control/Booking/property_info?propertyId=30501&brandInfo=WG&cid=%EAid!"));
	    //hotels.push(new oMapLocation("hotel","Hampton Inn","1516 McCullough Boulevard","Tupelo","MS","38804","(662) 840-8300",null));
	   // hotels.push(new oMapLocation("hotel","Quality Inn","1011 North Gloster Street","Tupelo","MS","38804","(662) 841-2222",null));
	    
	    function load() 
	    {
	      if (GBrowserIsCompatible()) 
	      {
	        map = new GMap2(document.getElementById("map"));
	        map.addControl(new GLargeMapControl());
	        map.addControl(new GMapTypeControl());
	        
					map.setCenter(new GLatLng(30.206119,-85.7460595), 12);
	        
	        
	        hotels.each(function(h)
	        {
	        	h.addDirections(arena);
	        	h.addDirections(airport);
	        	arena.addDirections(h);
	        	airport.addDirections(h);
	       		h.setMap(map);
						if (h.point == null)
	       			geoCoder.getLatLng(h.getFullAddress(), function(point){h.setPoint(point)});
						else
							h.setPoint(h.point);
	        });
	        arena.addDirections(airport)
	        airport.addDirections(arena)
	        arena.setMap(map)
					if (arena.point == null)
	        	geoCoder.getLatLng(arena.getFullAddress(), function(point){arena.setPoint(point),arena.openInfoWindow();});
					else
						arena.setPoint(arena.point);
	        airport.setMap(map)
					if (airport.point == null)
	        	geoCoder.getLatLng(airport.getFullAddress(), function(point){airport.setPoint(point)});
					else
						airport.setPoint(airport.point);
	               
	      }
	    }
      
       function setDirections(fromAddress, toAddress, locale, zoomout) 
       {
       		
			map = new GMap2(document.getElementById("map"));
	        map.addControl(new GSmallMapControl());
	        map.addControl(new GMapTypeControl());
			gdir = new GDirections(map, document.getElementById("directions"));
			GEvent.addListener(gdir, "load", onGDirectionsLoad);
			GEvent.addListener(gdir, "error", handleErrors(fromAddress,toAddress));	        
			gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
	   }

	    function handleErrors(from, to)
	    {
	     document.getElementById('map_head').style.width = '780px';
		   document.getElementById('dir_head').style.display= 'none';
		   document.getElementById('map').style.width="710px";
		   document.getElementById('directions').style.display = 'none';
		   //load();
			 location.href = "http://maps.google.com/maps?saddr="+from+"&daddr="+to
			 //alert(from)
		  /* if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		    alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
		   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
		   
		   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

		   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
	
		   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
		    
		   else alert("An unknown error occurred.");
		   */
		   
			   
		}
	function GetDirectionsNew(from,to,zoomOut)
	{
		
		document.getElementById('map_head').style.width = '373px';
		document.getElementById('dir_head').style.display= 'block';
		document.getElementById('map').style.width="373px";
		document.getElementById('directions').style.display = 'block';
		
        setDirections(from, to, 'en_US');
        //if (form == 'Arena2Hotel' || form == 'Hotel2Arena')
        if (zoomOut)
			GEvent.addListener(map, "load", function() { map.zoomOut(); });
	}
	
	function back2big()
	{
		document.getElementById('map_head').style.width = '780px';
		document.getElementById('dir_head').style.display= 'none';
		document.getElementById('map').style.width="780px";
		document.getElementById('directions').style.display = 'none';
		gdir.clear();
		load();
		
	}
	function onGDirectionsLoad()
	{ 
		// Use this function to access information about the latest load()
	}
	//GSearch.setOnLoadCallback(load);
	//]]>
