﻿window.onload= start;
window.onunload = bewaar;
var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("Windows") > -1)+1-1;
	 var map
	 var geocoder
	 var mgr
     var tooltip
	 var cluster
	 var vorige, vorige2
	 var gedaan = false
	 var eerstekeer = true
	 var venster
	 
	
	 function start() {
	 if (GBrowserIsCompatible()) {
	  	venster = location.hash.replace('#','');
		venster = venster.replace('v','');
		
		//lagen
		var tilelayers = [new GTileLayer(null , 4, 17)];
		tilelayers[0].getTileUrl = kaart_tiles;
		var KAART = new GMapType(tilelayers, new GMercatorProjection(32), "Kaart", {shortname:"Kaart", errorMessage:"Geen detailkaart: zoom uit of kies luchtfoto"} ); 
		
		var tilelayers2 = [new GTileLayer(null , 4, 17),new GTileLayer(null , 4, 17, {isPng:true})];
		tilelayers2[0].getTileUrl = function (tile,zoom) {return G_HYBRID_MAP.getTileLayers()[0].getTileUrl(tile,zoom)};
		tilelayers2[1].getTileUrl = function (tile,zoom) {return G_HYBRID_MAP.getTileLayers()[1].getTileUrl(tile,zoom)};
		var BEIDE  = new GMapType(tilelayers2, new GMercatorProjection(32), "Satelliet",  {shortname:"Satelliet", errorMessage:"Geen detailfoto: zoom uit"} );
		
		var tilelayers3 = [new GTileLayer(null , 4, 17),new GTileLayer(null , 4, 17, {isPng:true})];
		tilelayers3[0].getTileUrl = function (tile,zoom) {return G_HYBRID_MAP.getTileLayers()[0].getTileUrl(tile,zoom)};
		tilelayers3[1].getTileUrl = GetTileUrl;
		var LEEUW  = new GMapType(tilelayers3, new GMercatorProjection(32), "Leeuw",  {shortname:"Leeuw", errorMessage:"Geen detailfoto: zoom uit"} );
		
		tooltip = document.createElement("div");
		tooltip.className='tooltip';
		document.getElementById("debody").appendChild(tooltip);
		tooltip.style.visibility="hidden";
		
		map = new GMap2(document.getElementById("map"),{mapTypes : [KAART,BEIDE,LEEUW]});
    	map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(110,20)));		       
        map.addControl(new GLargeMapControl(),  new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(25,20)));
		map.addControl(new GScaleControl(),  new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(100,0)));
   
   	  	var zl  = parseInt(getCookie('map_zoom',7));
		var lat = parseFloat(getCookie('map_lat',52.089368));
		var lng = parseFloat(getCookie('map_lng',5.120668));
   		var mt = KAART;
		mt_str = getCookie('map_type','beide');
		if (mt_str == 'Satelliet') {mt = BEIDE;} if (mt_str == 'Leeuw') {mt = LEEUW;}
   
        map.setCenter(new GLatLng(lat,lng), zl, mt);
		map.enableScrollWheelZoom();
		geocoder = new GClientGeocoder();
		
		//markers
		cluster=new ClusterMarker(map);
		
		setTimeout("plaatsMarkers('" + venster + "')",100); 
		
	 }
	 }
	 function vulKolom(){
		var vensternr=0;
		var rs = "";
		for (i=0; i < data.vensters.length; i++){
			id =  data.vensters[i].id;
			var vid=0; if (i < (data.vensters.length-1)) vid = data.vensters[i+1].id;
			if (id==venster) {vensternr=i}
			
			if (isIE) {ie6sp = '<span style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'iconen/' + id + '.png\');"></span>'} else {ie6sp =''};
			
			rs += '<a href="#" onclick="slt(this);return false" title="toon alle vensters" class="slt" id="slt' + id + '"></a><a name="v' + vid + '" href="javascript:plaatsMarkers(\'' + id + '\');" onmouseover="tooltip2(this)" onmouseout="tooltip2uit()" id="ic' + id + '" rel="' + data.vensters[i].n + '"><img src="iconen/' + id + '.png" border="0"/>' + ie6sp + '</a>';
			

		}
		
		//diversen
		eId('vensterslijst').innerHTML = rs;
		vorige  = document.getElementById("ic1");
		vorige2 = document.getElementById("slt1");
		if (vensternr > 1 && !isIE) {eId('vensterslijst').scrollTop= (55 * (vensternr-1));}
		eId('zoek').style.display='block';
	 
	}
	
	function plaatsMarkers(venster){
		cluster.removeMarkers();
		var markersArray=[];
		
		if (venster != "") {vorige2.style.display='none'; vorige2 = eId('slt' + venster); mark(eId('ic' + venster)); eId('slt' + venster).style.display='block'}
		
		for (i=0; i < data.locaties.length; i++){
			var toonvenster = false;
			var vensters = data.locaties[i].v.split(',');
			if (venster == ""){ toonvenster = true; hetvenster = vensters[0];}
			else { for (j=0; j < vensters.length; j++) {
				if (vensters[j] == venster) {
					toonvenster = true;
					hetvenster = venster;
					
					}
				}}
			if (toonvenster){
				pnt = eval('new GLatLng(' + data.locaties[i].ll + ')');
				var marker = createMarker(pnt, data.locaties[i].n + ', ' + data.locaties[i].p, i, hetvenster)
				markersArray.push(marker);
			}
		}
		cluster.addMarkers(markersArray);
		cluster.fitMapMaxZoom=16;
		cluster.intersectPadding=5;
		if (venster != "" || !eerstekeer) {cluster.fitMapToMarkers();}
		eerstekeer = false;
		cluster.refresh();
	
	}
	
	
	function clusterIcoon(nr){
		icon = new GIcon();
		icon.image = "iconen/" + nr + '.png';
		icon.shadow = "map.png";
		icon.iconAnchor = new GPoint(25, 25);
		icon.iconSize = new GSize(50, 50);	
		icon.shadowSize = new GSize(55, 55);
		return icon;
	}

	function createMarker(ll, title, nr, c) {

		icon = new GIcon();
		icon.image = "iconen/" + c + '.png';
		icon.iconAnchor = new GPoint(25, 25);
		icon.infoWindowAnchor = new GPoint(25, 25);
		icon.iconSize = new GSize(50, 50);
		
		var marker = new GMarker(ll,{icon: icon});
		marker.hetid = c; marker.hetnr = nr;
		GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(maakIframe(nr), {buttons:{close:{show:8}} });});
		GEvent.addListener(marker,"mouseover", function() {showTooltip(marker, title);});        
        GEvent.addListener(marker,"mouseout", function() {tooltip.style.visibility="hidden" });
		return marker;
  }	

function vinfo(id){
	
	for (i=0; i < data.vensters.length; i++){
		if (data.vensters[i].id == id) {return data.vensters[i];}
	}
}

	
function maakIframe(nr){
	html = '<div class="ballon"><p align="right"><a href="javascript:map.closeInfoWindow()"><img src="sluit.gif"/></a></p><p style="margin-top:-25px;padding-right:25px">';
	if (data.locaties[nr].s != '') {
		html += '<a title="ga naar website" target="_blank" href="http://' + data.locaties[nr].s + '">' + data.locaties[nr].n + '</a>';
	} else {
		html += '<b>' + data.locaties[nr].n + '</b>';}
	html += '<br/>' + data.locaties[nr].p + '</p>';
	
	if (data.locaties[nr].t != '') html += '<p style="max-width:400px">' + unescape(data.locaties[nr].t).replace(/\+/g, ' ') + '</p>';
	
	vs = data.locaties[nr].v.split(',');
	for (j=0; j < vs.length; j++){
		if (isIE) {ie6sp = '<span style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'iconen/' +  vs[j] + '.png\');"></span>'} else {ie6sp =''};
		html += '<div title="gerelateerd venster" class="balic"><img src="iconen/' + vs[j] + '.png" align="left" />' + ie6sp + '<a href="/' + vinfo(vs[j]).u + '">' + vinfo(vs[j]).n + "</a></div>";
	}
	html += "</div>"
	return html;
}		
	
	

	function zoekop(){	
		geocoder.getLatLng(document.getElementById('adres').value + ' NL', kaart2);
	}
		
	function kaart2(p2){
		if(p2 == null) {alert('Niet gevonden...')} else {
	    map.setCenter(p2, 14);
	}
    }
	
	function vullen(){
	
	document.getElementById("res").value = document.getElementById("adres").value + '|' +  map.getCenter().toString().replace(' ','') + '|' + map.getZoom();
	}

	function punt(){
		var Nmarker = new GMarker(map.getCenter(), { bouncy: true, draggable: true, title : "Punt opvragen" });
		GEvent.addListener(Nmarker, "click", function(){prompt("Coördinaten:", Nmarker.getPoint().lat() + ',' + Nmarker.getPoint().lng());});
		map.addOverlay(Nmarker);
	}


function showTooltip(marker,str) {
    tooltip.innerHTML = str;
	ll = marker.getPoint();
	tooltip.style.left = map.fromLatLngToContainerPixel(ll).x + eId('map').offsetLeft + 10 + 'px' ;
	tooltip.style.top  = map.fromLatLngToContainerPixel(ll).y + eId('map').offsetTop  + 20 + 'px' ;
	tooltip.style.visibility="visible";
}

function tooltip2(obj){
	tooltip.innerHTML = obj.getAttribute("rel");
	tooltip.style.left = ''
	tooltip.style.right = '75px';
	tooltip.style.top = (obj.offsetTop - eId('vensterslijst').scrollTop + 10) + 'px';
	tooltip.style.visibility="visible";
}

function tooltip2uit(){
	tooltip.style.visibility="hidden";
}


function eId(w){return document.getElementById(w);}
	
function kaart_tiles(tile,zoom) {
	if (zoom >17) {
		return G_HYBRID_MAP.getTileLayers()[1].getTileUrl(tile,zoom)
	}
	else if (zoom >15) {
		return G_NORMAL_MAP.getTileLayers()[0].getTileUrl(tile,zoom)
	}
	else {
		return G_PHYSICAL_MAP.getTileLayers()[0].getTileUrl(tile,zoom)
	} 
}

	
function GetTileUrl(a,b) {
	if (b > 10) {return 'niet.png';} else {return "leeuw/" + TileToQuadKey(a.x, a.y, b) + '.png';}
	}		

function TileToQuadKey  ( tx,  ty,  zl) { 
   var quad; 
   quad = ""; 
   for (var i = zl; i > 0; i--){ 
	   var mask = 1 << (i - 1); 
	   var cell = 0; 
	   if ((tx & mask) != 0) 
		   cell++; 
	   if ((ty & mask) != 0) 
		   cell += 2; 
	   quad += cell; 
   } 
   return quad; 
}
	
function mark(obj){
vorige.style.background='none';
obj.style.backgroundColor='#FF8E42';
vorige = obj;
}

function fcs(obj){
obj.style.color='black';
if (!gedaan) { obj.value=''; gedaan = true;}
}

function slt(obj){
	vorige.style.background='none';
	obj.style.display='none';
	vorige2 = obj;
	map.setCenter(new GLatLng(52.089368,5.120668), 7);
	eerstekeer = true;
	setTimeout("plaatsMarkers('')",1); 
	
}


function bewaar(){
	document.cookie = "map_zoom=" + map.getZoom() + "; path=/";
	document.cookie = "map_lat="  + map.getCenter().lat() + "; path=/";
	document.cookie = "map_lng="  + map.getCenter().lng() + "; path=/";
	document.cookie = "map_type=" + map.getCurrentMapType().getName(1) + "; path=/";
}
function getCookie(name, defval) {
	var nameEQ = name + "="; var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
			ck = '' + c.substring(nameEQ.length,c.length); if (ck != '') return ck;}
	}
	return defval;
}


/*
	http://googlemapsapi.martinpearman.co.uk/clustermarker	
*/

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='http://maps.google.com/mapfiles/arrow.png';
		this.clusterMarkerIcon.iconSize=new GSize(39, 34);
		this.clusterMarkerIcon.iconAnchor=new GPoint(9, 31);
		this.clusterMarkerIcon.infoWindowAnchor=new GPoint(9, 31);
		this.clusterMarkerIcon.shadow='http://www.google.com/intl/en_us/mapfiles/arrowshadow.png';
		this.clusterMarkerIcon.shadowSize=new GSize(39, 34);
	}
	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]){
		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){
		//var mrkr = new GMarker($location, {icon:$icon, title:$title});
		//arjan: tooltip
		var mrkr = new GMarker($location, {icon:$icon});
		GEvent.addListener(mrkr,"mouseover", function() {
          showTooltip(mrkr, $title);
        });        
        GEvent.addListener(mrkr,"mouseout", function() {tooltip.style.visibility="hidden"});        
		// einde
		return mrkr;
	}
	var $clusterGroupBounds=new GLatLngBounds(), i, $clusterMarker, $clusteredMarkers=[], $marker, $this=this;
	var tit;
	var depl = '';
	var hetid;
	for(i=$clusterGroupIndexes.length-1; i>=0; i--){
		$marker=this._mapMarkers[$clusterGroupIndexes[i]];
		$marker.index=$clusterGroupIndexes[i];
		$clusterGroupBounds.extend($marker.getLatLng());
		$clusteredMarkers.push($marker);
		//arjan
		hetid = $marker.hetid;
		pl = (data.locaties[$marker.hetnr].p + ', ' + data.locaties[$marker.hetnr].pr).split(',');
		dezepl = pl[pl.length-2] + ',' + pl[pl.length-1];
		if (depl == '') {depl = dezepl};
		if (depl != dezepl) {
				var tmp = pl[pl.length-1];
				if (depl.indexOf(',') > 0) { depl = tmp; }
				else {
						if (depl.indexOf(tmp) < 0) {depl += ' en ' + tmp;}
					}
		}
		//einde arjan
	}
	//this.clusterMarkerIcon
	$clusterMarker=$newClusterMarker($clusterGroupBounds.getCenter(), clusterIcoon(hetid) , "<b>Zoom in:</b><br/>" + depl + "<br/><em>" + $clusterGroupIndexes.length + " locaties</em>");
	$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 });
	}));
	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;
	//if ($mapZoomLevel > 10) {$borderPadding = 15}
	
	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(this._iconBounds[$mapZoomLevel])==='undefined'){
		this._iconBounds[$mapZoomLevel]=[];
		this._activeMarkersChanged=true;	
		for(i=this._mapMarkers.length-1; i>=0; i--){
			$marker=this._mapMarkers[i];
			$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;
			$marker._makeVisible=$marker._isActive;
			if($marker._isActive){
				$uncachedIconBoundsIndexes.push(i);
			}
		}
	}else{
		for(i=this._mapMarkers.length-1; i>=0; i--){
			$marker=this._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(this._iconBounds[$mapZoomLevel][i])==='undefined'){
				$uncachedIconBoundsIndexes.push(i);
			}
		}
	}
	return $uncachedIconBoundsIndexes;
};

ClusterMarker.prototype._filterIntersectingMapMarkers=function(){
	var $clusterGroup, i, j, $mapZoomLevel=this._map.getZoom();
	for(i=this._mapMarkers.length-1; i>0; i--)
	{
		if(this._mapMarkers[i]._makeVisible){
			$clusterGroup=[];
			for(j=i-1; j>=0; j--){
				if(this._mapMarkers[j]._makeVisible && this._iconBounds[$mapZoomLevel][i].intersects(this._iconBounds[$mapZoomLevel][j])){
					$clusterGroup.push(j);
				}
			}
			if($clusterGroup.length!==0){
				$clusterGroup.push(i);
				for(j=$clusterGroup.length-1; j>=0; j--){
					this._mapMarkers[$clusterGroup[j]]._makeVisible=false;
				}
				this._clusterMarkers.push(this._clusterMarker($clusterGroup));
			}
		}
	}
};

ClusterMarker.prototype.fitMapToMarkers=function(){
	var $markers=this._mapMarkers, $markersBounds=new GLatLngBounds(), i;
	for(i=$markers.length-1; i>=0; i--){
		$markersBounds.extend($markers[i].getLatLng());
	}
	var $fitMapToMarkersZoom=this._map.getBoundsZoomLevel($markersBounds);
		
	if(this.fitMapMaxZoom && $fitMapToMarkersZoom>this.fitMapMaxZoom){
		$fitMapToMarkersZoom=this.fitMapMaxZoom;
	}
	
	//arjan
	if ($fitMapToMarkersZoom > 8) $fitMapToMarkersZoom -= 1;
	
	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){
	var $mapProjection=this._map.getCurrentMapType().getProjection(), $mapZoomLevel=this._map.getZoom(), i, $marker, $iconSize, $iconAnchorPoint, $iconAnchorPointOffset, $iconBoundsPointSw, $iconBoundsPointNe, $iconBoundsLatLngSw, $iconBoundsLatLngNe, $intersectPadding=this.intersectPadding;
	for(i=$indexes.length-1; i>=0; i--){
		$marker=this._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, $uncachedIconBoundsIndexes=this._filterActiveMapMarkers();
	if(this._activeMarkersChanged || $forceFullRefresh){
		this._removeClusterMarkers();
		if(this.clusteringEnabled && this._map.getZoom()<this._map.getCurrentMapType().getMaximumResolution()){
			if($uncachedIconBoundsIndexes.length>0){
				this._preCacheIconBounds($uncachedIconBoundsIndexes);
			}
			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(){
	for(var i=this._clusterMarkers.length-1; i>=0; i--){
		this._map.removeOverlay(this._clusterMarkers[i]);
	}
	for(i=this._eventListeners.length-1; i>=0; i--){
		GEvent.removeListener(this._eventListeners[i]);
	}
	this._clusterMarkers=[];
	this._eventListeners=[];
};

ClusterMarker.prototype.removeMarkers=function(){
	for(var i=this._mapMarkers.length-1; i>=0; i--){
		if(this._mapMarkers[i]. _isVisible){
			this._map.removeOverlay(this._mapMarkers[i]);
		}
		delete this._mapMarkers[i]._isVisible;
		delete this._mapMarkers[i]._isActive;
		delete this._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
		this._map.setCenter($marker.getLatLng());
		this._map.zoomIn();
		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(){
		//arjan
	tooltip.style.visibility="hidden";
	this._cancelMoveEnd=true;
	this.refresh(true);
};

