var map, cluster, eventListeners=[], markersArray=[], json=[], icon;
var linkURL ='/zakelijk/aov_meter';

function ClusterMarker($map, $options){
	this._map=$map;
	this._mapMarkers=[];
	this._iconBounds=[];
	this._clusterMarkers=[];
	this._eventListeners=[];
	if(typeof($options)==='undefined'){
		$options={};
	}
	this.borderPadding=($options.borderPadding)?$options.borderPadding:256;
	this.clusteringEnabled=($options.clusteringEnabled===false)?false:true;
	if($options.clusterMarkerClick){
		this.clusterMarkerClick=$options.clusterMarkerClick;
	}
	if($options.clusterMarkerIcon){
		this.clusterMarkerIcon=$options.clusterMarkerIcon;
	}else{
		this.clusterMarkerIcon=new GIcon();
		this.clusterMarkerIcon.image='../img/icons/orange_button.png';
		this.clusterMarkerIcon.iconSize=new GSize(28, 28);
		this.clusterMarkerIcon.iconAnchor=new GPoint(14, 14);
		this.clusterMarkerIcon.infoWindowAnchor=new GPoint(28, 0);
		//this.clusterMarkerIcon.shadow='../img/icons/orange_button.png';
		//this.clusterMarkerIcon.shadowSize=new GSize(28, 28);
	}
	this.clusterMarkerTitle=($options.clusterMarkerTitle)?$options.clusterMarkerTitle:'Click to zoom in and see %count markers';
	if($options.fitMapMaxZoom){
		this.fitMapMaxZoom=$options.fitMapMaxZoom;
	}
	this.intersectPadding=($options.intersectPadding)?$options.intersectPadding:0;
	if($options.markers){
		this.addMarkers($options.markers);
	}
	GEvent.bind(this._map, 'moveend', this, this._moveEnd);
	GEvent.bind(this._map, 'zoomend', this, this._zoomEnd);
	GEvent.bind(this._map, 'maptypechanged', this, this._mapTypeChanged);
}

ClusterMarker.prototype.addMarkers=function($markers){
	var i;
	if(!$markers[0]){
		//	assume $markers is an associative array and convert to a numerically indexed array
		var $numArray=[];
		for(i in $markers){
			$numArray.push($markers[i]);
		}
		$markers=$numArray;
	}
	for(i=$markers.length-1; i>=0; i--){
		$markers[i]._isVisible=false;
		$markers[i]._isActive=false;
		$markers[i]._makeVisible=false;
	}
	this._mapMarkers=this._mapMarkers.concat($markers);
};

ClusterMarker.prototype._clusterMarker=function($clusterGroupIndexes){
	function $newClusterMarker($location, $icon, $title){
		return new GMarker($location, {icon:$icon, title:$title});
	}
	var $clusterGroupBounds=new GLatLngBounds(), i, $clusterMarker, $clusteredMarkers=[], $marker, $this=this, $mapMarkers=this._mapMarkers;
	for(i=$clusterGroupIndexes.length-1; i>=0; i--){
		$marker=$mapMarkers[$clusterGroupIndexes[i]];
		$marker.index=$clusterGroupIndexes[i];
		$clusterGroupBounds.extend($marker.getLatLng());
		$clusteredMarkers.push($marker);
	}
	$clusterMarker=$newClusterMarker($clusterGroupBounds.getCenter(), this.clusterMarkerIcon, this.clusterMarkerTitle.replace(/%count/gi, $clusterGroupIndexes.length));
	$clusterMarker.clusterGroupBounds=$clusterGroupBounds;	//	only req'd for default cluster marker click action
	this._eventListeners.push(GEvent.addListener($clusterMarker, 'click', function(){
		$this.clusterMarkerClick({clusterMarker:$clusterMarker, clusteredMarkers:$clusteredMarkers });
	}));
	$clusterMarker._childIndexes=$clusterGroupIndexes;
	for(i=$clusterGroupIndexes.length-1; i>=0; i--){
		$mapMarkers[$clusterGroupIndexes[i]]._parentCluster=$clusterMarker;
	}
	return $clusterMarker;
};

ClusterMarker.prototype.clusterMarkerClick=function($args){
	this._map.setCenter($args.clusterMarker.getLatLng(), this._map.getBoundsZoomLevel($args.clusterMarker.clusterGroupBounds));
};

ClusterMarker.prototype._filterActiveMapMarkers=function(){
	var $borderPadding=this.borderPadding, $mapZoomLevel=this._map.getZoom(), $mapProjection=this._map.getCurrentMapType().getProjection(), $mapPointSw, $activeAreaPointSw, $activeAreaLatLngSw, $mapPointNe, $activeAreaPointNe, $activeAreaLatLngNe, $activeAreaBounds=this._map.getBounds(), i, $marker, $uncachedIconBoundsIndexes=[], $oldState, $mapMarkers=this._mapMarkers, $iconBounds=this._iconBounds;
	if($borderPadding){
		$mapPointSw=$mapProjection.fromLatLngToPixel($activeAreaBounds.getSouthWest(), $mapZoomLevel);
		$activeAreaPointSw=new GPoint($mapPointSw.x-$borderPadding, $mapPointSw.y+$borderPadding);
		$activeAreaLatLngSw=$mapProjection.fromPixelToLatLng($activeAreaPointSw, $mapZoomLevel);
		$mapPointNe=$mapProjection.fromLatLngToPixel($activeAreaBounds.getNorthEast(), $mapZoomLevel);
		$activeAreaPointNe=new GPoint($mapPointNe.x+$borderPadding, $mapPointNe.y-$borderPadding);
		$activeAreaLatLngNe=$mapProjection.fromPixelToLatLng($activeAreaPointNe, $mapZoomLevel);
		$activeAreaBounds.extend($activeAreaLatLngSw);
		$activeAreaBounds.extend($activeAreaLatLngNe);
	}
	this._activeMarkersChanged=false;
	if(typeof($iconBounds[$mapZoomLevel])==='undefined'){
		//	no iconBounds cached for this zoom level
		//	no need to check for existence of individual iconBounds elements
		this._iconBounds[$mapZoomLevel]=[];
		this._activeMarkersChanged=true;	//	force refresh(true) as zoomed to uncached zoom level
		for(i=$mapMarkers.length-1; i>=0; i--){
			$marker=$mapMarkers[i];
			$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;
			$marker._makeVisible=$marker._isActive;
			if($marker._isActive){
				$uncachedIconBoundsIndexes.push(i);
			}
		}
	}else{
		//	icondBounds array exists for this zoom level
		//	check for existence of individual iconBounds elements
		for(i=$mapMarkers.length-1; i>=0; i--){
			$marker=$mapMarkers[i];
			$oldState=$marker._isActive;
			$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;
			$marker._makeVisible=$marker._isActive;
			if(!this._activeMarkersChanged && $oldState!==$marker._isActive){
				this._activeMarkersChanged=true;
			}
			if($marker._isActive && typeof($iconBounds[$mapZoomLevel][i])==='undefined'){
				$uncachedIconBoundsIndexes.push(i);
			}
		}
	}
	return $uncachedIconBoundsIndexes;
};

ClusterMarker.prototype._filterIntersectingMapMarkers=function(){
	var $clusterGroup, i, j, $mapZoomLevel=this._map.getZoom(), $mapMarkers=this._mapMarkers, $iconBounds=this._iconBounds;
	for(i=$mapMarkers.length-1; i>0; i--)
	{
		if($mapMarkers[i]._makeVisible){
			$clusterGroup=[];
			for(j=i-1; j>=0; j--){
				if($mapMarkers[j]._makeVisible && $iconBounds[$mapZoomLevel][i].intersects($iconBounds[$mapZoomLevel][j])){
					$clusterGroup.push(j);
				}
			}
			if($clusterGroup.length!==0){
				$clusterGroup.push(i);
				for(j=$clusterGroup.length-1; j>=0; j--){
					$mapMarkers[$clusterGroup[j]]._makeVisible=false;
				}
				this._clusterMarkers.push(this._clusterMarker($clusterGroup));
			}
		}
	}
};

ClusterMarker.prototype.fitMapToMarkers=function(){
	var $mapMarkers=this._mapMarkers, $markersBounds=new GLatLngBounds(), i;
	for(i=$mapMarkers.length-1; i>=0; i--){
		$markersBounds.extend($mapMarkers[i].getLatLng());
	}
	var $fitMapToMarkersZoom=this._map.getBoundsZoomLevel($markersBounds);
		
	if(this.fitMapMaxZoom && $fitMapToMarkersZoom>this.fitMapMaxZoom){
		$fitMapToMarkersZoom=this.fitMapMaxZoom;
	}
	this._map.setCenter($markersBounds.getCenter(), $fitMapToMarkersZoom);
	this.refresh();
};

ClusterMarker.prototype._mapTypeChanged=function(){
	this.refresh(true);
};

ClusterMarker.prototype._moveEnd=function(){
	if(!this._cancelMoveEnd){
		this.refresh();
	}else{
		this._cancelMoveEnd=false;
	}
};

ClusterMarker.prototype._preCacheIconBounds=function($indexes, $mapZoomLevel){
	var $mapProjection=this._map.getCurrentMapType().getProjection(), i, $marker, $iconSize, $iconAnchorPoint, $iconAnchorPointOffset, $iconBoundsPointSw, $iconBoundsPointNe, $iconBoundsLatLngSw, $iconBoundsLatLngNe, $intersectPadding=this.intersectPadding, $mapMarkers=this._mapMarkers;
	for(i=$indexes.length-1; i>=0; i--){
		$marker=$mapMarkers[$indexes[i]];
		$iconSize=$marker.getIcon().iconSize;
		$iconAnchorPoint=$mapProjection.fromLatLngToPixel($marker.getLatLng(), $mapZoomLevel);
		$iconAnchorPointOffset=$marker.getIcon().iconAnchor;
		$iconBoundsPointSw=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x-$intersectPadding, $iconAnchorPoint.y-$iconAnchorPointOffset.y+$iconSize.height+$intersectPadding);
		$iconBoundsPointNe=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x+$iconSize.width+$intersectPadding, $iconAnchorPoint.y-$iconAnchorPointOffset.y-$intersectPadding);
		$iconBoundsLatLngSw=$mapProjection.fromPixelToLatLng($iconBoundsPointSw, $mapZoomLevel);
		$iconBoundsLatLngNe=$mapProjection.fromPixelToLatLng($iconBoundsPointNe, $mapZoomLevel);
		this._iconBounds[$mapZoomLevel][$indexes[i]]=new GLatLngBounds($iconBoundsLatLngSw, $iconBoundsLatLngNe);
	}
};

ClusterMarker.prototype.refresh=function($forceFullRefresh){
	var i, $marker, $zoomLevel=this._map.getZoom(), $uncachedIconBoundsIndexes=this._filterActiveMapMarkers();
	if(this._activeMarkersChanged || $forceFullRefresh){
		this._removeClusterMarkers();
		if(this.clusteringEnabled && $zoomLevel<this._map.getCurrentMapType().getMaximumResolution()){
			if($uncachedIconBoundsIndexes.length>0){
				this._preCacheIconBounds($uncachedIconBoundsIndexes, $zoomLevel);
			}
			this._filterIntersectingMapMarkers();
		}
		for(i=this._clusterMarkers.length-1; i>=0; i--){
			this._map.addOverlay(this._clusterMarkers[i]);
		}
		for(i=this._mapMarkers.length-1; i>=0; i--){
			$marker=this._mapMarkers[i];
			if(!$marker._isVisible && $marker._makeVisible){
				this._map.addOverlay($marker);
				$marker._isVisible=true;
			}
			if($marker._isVisible && !$marker._makeVisible){
				this._map.removeOverlay($marker);
				$marker._isVisible=false;
			}
		}
	}
};

ClusterMarker.prototype._removeClusterMarkers=function(){
	var i, j, $map=this._map, $eventListeners=this._eventListeners, $clusterMarkers=this._clusterMarkers, $childIndexes, $mapMarkers=this._mapMarkers;
	for(i=$clusterMarkers.length-1; i>=0; i--){
		$childIndexes=$clusterMarkers[i]._childIndexes;
		for(j=$childIndexes.length-1; j>=0; j--){
			delete $mapMarkers[$childIndexes[j]]._parentCluster;
		}
		$map.removeOverlay($clusterMarkers[i]);
	}
	for(i=$eventListeners.length-1; i>=0; i--){
		GEvent.removeListener($eventListeners[i]);
	}
	this._clusterMarkers=[];
	this._eventListeners=[];
};

ClusterMarker.prototype.removeMarkers=function(){
	var i, $mapMarkers=this._mapMarkers, $map=this._map;
	for(i=$mapMarkers.length-1; i>=0; i--){
		if($mapMarkers[i]._isVisible){
			$map.removeOverlay($mapMarkers[i]);
		}
		delete $mapMarkers[i]._isVisible;
		delete $mapMarkers[i]._isActive;
		delete $mapMarkers[i]._makeVisible;
	}
	this._removeClusterMarkers();
	this._mapMarkers=[];
	this._iconBounds=[];
};

ClusterMarker.prototype.triggerClick=function($index){
	var $marker=this._mapMarkers[$index];
	if($marker._isVisible){
		//	$marker is visible
		GEvent.trigger($marker, 'click');
	}
	else if($marker._isActive){
		//	$marker is clustered
		var $clusteredMarkersIndexes=$marker._parentCluster._childIndexes, $intersectDetected=true, $uncachedIconBoundsIndexes, i, $mapZoomLevel=this._map.getZoom(), $clusteredMarkerIndex, $iconBounds=this._iconBounds, $mapMaxZoomLevel=this._map.getCurrentMapType().getMaximumResolution();
		while($intersectDetected && $mapZoomLevel<$mapMaxZoomLevel){
			$intersectDetected=false;
			$mapZoomLevel++;
			if(typeof($iconBounds[$mapZoomLevel])==='undefined'){
				//	no iconBounds cached for this zoom level
				//	no need to check for existence of individual iconBounds elements
				$iconBounds[$mapZoomLevel]=[];
				// need to create cache for all clustered markers at $mapZoomLevel
				this._preCacheIconBounds($clusteredMarkersIndexes, $mapZoomLevel);
			}else{
				//	iconBounds array exists for this zoom level
				//	check for existence of individual iconBounds elements
				$uncachedIconBoundsIndexes=[];
				for(i=$clusteredMarkersIndexes.length-1; i>=0; i--){
					if(typeof($iconBounds[$mapZoomLevel][$clusteredMarkersIndexes[i]])==='undefined'){
						$uncachedIconBoundsIndexes.push($clusteredMarkersIndexes[i]);
					}
				}
				if($uncachedIconBoundsIndexes.length>=1){
					this._preCacheIconBounds($uncachedIconBoundsIndexes, $mapZoomLevel);
				}
			}
			for(i=$clusteredMarkersIndexes.length-1; i>=0; i--){
				$clusteredMarkerIndex=$clusteredMarkersIndexes[i];
				if($clusteredMarkerIndex!==$index && $iconBounds[$mapZoomLevel][$clusteredMarkerIndex].intersects($iconBounds[$mapZoomLevel][$index])){	
					$intersectDetected=true;
					break;
				}
			}
			
		};
		this._map.setCenter($marker.getLatLng(), $mapZoomLevel);
		this.triggerClick($index);
	}else{
		// $marker is not within active area (map bounds + border padding)
		this._map.setCenter($marker.getLatLng());
		this.triggerClick($index);
	}
};

ClusterMarker.prototype._zoomEnd=function(){
	this._cancelMoveEnd=true;
	this.refresh(true);
};
json[0]={"companyName":"Bremavo Verzekeringen","addressCity":"Zwijndrecht","webURL":"www.bremavoverzekeringen.nl","lat":"51.8159225","lng":"4.6419057"};json[1]={"companyName":"4Klik Verzekeringen","addressCity":"Zwanenburg","webURL":"www.4klikverzekeringen.nl","lat":"52.38021","lng":"4.74993"};json[2]={"companyName":"Peter van Zutphen Verzekeringen","addressCity":"Zwaagwesteinde","webURL":"www.pvz.nl","lat":"53.2544938","lng":"6.0307255"};json[3]={"companyName":"Assurantiekantoor G.Strabbing","addressCity":"Zuidbroek","webURL":"www.strabbing.com","lat":"53.16548","lng":"6.86118"};json[4]={"companyName":"BB Assuranti&euml;n BV","addressCity":"Zoetermeer","webURL":"www.bbassurantien.nl","lat":"52.04072","lng":"4.46361"};json[5]={"companyName":"Hat&eacute;ka Assurantiekantoor en Makelaardij","addressCity":"Zaamslag","webURL":"www.hateka.nl","lat":"51.3127985","lng":"3.912718"};json[6]={"companyName":"Finas Adviesgroep","addressCity":"Wageningen","webURL":"www.finas.nl","lat":"51.9667624","lng":"5.6620732"};json[7]={"companyName":"RESIDENTIEPOLIS.NL","addressCity":"Voorburg","webURL":"www.residentiepolis.nl","lat":"52.0679455","lng":"4.3604238"};json[8]={"companyName":"Post Financi&euml;le Diensten","addressCity":"Vlijmen","webURL":"www.postfinancielediensten.nl","lat":"51.6968169","lng":"5.2139599"};json[9]={"companyName":"Assurantor BV","addressCity":"Vlaardingen","webURL":"www.assurantor.nl","lat":"51.9093714","lng":"4.3490193"};json[10]={"companyName":"Bourgondi&euml;n Kok Financi&euml;le Diensten","addressCity":"Ulft","webURL":"www.fdbk.nl","lat":"51.8998353","lng":"6.3763145"};json[11]={"companyName":"Finance Partner BV","addressCity":"Uden","webURL":"www.financepartner.nl","lat":"51.6552587","lng":"5.6188368"};json[12]={"companyName":"Finion Hypotheken &amp; Financi&euml;le Planning","addressCity":"Tilburg","webURL":"www.finion.nl","lat":"51.5561072","lng":"5.0993604"};json[13]={"companyName":"Lodewijks - Van Ginneken Assurantiegroep BV","addressCity":"Sprundel","webURL":"www.lvg.nl","lat":"51.5370472","lng":"4.5961254"};json[14]={"companyName":"Financeel Adviesbureau Van den Haspel","addressCity":"Rotterdam","webURL":"www.vandenhaspel.nl","lat":"51.890043","lng":"4.4904937"};json[15]={"companyName":"De Rotterdamse Adviesgroep","addressCity":"Rotterdam","webURL":"www.derotterdamseadviesgroep.nl","lat":"51.92407","lng":"4.49178"};json[16]={"companyName":"De Nederlandse Geldmeesters B.V.","addressCity":"ROSMALEN","webURL":"www.geldmeestersdirect.nl","lat":"51.7093924","lng":"5.3850323"};json[17]={"companyName":"WDO Verzekeringen","addressCity":"Roosendaal","webURL":"www.wdoverzekeringen.nl","lat":"51.5346007","lng":"4.4596534"};json[18]={"companyName":"Meer Direct","addressCity":"ROELOFARENDSVEEN","webURL":"www.meer-direct.nl","lat":"52.2013825","lng":"4.6315304"};json[19]={"companyName":"Assurantiekantoor Ben Weeterings","addressCity":"Ridderkerk","webURL":"www.benweeterings.nl","lat":"51.8664409","lng":"4.5891688"};json[20]={"companyName":"Perdijk Assuranti&euml;n","addressCity":"Reeuwijk","webURL":"www.perdijkassurantien.nl","lat":"52.039157","lng":"4.7175325"};json[21]={"companyName":"FPO Financi&euml;le Planning","addressCity":"Overberg","webURL":"www.fpo.nl","lat":"52.031725","lng":"5.5165037"};json[22]={"companyName":"Schep Assuranti&euml;n BV","addressCity":"Oud-Beijerland","webURL":"www.schep-assurantien.nl","lat":"51.8147523","lng":"4.4147487"};json[23]={"companyName":"Hallema Financial Consultancy","addressCity":"Nuth","webURL":"www.hallema-fc.nl","lat":"50.9148688","lng":"5.8877766"};json[24]={"companyName":"Ouddeken Assuranti&euml;n B.V.","addressCity":"Noordwijk","webURL":"www.nouddeken.nl","lat":"52.2374785","lng":"4.4477778"};json[25]={"companyName":"Goedkoopste-Verzekering.nl","addressCity":"NIJVERDAL","webURL":"www.goedkoopste-verzekering.nl","lat":"52.364796","lng":"6.467279"};json[26]={"companyName":"RibbensDirect.nl","addressCity":"Moordrecht","webURL":"www.ribbensdirect.nl","lat":"51.9861295","lng":"4.6714797"};json[27]={"companyName":"Jacobi Assuranti&euml;n","addressCity":"Montfoort","webURL":"www.jacobibv.nl","lat":"52.0453402","lng":"4.947624"};json[28]={"companyName":"De Vries Verzekeringen","addressCity":"Monster","webURL":"www.devriesverzekeringen.nl","lat":"52.02535","lng":"4.17769"};json[29]={"companyName":"Hessels &amp; Hessels Adviesgroep","addressCity":"Lelystad","webURL":"www.hessels.net","lat":"52.5059505","lng":"5.4745914"};json[30]={"companyName":"Hoogstins Hellema Assuranti&euml;n","addressCity":"Leeuwarden","webURL":"www.hoogstins-hellema.nl","lat":"53.2018921","lng":"5.7952784"};json[31]={"companyName":"Van den Beukel Assuranti&euml;n BV","addressCity":"Leerdam","webURL":"www.vdbeukel.nl","lat":"51.892799","lng":"5.09587"};json[32]={"companyName":"LimburgDirect.nl","addressCity":"Kerkrade","webURL":"www.limburgdirect.nl","lat":"50.86454","lng":"6.02260"};json[33]={"companyName":"Ferwerda Joure","addressCity":"Joure","webURL":"www.ferwerda-joure.nl","lat":"52.96037","lng":"5.81322"};json[34]={"companyName":"Aarendonk Assuranti&euml;n &amp; Hypotheken","addressCity":"IJsselstein","webURL":"www.aarendonkadvies.nl","lat":"52.018724","lng":"5.040445"};json[35]={"companyName":"Assurantiebedrijf Hoekstra BV","addressCity":"Harderwijk","webURL":"www.asshoekstra.nl","lat":"52.3450868","lng":"5.6241501"};json[36]={"companyName":"Verzekeringsgemak.nl","addressCity":"Groningen","webURL":"www.verzekeringsgemak.nl","lat":"53.1966486","lng":"6.580722"};json[37]={"companyName":"Van Dalfsen Assuranti&euml;n","addressCity":"GENEMUIDEN","webURL":"www.vandalfsenassurantien.nl","lat":"52.6221706","lng":"6.0410899"};json[38]={"companyName":"De Hypotheekspecialist Huisman","addressCity":"Epe","webURL":"www.hs-huisman.nl","lat":"52.35026","lng":"5.98114"};json[39]={"companyName":"VerzekeringsDiscounter","addressCity":"Eindhoven","webURL":"www.verzekeringsdiscounter.nl","lat":"51.4313959","lng":"5.485247"};json[40]={"companyName":"A1B Verzekeringen","addressCity":"Ede","webURL":"www.a1bverzekeringen.nl","lat":"52.02833","lng":"5.64719"};json[41]={"companyName":"Verzekeringskantoor Peer","addressCity":"DUIVEN","webURL":"www.peer-duiven.nl","lat":"51.94196","lng":"6.01649"};json[42]={"companyName":"FINEAS BV","addressCity":"Dongen","webURL":"www.fineas.nl","lat":"51.6276575","lng":"4.9405734"};json[43]={"companyName":"Van der Weij Assuranti&euml;n","addressCity":"Chaam","webURL":"www.verzekerjebijons.nl","lat":"51.5057234","lng":"4.8612707"};json[44]={"companyName":"Assurantiekantoor van Hunsel &amp; Govers BV","addressCity":"Budel","webURL":"www.vanhunselengovers.nl","lat":"51.2737318","lng":"5.5755227"};json[45]={"companyName":"Adviesgroep Koeman-De Baronie B.V.","addressCity":"BREDA","webURL":"www.debaronie.nl","lat":"51.5852","lng":"4.7672"};json[46]={"companyName":"Duijvelaar &amp; Groffen Verzekeringen","addressCity":"Bergen op Zoom","webURL":"www.duijvelaar-groffen.nl","lat":"51.4951471","lng":"4.2818404"};json[47]={"companyName":"Assurantiekantoor A.S.J. Diks","addressCity":"Beesd","webURL":"www.assurantiekantoordiks.nl","lat":"51.8857934","lng":"5.1960092"};json[48]={"companyName":"ASKAL-online","addressCity":"Beek","webURL":"www.askal-online.nl","lat":"50.9397808","lng":"5.7985718"};json[49]={"companyName":"Assurantiekantoor Havekes","addressCity":"Arnhem","webURL":"www.havekesverzekeringen.nl","lat":"51.9898376","lng":"5.9121919"};json[50]={"companyName":"KleinAdvies","addressCity":"Ankeveen","webURL":"www.kleinadvies.nl","lat":"52.26042","lng":"5.12083"};json[51]={"companyName":"Colijn Verzekeringen","addressCity":"Alphen aan den Rijn","webURL":"www.colijnverzekeringen.nl","lat":"52.1324664","lng":"4.6376642"};json[52]={"companyName":"Assurantiebedrijf van Peppen","addressCity":"'s-Gravenhage","webURL":"www.vanpeppen.nl","lat":"52.0719947","lng":"4.2581808"};json[53]={"companyName":"Van Eersel Assuranti&euml;n","addressCity":"&rsquo;s Gravenmoer","webURL":"www.vaneerselverzekeringen.nl","lat":"51.65689","lng":"4.93868"};// JavaScript Document
String.prototype.unescapeHtml = function () {
    var temp = document.createElement("div");
    temp.innerHTML = this;
    var result = temp.childNodes[0].nodeValue;
    temp.removeChild(temp.firstChild)
    return result;
} 
 
function load() {
	if (GBrowserIsCompatible()) {
		map=new GMap2(document.getElementById('map'));
 	    map.setCenter(new GLatLng(52.1326330, 5.2912660), 8);
	    var customUI = map.getDefaultUI();
		map.addMapType(G_MAPMAKER_NORMAL_MAP);
       	customUI.maptypes.hybrid = false;
       	customUI.maptypes.normal = false;
		customUI.maptypes.satellite = false;
	 	customUI.zoom.doubleclick = true;
	 	customUI.zoom.scrollwheel = false;
       	map.setUI(customUI);
		
		function myClusterClick(args) {
			cluster.defaultClickAction=function(){
				map.setCenter(args.clusterMarker.getLatLng(), map.getBoundsZoomLevel(args.clusterMarker.clusterGroupBounds))
				delete cluster.defaultClickAction;
			}
			var html='<div class="infoWindow"><div class="infoBalloon"><strong>'+args.clusteredMarkers.length+' adviseurs:</strong><br/>';
			for (i=0; i<args.clusteredMarkers.length; i++) {
				var rowcolor = (i%2) ? 'even' : 'odd';
				var titletext = args.clusteredMarkers[i].getTitle().split(' | ');
				html+='<div class="'+rowcolor+'">'+getTitleHtml(titletext[0],titletext[1],titletext[2])+'</div>';
			}
			html+='<span style="font-size:10px; padding-top:10px;">Klik op de kantoornaam om je premie te berekenen.</span></div></div>';
			map.openInfoWindowHtml(args.clusterMarker.getLatLng(), html);
		}
		
		//	create a ClusterMarker
		cluster=new ClusterMarker(map, {clusterMarkerTitle:'%count adviseurs' , clusterMarkerClick:myClusterClick });
		icon=new GIcon();
		icon.iconSize=new GSize(20, 20);
		icon.iconAnchor=new GPoint(10, 10);
		icon.infoWindowAnchor=new GPoint(15, 5);
		newMarkerCluster();
	}
}
 
function newMarker(markerLocation, markerIcon, companyName, addressCity, webURL) {
	var marker=new GMarker(markerLocation, {title: companyName.unescapeHtml()+' | '+addressCity+' | '+webURL, icon:markerIcon});
	eventListeners.push(GEvent.addListener(marker, 'click', function() {
	marker.openInfoWindowHtml('<div class="infoBalloon"><div class="odd">'+getTitleHtml(companyName, addressCity, webURL)+'</div></div><span style="font-size:10px; padding-top:10px;">Klik op de kantoornaam om je premie te berekenen.</span>');
	}));
	return marker;
}
 
function getTitleHtml (companyName, addressCity, webURL) {
	var title='<a href="http://'+webURL+''+linkURL+'" rel="nofollow" target="_blank" onclick="javascript: pageTracker._trackPageview(\'/uitgaande_klik/'+companyName+'\');"><b>'+companyName+'</b><br /><span style="font-size:11px;">'+addressCity+'</span></a>';
	return title;
}
 
function newMarkerCluster(){
		var marker, newIcon, j=1, title, lat, lng;
		for (var i=0; i<json.length; i++) {
			newIcon=new GIcon(icon, '../img/icons/orange_button.png');
			icon.iconSize=new GSize(20, 20);
			lat=Math.round(json[i].lat*100)/100;
			lng=Math.round(json[i].lng*100)/100;
			marker=newMarker(new GLatLng(json[i].lat, json[i].lng), newIcon,json[i].companyName,json[i].addressCity,json[i].webURL);
			markersArray.push(marker);
		}
		cluster.removeMarkers();
		cluster.addMarkers(markersArray);
		cluster.fitMapToMarkers();
		map.savePosition();
		json=[];
}
