	window.addEvent('domready', function()
		{


			box = new MultiBox('mb', {descClassName: 'mbBox'});
			
			var google_map_SF = $('google_map_SF');
			google_map_SF.get('tween').options.duration = 1000;
			google_map_SF.fade('hide');	
			
			var google_map_LA = $('google_map_LA');
			google_map_LA.get('tween').options.duration = 1000;
			google_map_LA.fade('hide');	
			
			$('SF_map_link').addEvent('click', function(event){
				event = new Event(event).stop();
				google_map_SF.fade('in');	
			});
			
			$('map_close_SF').addEvent('click', function(event){
				event = new Event(event).stop();
				google_map_SF.fade('out');	
			});
			
			$('LA_map_link').addEvent('click', function(event){
				event = new Event(event).stop();
				google_map_LA.fade('in');	
			});
			
			$('map_close_LA').addEvent('click', function(event){
				event = new Event(event).stop();
				google_map_LA.fade('out');	
			});
		
		});
		
		
		
		
		var map;
    var gdir;
    var geocoder = null;
    var addressMarker;


    function initialize_SF(map_div,map_address,city) {
      if (GBrowserIsCompatible()) {
        map_SF = new GMap2(document.getElementById(map_div));
				gdir = new GDirections(map, document.getElementById("directions_result"));
				GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
				
				geocoder = new GClientGeocoder();
				showAddress_SF(map_address,city);
				
      }
    }
		
		function initialize_LA(map_div,map_address,city) {
      if (GBrowserIsCompatible()) {
        map_LA = new GMap2(document.getElementById(map_div));
				gdir = new GDirections(map, document.getElementById("directions_result"));
				GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
				
				geocoder = new GClientGeocoder();
				showAddress_LA(map_address,city);
				
      }
    }

    function showAddress_SF(address,city) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map_SF.setCenter(point, 16);
              var marker_SF = new GMarker(point);
              map_SF.addOverlay(marker_SF);
							map_SF.addControl(new GSmallMapControl());
			        map_SF.addControl(new GMapTypeControl());
              //marker_SF.openInfoWindowHtml('<div style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; width: 300px;"><p style="margin: 0; float: left; width: 100px;"><strong style="color: #262626;">POPGUN<br />' + city + '</strong></p><p style="text-align: right; margin: 0;"><a href="http://maps.google.com/maps?q=' + address.replace(/ /ig,'+') + '" target="_blank">Show in Google Maps</a></p></div>');

            }
          }
        );
      }
    }
		
		function showAddress_LA(address,city) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map_LA.setCenter(point, 16);
              var marker_LA = new GMarker(point);
              map_LA.addOverlay(marker_LA);
							map_LA.addControl(new GSmallMapControl());
			        map_LA.addControl(new GMapTypeControl());
              //marker_LA.openInfoWindowHtml('<div style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; width: 300px;"><p style="margin: 0;"><strong style="color: #262626; width: 100px; float: left;">POPGUN<br />' + city + '</strong></p><p style="text-align: right; margin: 0;"><a href="http://maps.google.com/maps?q=' + address.replace(/ /ig,'+') + '" target="_blank">Show in Google Maps</a></p></div>');

            }
          }
        );
      }
    }



    function handleErrors(){
	   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 onGDirectionsLoad(){ 
	}
	
	
	function postDirections(addr)
		{		
			addr = addr.replace(/^\s+|\s+$/g, '');
			addr = addr.replace(/ /,"+");
			setDirections(addr, '', 'en');
			var view_link = document.getElementById('view_map');
			view_link.style.display = '';
			//view_link.href = "http://maps.google.com/maps?q=from:+" + addr + "+to:+Vincent+Street,+Daylesford+Victoria";
			
		}
	

		
