﻿//Basic Map
	//<![CDATA[
		var map;
	    var gdir;
	    var geocoder = null;
	    var geoCoder = new GClientGeocoder();
	    
	    var arena = new oMapLocation("arena","BancorpSouth Arena","375 E Main St","Tupelo","MS","38804","(662) 841-6528","http://www.bcsarena.com");
			var airports = new Array();
	    airports.push(new oMapLocation("airport","Tupelo Regional Airport","2704 W Jackson St","Tupelo","MS","38801","(662) 841-6570","http://www.flytupelo.com"));
	    airports.push(new oMapLocation("airport","Memphis International","2491 Winchester Rd","Memphis","TN","38116","(901) 922-8000","http://www.mscaa.com/index.html"));
	    var airport = new oMapLocation("airport","Tupelo Regional Airport","2704 W Jackson St","Tupelo","MS","38801","(662) 841-6570","http://www.flytupelo.com");
	    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","Holiday Inn","1612 McClure Cove","Tupelo","MS","38804","(662) 620-8184",null));
	    hotels.push(new oMapLocation("hotel","Sleep Inn","1721 North Gloster Street","Tupelo","MS","38804","(662) 840-7737",null));
	    hotels.push(new oMapLocation("hotel","Baymont Inn","625 Spicer Drive","Tupelo","MS","38804","(662) 844-7660",null));
	    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));
	    hotels.push(new oMapLocation("hotel","Courtyard by Marriot","1320 North Gloster Street","Tupelo","MS","38804","(662) 841-9960",null));
	    
	    function load() 
	    {
	      if (GBrowserIsCompatible()) 
	      {
	        map = new GMap2(document.getElementById("map"));
	        map.addControl(new GLargeMapControl());
	        map.addControl(new GMapTypeControl());
			var options = {
				searchFormHint : "ex Searches: Attractions",
				linkTarget : GSearch.LINK_TARGET_BLANK,
				title : "Tupelo, MS",
				url : "http://www.bcsarena.com"
			};
	        map.addControl(new google.maps.LocalSearch(options), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10)));
	        map.setCenter(new GLatLng(34.257537,-88.69883), 12);
	        
	        
	        hotels.each(function(h)
	        {
	        	h.addDirections(arena);
						airports.each(function(a)
						{
	        		h.addDirections(a);
							a.addDirections(h);
						});	
	        	//h.addDirections(airport);
	        	arena.addDirections(h);
	        	//airport.addDirections(h);
	       		h.setMap(map);
	       		geoCoder.getLatLng(h.getFullAddress(), function(point){h.setPoint(point)});
	        });
					airports.each(function(a)
					{
	       		a.addDirections(arena);
						arena.addDirections(a);
						a.setMap(map);
	       		geoCoder.getLatLng(a.getFullAddress(), function(point){a.setPoint(point)});
					});	
	        //arena.addDirections(airport)
	        //airport.addDirections(arena)
	        arena.setMap(map)
	        geoCoder.getLatLng(arena.getFullAddress(), function(point){arena.setPoint(point),arena.openInfoWindow();});
	        //airport.setMap(map)
	        //geoCoder.getLatLng(airport.getFullAddress(), function(point){airport.setPoint(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);	        
			gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
	   }

	    function handleErrors()
	    {
	       document.getElementById('map_head').style.width = '710px';
		   document.getElementById('dir_head').style.display= 'none';
		   document.getElementById('map').style.width="710px";
		   document.getElementById('directions').style.display = 'none';
		   load();
		   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 = '353px';
		document.getElementById('dir_head').style.display= 'block';
		document.getElementById('map').style.width="353px";
		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 = '710px';
		document.getElementById('dir_head').style.display= 'none';
		document.getElementById('map').style.width="710px";
		document.getElementById('directions').style.display = 'none';
		gdir.clear();
		load();
		
	}
	function onGDirectionsLoad()
	{ 
		// Use this function to access information about the latest load()
	}
	GSearch.setOnLoadCallback(load);
	//]]>
