
var AxGoogleMap={mapDOM:null,dirDOM:null,origin:null,destination:null,travelMode:null,mapTypeId:null,disableDefaultUI:null,zoom:null,center:null,markers:null,listeners:null,ready:false,directionsRenderer:null,directionsResult:null,construct:function(){this.markers=new Array();this.listeners=new Array();},init:function(){this.loadDefaults();this.buildMapOptions();this.initMap();this.initRenderer();this.initTravelMode();this.ready=true;},isReady:function(){return this.ready;},initMap:function(){this.map=new google.maps.Map(this.mapDOM,this.mapOptions);},initRenderer:function(){this.directionsRenderer=new google.maps.DirectionsRenderer({map:this.map});},initTravelMode:function(){this.setTravelMode(google.maps.DirectionsTravelMode.DRIVING);},initDir:function(){this.directionsRenderer.setPanel(this.dirDOM);},buildRequest:function(){this.request={destination:this.destination,origin:this.origin,travelMode:this.travelMode};},requestDirections:function(){var directionService=new google.maps.DirectionsService();directionService.route(this.request,function(result,status){if(status==google.maps.DirectionsStatus.OK){AxGoogleMap.setDirectionsResult(result);AxGoogleMap.directionsRenderer.setDirections(result);AxGoogleMap.listener('requestDirections');}});},buildMapOptions:function(){this.mapOptions={center:this.center,zoom:this.zoom,mapTypeId:this.mapTypeId,disableDefaultUI:this.disableDefaultUI};},loadDefaults:function(){this.setMapDOMId(getMapDOMName());this.setDirDOMId(getDirDOMName());this.setMapTypeId(google.maps.MapTypeId.ROADMAP);this.setDisableDefaultUI(false);this.setZoom(getInitZoom());this.setTravelMode(google.maps.DirectionsTravelMode.WALKING);this.setCenter(getInitCenter());},setZoom:function(myZoom){this.zoom=myZoom;},setDisableDefaultUI:function(myDisableDefaultUI){this.disableDefaultUI=myDisableDefaultUI;},setDestination:function(myDestination){this.destination=myDestination;},setOrigin:function(myOrigin){this.origin=myOrigin;},setTravelMode:function(myTravelMode){this.travelMode=myTravelMode;},setMapTypeId:function(myMapTypeId){this.mapTypeId=myMapTypeId;},setMapDOMId:function(myMapDOMId){this.mapDOM=document.getElementById(myMapDOMId);},setDirDOMId:function(myDirDOMId){this.dirDOM=document.getElementById(myDirDOMId);},setCenter:function(myCenter){this.center=myCenter;},setDirectionsResult:function(result){this.directionsResult=result;},onlyShowMarker:function(theCityName){if(theCityName&&theCityName.length>0){for(cityName in AxGoogleMap.markers){if(typeof(AxGoogleMap.markers[cityName])=="object"){if(cityName==theCityName){AxGoogleMap.markers[cityName].setVisible(true);}else{AxGoogleMap.markers[cityName].setVisible(false);}}}}},setMarkerFromAddress:function(cityName,countryName,countryTLD,onlyShowThisMarker){if(onlyShowThisMarker){this.setListener('setMarker',AxGoogleMap.onlyShowMarker,cityName);}
if(this.markers[cityName]){this.listener('setMarker');return;}
if(countryName){var theAddress=cityName+", "+countryName;}else{var theAddress=cityName;}
if(countryTLD){var myGEOReq={address:theAddress,region:countryTLD}}else{var myGEOReq={address:theAddress}}
var myGeocoder=new google.maps.Geocoder();myGeocoder.geocode(myGEOReq,function(results,status){if(status==google.maps.GeocoderStatus.OK){for(x in results){if(results[x].geometry){var t=new Array();var s="";for(y in results[x].address_components){if(results[x].address_components[y].long_name){t.push(results[x].address_components[y].long_name);if(s==""){s=results[x].address_components[y].long_name;}}}
var title=t.join(", ");AxGoogleMap.setMarker(results[x].geometry.location,s,title);AxGoogleMap.listener('setMarkerFromAddress');}}}else{window.alert("Niet gevonden: "+status);}});},setMarker:function(latlng,cityName,title){var marker=new google.maps.Marker({map:this.map,position:latlng,title:title});if(this.markers[cityName]){this.markers[cityName].position=latlng;this.markers[cityName].title=title;}else{this.markers[cityName]=marker;}
this.listener('setMarker');},getMarkers:function(){return this.markers;},listener:function(calledFunction){if(typeof(this.listeners[calledFunction])=='object'&&typeof(this.listeners[calledFunction]['function'])=='function'){switch(typeof(this.listeners[calledFunction]['argv'])){case'object':var newArgv=new Array();for(i in this.listeners[calledFunction]['argv']){newArgv[i]=eval(this.listeners[calledFunction]['argv'][i]);}
break;case'string':default:newArgv=this.listeners[calledFunction]['argv'];break;}
this.listeners[calledFunction]['function'](newArgv);}},setListener:function(calledFunction,functionToCall,argv){if(typeof(calledFunction)=='string'&&typeof(functionToCall)=='function'&&(typeof(argv)=="object"||typeof(argv)=="string")){this.listeners[calledFunction]=new Array();this.listeners[calledFunction]["function"]=functionToCall;this.listeners[calledFunction]["argv"]=argv;}}}
function loadScript(){var script=document.createElement("script");script.type="text/javascript";script.src="http://maps.google.com/maps/api/js?sensor=false&language=nl&region=NL&callback=AxGoogleMap.init";document.body.appendChild(script);}
addWindowOnloadAfter(loadScript);AxGoogleMap.construct();
