/* SVN $Id: main.js 96 2009-05-08 14:09:24Z jeroen $ */
/* SVN $URL: file:///T:/SOURCE_SVN/Start_Website/httpdocs/js/main.js $ */

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

function Main_Initialize()
{
  var oForm = WHITE_GetElementFlex('searchform');
  if ('object' == typeof oForm)
  {
    WHITE_InitFieldExplanation('searchfield', 'zoeken');
    WHITE_AddEvent(oForm, 'submit', WHITE_FormRemoveEplanationsEvent);
  }
  
  WHITE_InitAddBookmarkLinks();
  WHITE_AddBodyLoadFunction(GoogleLoadMap);
  
}

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

/*# /Initialize */

/*#############################################################################
# Google maps function
#############################################################################*/
// Put here the finish location for the Google Directions part
var sToLocation = "Esp 422, 5633 AJ Eindhoven";

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

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

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

      var marker = new GMarker(point);
      var html = "<strong>Verschuren Interieurbouw</strong><br>Esp 422<br>5633 AJ Eindhoven<br><br>0031 40 264 73 10";
      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 });
}
/*#############################################################################*/


function createFlashSizer(){
   
   var aParams = {
     allowscriptaccess:  "always"
   };
   
   var aFlashvars = {
   }

   swfobject.embedSWF("http://www.verschuren-interieurbouw.nl/flash/resizer.swf", "sizer", "672", "400", "10.0.0", "", aFlashvars, aParams);
}

createFlashSizer();
