/*############################################################################*/
/*# Initialize */

function Main_Initialize()
{
  // init functions here
}

if ('function' == typeof WHITE_AddBodyLoadFunction)
{
  WHITE_AddBodyLoadFunction(Main_Initialize);
}
if ('function' == typeof WHITE_AddLoadEvent)
{
  WHITE_AddLoadEvent(WHITE_ChangeOverImagesInit);
}

/*# /Initialize */
/*############################################################################*/

/*#############################################################################
# Google maps function
#############################################################################*/

if('function' == typeof GoogleLoadMap)
{
  WHITE_AddLoadEvent(GoogleLoadMap);
}

// Put here the finish location for the Google Directions part
var sToLocation = "Luikerweg 25a, 5554 NA Valkenswaard";

function GoogleLoadMap() {
  var oGoogleMapDiv = WHITE_GetElementFlex('map');
  if ('object' == typeof oGoogleMapDiv)
  {
    if (GBrowserIsCompatible()) {
      var map = new GMap2(oGoogleMapDiv);
      var point = new GLatLng(51.34936, 5.45711);

      map.setCenter(point, 15);
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      map.setMapType(G_NORMAL_MAP);

      /* Part for the directions */
      gdir = new GDirections(map, document.getElementById("directions"));
      GEvent.addListener(gdir, "error", handleErrors);
      /* End directions */

      var marker = new GMarker(point);
      var html = "<b>Luikerweg 25a<br />5554 NA Valkenswaard<\/b>";
      GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); });

      map.addOverlay(marker);

      marker.openInfoWindowHtml(html);
    }
  }
}

function handleErrors(){
  if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	 alert("Google heeft uw locatie niet kunnen vaststellen. De beste manier om de route te zoeken, is door het volgende formaat aan te houden: straatnaam nummer, plaats.");
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("Er heeft zich een fout voor gedaan op de server van Google. Probeert u het nog een keer.\n Fout code code: " + gdir.getStatus().code);

else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("De HTTP q parameter mist of heeft geen waarde.\n Fout code: " + gdir.getStatus().code);

	else if (gdir.getStatus().code == G_GEO_BAD_KEY)
  	alert("De opgegeven sleutel is niet geldig. \n Fout 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("U heeft het veld 'Vertrekpunt' leeg gelaten. Deze is vereist om een route te plannen");
}

function setDirections(sFromAddress, locale) {
  gdir.load("from: " + sFromAddress +" to: "+sToLocation,{ "locale": locale });
}

