
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
	
	var mainOffice;
    var satelliteOffice;
    var errorDiv;
    
    var mainOfficeMarker;
    var satelliteOfficeMarker;
    
    var toMarker;
    
    function load() {
      
      if (GBrowserIsCompatible()) {    
      	
      	errorDiv = document.getElementById('mapError');//sets the element that should display error messages
      	
      	//these lines grab whatever HTML is inside the named divs in order to show them in the map bubble
      	mainOffice = 'Main Office - Suwanee'; 
      	satelliteOffice = 'Satellite Office - Lawrenceville';
      	 
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());//add directional/zoom controls
        
        gdir = new GDirections(map, document.getElementById("directions"));
        
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
		
		map.setCenter(new GLatLng(34.072228,-84.171012),9);
		

		
		var point1 = new GLatLng(34.072228,-84.171012);
		var point2 = new GLatLng(33.958282,-84.014275);
		
		mainOfficeMarker = new GMarker(point1);
		mainOfficeMarker.bindInfoWindow(mainOffice);
		
		satelliteOfficeMarker = new GMarker(point2);
		satelliteOfficeMarker.bindInfoWindow(satelliteOffice);
		
		map.addOverlay(mainOfficeMarker);
		map.addOverlay(satelliteOfficeMarker);
		
      }
    }
    
    function setDirections(fromAddress, office) {
    
    	switch(office)
    	{
    		case "mainOffice":
    			toMarker = 'mainOffice';
    			toAddress = '4375 Johns Creek Pkwy, Ste 330 Suwanee, GA 30024';
    			break;
    		case "satelliteOffice":
    			toMarker = 'satelliteOffice';
    			toAddress = '753 Old Norcross Road, Suite A Lawrenceville, GA 30045';
    			break;
    		default:
    			toMarker = 'mainOffice';
				toAddress = '4375 Johns Creek Pkwy, Ste 330 Suwanee, GA 30024';
    	}

      	map.removeOverlay(mainOfficeMarker);
		map.removeOverlay(satelliteOfficeMarker);
      	
      	errorDiv.style.display = "none";
      	gdir.load("from: " + fromAddress + " to: " + toAddress);
    }


	function onGDirectionsLoad(){ 
		marker = gdir.getMarker(1);
		GEvent.addListener(marker,'click',showInfo());
	}	
	
	function showInfo()
	{
		content = document.getElementById(toMarker).innerHTML;
		marker.bindInfoWindowHtml(content);
	}
	
	function handleErrors(){
	errorDiv.style.display = "";
	
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	    errorDiv.innerHTML = "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)
	    errorDiv.innerHTML = "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)
	     errorDiv.innerHTML = "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)
	     errorDiv.innerHTML = "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)
	     errorDiv.innerHTML = "A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code;
	    
	   else errorDiv.innerHTML = "An unknown error occurred.";
	   
	}
	
	Event.observe(window,'load',function(){
		load();
	});