//<![CDATA[
var map = null;
var geocoder = null;


// Create our "tiny" marker icon
var icon = new GIcon();
icon.image = "images/marker.png";
icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(12, 20);
icon.infoWindowAnchor = new GPoint(25, 1);


var marker;

var sInfo;
var sInfoRoute;

// Initialize the main google map.
function initMap(adress, titel, html_adres) {
	if (GBrowserIsCompatible()) {
    
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	
    map.setCenter(new GLatLng('52.20150497525112', '4.700260162353516'), 13);
	geocoder = new GClientGeocoder();
	
	showAddress(adress, titel, html_adres);
	}
}

// Adres op map weergeven
function showAddress(adress, titel, html_adres) {	
  geocoder.getLatLng(
    adress+', Nederland',
    function(point) {
      if (!point) {
        alert(adress + " not found");
      } else {
        map.setCenter(point, 13);
        marker = new GMarker(point, icon);
        map.addOverlay(marker);
		
		sInfo = '<strong style="font-size:14px;font-weigth:bold;">' + titel + '</strong><br>';
        sInfo = sInfo + html_adres;
				
		sInfo = sInfo + '<p>Klik <a style=\'text-decoration:underline;\' href="#" onclick="openRouteInfo(\'' + adress + ', Nederland\', \'' + titel + '\');return false;">hier</a> voor een route beschrijving.</p>';		
        //marker.openInfoWindowHtml(sInfo);
      }
    }
  );
}

function openRouteInfo(adress, titel) {
	
	sInfoRoute = '<strong style="font-size:14px;font-weigth:bold;">' + titel + '</strong><p><form id="route" class="route" action="javascript:void(0)">Vul uw adres in voor een routebeschrijving <br />naar <i>' + adress + '</i>.<br /><table><tr><td>Straatnaam:</td><td><input type="text" id="saddr" /></td><td></td></tr><tr><td>Woonplaats:</td><td><input type="text" id="splaa" /></td><td></td></tr><tr><td></td><td><input type="submit" onclick="javascript:route();return false;" class="btn_85" value="Toon route"></td></tr></table><input type="hidden" id="planner_adres" value="' + adress + '" /></form>';
	
	marker.openInfoWindowHtml( sInfoRoute + '</p>');
}


/**************************
*	Routeplanner
**************************/
function route(){
	// Start address -> moet in het formaat "straat, plaatsnaam" zijn
	saddr = document.getElementById("saddr").value;
	splaa = document.getElementById("splaa").value;

	// Adres van locatie
	daddr = document.getElementById("planner_adres").value;
	
	
	// Url
	url = 'http://maps.google.nl/?ie=UTF8&hl=nl&saddr=' + saddr +',' + splaa + '&daddr=' + daddr + '&f=d&sampleq=1';

	if(saddr != '' && splaa != ''){
		var load = window.open(url,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');	
	} else {
		alert('Vul a.u.b. een straat en plaatsnaam in.');
	}
}

//]]>
