// JavaScript Document
var directions;
var directionsPanel;
var geocoder;
var map;
var point;
var address = '407 Cincinnati Street, Delhi, Louisiana 71232';
var bindInfo = "<center><span style='color:#000;'>Delhi Hospital</strong><br/>407 Cincinnati Street,<br/> Delhi, Louisiana 71232<br />Phone: (318) 878-5171 <br/>Fax: (318) 878-6363<br/><a style='color:#0000ff' target='_blank' href='http://maps.google.com/maps?saddr=&daddr=407+Cincinnati+Street,+Delhi,+Louisiana+71232'><br/>Get Driving Directions</a></span></center>";



/*$(document).ready(function() {


 	$('#monroeoffice').click(function(){
		address = '601 Clyde Fant Pkwy, Shreveport, LA 71101';
		bindInfo = "<center><span style='color:#000;'>Barnwell Garden and Art Center</strong><br/>7601 Clyde Fant Pkwy,<br/> Shreveport, LA 71101<br /><a style='color:#0000ff' target='_blank' href='http://maps.google.com/maps?saddr=&daddr=7601+Clyde+Fant+Pkwy,+Shreveport+LA+71101'>Get Driving Directions</a></span></center>";
		loadMap(address);
		
	});
	
	$('#corporateoffice').click(function(){
		address = '601 Clyde Fant Pkwy, Shreveport, LA 71101';
		bindInfo = "<center><span style='color:#000;'>Barnwell Garden and Art Center</strong><br/>7601 Clyde Fant Pkwy,<br/> Shreveport, LA 71101<br /><a style='color:#0000ff' target='_blank' href='http://maps.google.com/maps?saddr=&daddr=7601+Clyde+Fant+Pkwy,+Shreveport+LA+71101'>Get Driving Directions</a></span></center>";
		loadMap(address);
	});
});
*/


function loadMap() 
{
	
	if (GBrowserIsCompatible())
	{
		map = new GMap2(document.getElementById("map"));
		geocoder = new GClientGeocoder();
		
		//add map type, zoom, and pan controls
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GLargeMapControl());
		
		geocoder.getLocations(address, addToMap);
	}
}




function addToMap(response)
{
  // Retrieve the object
  place = response.Placemark[0];

  // Retrieve the latitude and longitude
  point = new GLatLng(place.Point.coordinates[1],	place.Point.coordinates[0]);

  // Center the map on this point
  map.setCenter(point, 15);

  // Create a marker
  marker = new GMarker(point, {"clickable": true});

  // Add the marker to map
  map.addOverlay(marker);

 //point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
	//map.setCenter(point, 5);

  // Add address information to marker
//	marker.bindInfoWindow

   //marker.bindInfoWindow("<center><span style='color:#000;'>Synapse Multimedia</strong><br/>788 Brook Hollow Dr.<br/> Shreveport LA 71105<br /><a style='color:#0000ff' target='_blank' href='http://maps.google.com/maps?saddr=&daddr=788+Brook+Hollow+Dr.,+Shreveport+LA+71105'>Get Driving Directions</a></span></center>");
	//marker.openInfoWindow("<center><span style='color:#000;'>Synapse Multimedia</strong><br/>788 Brook Hollow Dr.<br/> Shreveport LA 71105<br /><a style='color:#0000ff' target='_blank' href='http://maps.google.com/maps?saddr=&daddr=788+Brook+Hollow+Dr.,+Shreveport+LA+71105'>Get Driving Directions</a></span></center>");
	marker.bindInfoWindow(bindInfo);
	marker.openInfoWindow(bindInfo);
}

function setDirections(fromAddress, toAddress)
{
	if(fromAddress != "" && toAddress != "")
	{
		directions.load("from: " + fromAddress + " to: " + toAddress, { "locale": "English" });
		showPrintButton();
	}
	else
	{
		if(fromAddress == "")
		{
			alert("Please enter a starting location.");
		}
		else if(toAddress == "")
		{
			alert("Please enter an ending location.");
		}
	}
}

function handleErrors()
{
   if (directions.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: " + directions.getStatus().code);
   else if (directions.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: " + directions.getStatus().code) 
   else if (directions.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: " + directions.getStatus().code);
//   else if (directions.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + directions.getStatus().code);
	 
   else if (directions.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: " + directions.getStatus().code);

   else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("A directions request could not be successfully parsed.\n Error code: " + directions.getStatus().code);
	
   else alert("An unknown error occurred.");
}

function onGDirectionsLoad()
{ 
  // Use this function to access information about the latest load()
  // results.


  // e.g.
  // document.getElementById("getStatus").innerHTML = directions.getStatus().code;
  // and yada yada yada...
}
