key = 'ABQIAAAAiQLTb9gQUkPR-39vsZildBQHr6y_ejSzzUIuEPbHQZw-uHnFMBQm2yZAUhkVcU_MpngOTHUv5KE-6w';
var scriptTag = '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='+key+'" type="text/javascript">' + '<' + '/script' + '>';
document.write(scriptTag);

jQuery(function($) {
	 $(document).ready(function () {
	     if ($("#map").length ==1 && GBrowserIsCompatible()) {
		      //settings
			  var companyMarkerImage= "/assets/img/marker.gif";
			  var companyLatLng     = new GLatLng(51.875855,-0.385594);
			  var companyMarkerSize = new GSize(52, 44); //width, height

			  var defaultZoomLevel  = 15;
			  //end settings

			  //setup elements
			  var map   = new GMap2(document.getElementById("map"));
			  map.setUIToDefault();
			  gdir  = new GDirections(map, document.getElementById("directions"));

			  //error handler
			  GEvent.addListener(gdir, "error", function (){
				    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.");
				  });

			  createMarker = function(latlng, imageURL, imageSize)
			  {

			      var marker      = new GIcon(G_DEFAULT_ICON, imageURL);
			      marker.iconSize = imageSize;

			      return new GMarker(latlng, { icon: marker });

			  }

			  //set company marker
			  var companyMarker = createMarker(companyLatLng, companyMarkerImage, companyMarkerSize);

			  //set map center
			  map.setCenter(companyLatLng, defaultZoomLevel);
			  map.addOverlay(companyMarker);




			  $('#getDirections').bind("click", function(e){
			      gdir.load("from: " + $('#from').get(0).value + " to: " + "51.875855,-0.385594");
			  });
		}
	 });
});
