﻿var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("Windows") > -1)+1-1; 
var map
var opa = 1
var geocoder
var oldcenter
var sp = 'fast'
var clickpoint
var isBallon = false	
var icon1, icon2, icon3
var m1,m2,m3
var markers = []
var withoos = false
var puntenweg = false
var srvr = "http://www.amersfoortopdekaart.nl/"

try { if (isIE) document.execCommand('BackgroundImageCache', false, true); } catch(e) {}

window.onload = start;

function start(){
		   
		$("#menu a").click(function(){
				var h = this.href;
				if (h.indexOf('#') < 0 && h.indexOf('.pdf') < 0 && h.indexOf('&') < 0 ) {doe(this.href); return false;}
		});
		
		$("#locaties h3").click(function(){
				$("#locaties span").not($(this).next()).removeClass( 'toon' );
				$(this).next().toggleClass( 'toon' );
				window.setTimeout(zetbounds, 1);
		});	
		$("#wandelingen h3").click(function(){
				$("#wandelingen span").not($(this).next()).removeClass( 'toon' );
				$(this).children('i').toggleClass( 'toon' );
				$(this).next().toggleClass( 'toon' );
				var tmp = this.id;
				window.setTimeout(function() {zetroutepunten(tmp)}, 1);
		});				
		
		$("#doorzichtig").checked = false;
		 
		 withoos = eId('withoos');
		 

		 
	 if (GBrowserIsCompatible()) {
	  	
		if (!withoos) {
			
			//lagen
			var tilelayers = [new GTileLayer(null , 12, 19)];
			tilelayers[0].getTileUrl = kaart_tiles;
			KAART = new GMapType(tilelayers, new GMercatorProjection(32), "Kaart", {shortname:"Kaart", errorMessage:"Geen detailkaart: zoom uit of kies luchtfoto"} ); 
			
			var tilelayers1 = [new GTileLayer(null , 12, 19)];
			tilelayers1[0].getTileUrl = function (tile,zoom) {return G_HYBRID_MAP.getTileLayers()[0].getTileUrl(tile,zoom)};
			LUCHTFOTO = new GMapType(tilelayers1, new GMercatorProjection(32), "Luchtfoto", {shortname:"Luchtfoto", errorMessage:"Geen detailfoto"} ); 		
			
			var tilelayers2 = [new GTileLayer(null , 12, 19),new GTileLayer(null , 12, 19, {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)};
			BEIDE  = new GMapType(tilelayers2, new GMercatorProjection(32), "Satelliet",  {shortname:"Satelliet", errorMessage:"Geen detailfoto: zoom uit"} );
			
			//tilelayers
			var tilelayer1650 = new GTileLayer();
			tilelayer1650.getTileUrl = GetTileUrlBlaeu;
			tilelayer1650.isPng = function() { return true;};
			tilelayer1650.getOpacity = function() {return opa};
			OV1650 = new GTileLayerOverlay(tilelayer1650);		
			
			var tilelayer1565 = new GTileLayer();
			tilelayer1565.getTileUrl = GetTileUrl_deventer;
			tilelayer1565.isPng = function() { return true;};
			tilelayer1565.getOpacity = function() {return opa};
			OV1565 = new GTileLayerOverlay(tilelayer1565);
	
			var tilelayer1888 = new GTileLayer();
			tilelayer1888.getTileUrl = GetTileUrl1888;
			tilelayer1888.isPng = function() { return true;};
			tilelayer1888.getOpacity = function() {return opa};
			OV1888 = new GTileLayerOverlay(tilelayer1888);
	
			var tilelayer1946 = new GTileLayer();
			tilelayer1946.getTileUrl = GetTileUrl1946;
			tilelayer1946.isPng = function() { return true;};
			tilelayer1946.getOpacity = function() {return opa};
			OV1946 = new GTileLayerOverlay(tilelayer1946);
	
			var tilelayer1979 = new GTileLayer();
			tilelayer1979.getTileUrl = GetTileUrl1979;
			tilelayer1979.isPng = function() { return true;};
			tilelayer1979.getOpacity = function() {return opa};
			OV1979 = new GTileLayerOverlay(tilelayer1979);
	
			
			map = new GMap2(document.getElementById("map"),{mapTypes : [KAART,LUCHTFOTO,BEIDE], backgroundColor: 'transparent'});
			map.addControl(new GLargeMapControl());
			map.addControl(new GScaleControl(),  new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(100,0)));
			map.addControl(new GOverviewMapControl());
	   
			var zl  = 14;
			var lat = 52.155156031161006;
			var lng = 5.387152433395386;
			var mt  = BEIDE;
			mt_str = 'beide';
			if (mt_str == 'Satelliet') {mt = BEIDE;} if (mt_str == 'Blaeu') {mt = BLAEU;}
	   
			map.setCenter(new GLatLng(lat,lng), zl, mt);
		
		}
		else
		{
		  map = new GMap2(document.getElementById("map"), {backgroundColor: '#000000'});
		  map.addControl(new GLargeMapControl());
		  var withoos_copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180),new GLatLng(90,180)), 1, "(c) 2008 ab-c.nl");
		  var withoos_copyrightCollection = new GCopyrightCollection('Map Data:');
		  withoos_copyrightCollection.addCopyright(withoos_copyright);
		  withoos_CustomGetTileUrl=function(a,b){
			 var f = "/tiles/withoos/"+b+"_"+a.x+"_"+a.y+".jpg";
			 return f;
		  }
		  var withoos_tilelayers = [new GTileLayer(withoos_copyrightCollection,8,12)];
		  withoos_tilelayers[0].getTileUrl = withoos_CustomGetTileUrl;
		  var withoos_custommap = new GMapType(withoos_tilelayers, new GMercatorProjection(13), "Old OS");
		  map.addMapType(withoos_custommap);
		  map.setCenter(new GLatLng(84.9901001802348, -177.71484375, true), 10, withoos_custommap);

		}
		oldcenter = map.getCenter();
		map.enableScrollWheelZoom();


		GEvent.addListener(map,"zoomend",function(a,b) { hidecontextmenu(); if (oldcenter != map.getCenter()) {sluitballon(); grootweg();}});
		
		contextmenu = document.createElement("div");
		contextmenu.style.visibility="hidden";
		contextmenu.id = "contextmenu";
		if (!withoos) contextmenu.innerHTML =  '<a href="javascript:infoHere()" style="border:0">Toon afbeeldingen</a>';
		contextmenu.innerHTML +=  '<a href="javascript:zoomInHere()">Inzoomen</a>'
							  + '<a href="javascript:zoomOutHere()">Uitzoomen</a>';
		if (!withoos) contextmenu.innerHTML +=  '<a href="javascript:voegtoeHere()">Locatie toevoegen</a>';
		map.getContainer().appendChild(contextmenu);	
		

		GEvent.addListener(map,"singlerightclick",function(pixel,tile) {
			if (!isBallon){
				clickpoint = map.fromContainerPixelToLatLng(pixel)
				var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(pixel.x,pixel.y));  
				pos.apply(contextmenu);
				contextmenu.style.visibility = "visible";
			} else {sluitballon();
			}
		});

		GEvent.addListener(map, "click", function(m,p) {
			if (!isBallon){									  
				clickpoint = p;
				var ll = map.fromLatLngToContainerPixel(p);
				var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(ll.x,ll.y));  
				pos.apply(contextmenu);
				contextmenu.style.visibility = "visible";
			}
		
		});		
		GEvent.addListener(map, "dblclick", function() {hidecontextmenu()});
		GEvent.addListener(map, "movestart", function() {hidecontextmenu()});
		
		geocoder = new GClientGeocoder();
		geocoder.setBaseCountryCode("nl");
		
		var iA =  new GPoint(10, 18); var iS = new GSize(22, 22);
		
		icon1 = new GIcon();
		icon1.image = "grafiek/i1.png";
		icon1.iconAnchor = iA; icon1.iconSize = iS
		
		icon2 = new GIcon();
		icon2.image = "grafiek/i2.png";
		icon2.iconAnchor = iA; icon2.iconSize = iS
		
		icon3 = new GIcon();
		icon3.image = "grafiek/i3.png";
		icon3.iconAnchor = iA; icon3.iconSize = iS
		
		icon4 = new GIcon();
		icon4.image = "grafiek/i4.png";
		icon4.iconAnchor = iA; icon4.iconSize = iS		
				
			 
	 window.setTimeout(rsz, 1);
	 window.setTimeout(zetpunten, 1);
	 window.onresize = rsz;
	 }
}

function zetpunten(){
		// markers zetten vanuit html
		markers = [];
		puntenweg = false;
		$("#locaties a").not(".balkje").each(function (i) {
			eval('ll = new GLatLng(' + this.getAttribute('rel') + ')');
			href = this.href.replace(location.href, '');	 
			markers.push(createMarker(ll, this.innerHTML, href, false));
		});
		
		if (!withoos) {
			for (i=0; i < ingezonden.punten.length; i++){
				eval('ll = new GLatLng(' + ingezonden.punten[i].ll + ')');	 
				markers.push(createMarker(ll, ingezonden.punten[i].t, 'ingezonden/' + title2url(ingezonden.punten[i].t), false));
			}
		}
			
		for (var i=0; i<markers.length; i++){map.addOverlay(markers[i])}	
		
	 if (location.hash != '') doe( srvr + location.hash.replace('#',''));		
		
}


function zetroutepunten(id){

		map.clearOverlays();
		puntenweg = true;
		markers = []
		var routebounds = new GLatLngBounds();
		$("#s" + id + " a").each(function (i) {
			eval('ll = new GLatLng(' + this.getAttribute('rel') + ')');
			href = this.href.replace(location.href, '');	 
			markers.push(createMarker(ll, this.innerHTML, href, false));
			routebounds.extend(ll);
		});
		for (var i=0; i<markers.length; i++){map.addOverlay(markers[i])}

		if (!routebounds.isEmpty()) {
				zl = map.getBoundsZoomLevel(routebounds);
				if (zl > 17) zl = 17;
				map.setCenter(routebounds.getCenter(), zl);
		}


}



function rsz(){
	if (!isIE){
		eId('map').style.height=window.innerHeight + 'px';
	}
	map.checkResize();
	
}

function hidecontextmenu(){
	eId('contextmenu').style.visibility = "hidden";
}

function zoomInHere() {
	
	map.zoomIn(clickpoint,true); hidecontextmenu();
}      
function zoomOutHere() {

	map.setCenter(clickpoint,map.getZoom()-1); hidecontextmenu();
}      
function infoHere() {
	info(clickpoint); hidecontextmenu();
}      

function voegtoeHere() {
	hidecontextmenu();	voegtoeinfo(clickpoint);
}      

function startvoegtoe(){
		var v = eId('toevoegterm').value + ' Amersfoort';
		geocoder.setBaseCountryCode('nl');
		geocoder.getLatLng(v, function(p2){
				if (p2 == null) {alert('Niets gevonden...')} else { voegtoeinfo(p2); }
		});
}

function voegtoeinfo(point){
	geocoder.getLocations(point, function(addresses) {
			var title=' ';
       		if(addresses.Status.code == 200) {
           		address = addresses.Placemark[0].address.split(','); title = address[0].replace(/ \d+.*/g,'');
         	}	
			var mrkr = toevoegMarker(point, title); 
			map.addOverlay(mrkr); toevoegballon(mrkr, title);
			
		});	
		
}

function info(point){

		
		geocoder.getLocations(point, function(addresses) {
			var title=''; var url='';
       		if(addresses.Status.code == 200) {
           		address = addresses.Placemark[0].address.split(',');
				title = address[0].replace(/ \d+.*/g,'');
				url = "/collecties/?q=" + escape(address[0]);
				
         	}
			
			//overrulen met parken etc.
			for (i=0; i < data.parken.length; i++){
				dp = eval('new GLatLng(' + data.parken[i].ll + ')');
				if (dp.distanceFrom(point) < 200){
					title =  data.parken[i].t;
					url = "/collecties/?v=" + data.parken[i].v + "&q=" + escape(data.parken[i].t);
				}
			}
			
			if (title != ''){
				mrkr = createMarker(point,  title, url, true);
				map.addOverlay(mrkr); ballon(mrkr, title);
			} else {
				createMarker(point, 'Niets gevonden...', true)
			}
			
		});
}



function createMarker(posn, title, url, dragg) {
    var marker 
	if (dragg){
		marker= new GMarker(posn, { bouncy: true, draggable: true, title : title, icon: icon3});
		GEvent.addListener(marker, "dragend", function(p){info(p); map.removeOverlay(this)});
	
	} else {
		var ic = icon1;
		if (url.indexOf('wandeling') > -1) ic = icon4;
		if (url.indexOf('ingezonden') > -1) ic = icon2;
		marker = new GMarker(posn, {title: title, icon: ic});
		
	}
	marker.url = url;
	GEvent.addListener(marker, "click", function() {ballon(this, title)});
    return marker;
}

function sluitballon() {
  if (window.currentMarker) {
  	map.removeOverlay(currentMarker.overlay);
	isBallon = false;
  }
}

function ballon(mrkr, title){
			sluitballon(); hidecontextmenu(); grootweg();
		  	html = "<div class='balkje2'><a class='aknop' onclick='sluitballon()'>&nbsp;</a><span id='detitel'>" + title + "</span></div>"
			html += '<div id="ballontekst"><img id="loading" src="/grafiek/loader.gif" alt="loading"/></div>'
			
			if (window.currentMarker) {sluitballon();}
			if (!mrkr.overlay) { mrkr.overlay = new MyOverlay(mrkr, html);}
			
			currentMarker = mrkr;
			map.panTo(new GLatLng(mrkr.getPoint().lat(), mrkr.getPoint().lng()));
			
			map.addOverlay(mrkr.overlay);
			$("#ballontekst").load(mrkr.url + '/kort');
			oldcenter = map.getCenter();
	
}

function voegtoe(){ groot( "Locatie toevoegen", '/post/toevoegen.aspx?ll=' +  eId('ll').value + '&a=' + escape(eId('detitel').innerHTML)) }


function toevoegMarker(posn, title) {
    var marker= new GMarker(posn, { bouncy: true, draggable: true, title : title, icon: icon2});
	GEvent.addListener(marker, "dragend", function(p){voegtoeinfo(p);map.removeOverlay(this);});
	GEvent.addListener(marker, "click", function() {toevoegballon(this, title)});
    return marker;
}

function toevoegballon(mrkr, title){
			sluitballon(); hidecontextmenu(); grootweg();
		  	html = "<div class='balkje2'><a class='aknop' onclick='sluitballon()'>&nbsp;</a><span id='detitel'>" + title + "</span></div>"
		  	html += '<div id="ballontekst" style="text-align:center"><input type="hidden" name="ll" id="ll" value="' + mrkr.getPoint().lat() + ',' + mrkr.getPoint().lng() + '"/>';
			html += '<p>Versleep indien nodig het i-tje hieronder<br/>naar de exacte locatie.</p><a href="javascript:voegtoe()">voeg info toe over deze locatie</a></center></div>'
			if (!mrkr.overlay) { mrkr.overlay = new MyOverlay(mrkr, html);}
			
			currentMarker = mrkr;
			map.panTo(new GLatLng(mrkr.getPoint().lat(), mrkr.getPoint().lng()));
			map.addOverlay(mrkr.overlay);
}


function transp(op){
	if (window.cOV) {
		opa = op/10;
		map.removeOverlay(cOV);
		cOV.getTileLayer().getOpacity = function() {return opa};
		map.addOverlay(cOV);
	}
}


var MyOverlay = function(marker, html) {
	  this.marker = marker;
	  this.html = html;
	}
	MyOverlay.prototype = new GOverlay();
	MyOverlay.prototype.initialize = function(map) {isBallon = true;
	  var div = document.createElement("div");
	  div.id = 'ballon';
	  div.innerHTML = this.html;
	  div.style.left = (map.fromLatLngToDivPixel(this.marker.getPoint()).x - 150) + 'px';
	  div.style.top = (map.fromLatLngToDivPixel(this.marker.getPoint()).y - 250) + 'px';
	  this._map = map;
	  this._div = div;
	  map.getPane(G_MAP_FLOAT_PANE).appendChild(div);  
	}
	MyOverlay.prototype.remove = function(){
	  this._div.parentNode.removeChild(this._div);
	}
	MyOverlay.prototype.redraw = function() {
	  //niet
	}




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 GetTileUrl1888(a,b) {
	if (b > 18) {return 'niet.png';} else {return "/tiles/1888/" + TileToQuadKey(a.x, a.y, b) + '.png';}
	}

function GetTileUrl1946(a,b) {
	if (b > 18) {return 'niet.png';} else {return "/tiles/1946/" + TileToQuadKey(a.x, a.y, b) + '.png';}
	}

function GetTileUrl1979(a,b) {
	if (b > 18) {return 'niet.png';} else {return "/tiles/1979/" + TileToQuadKey(a.x, a.y, b) + '.png';}
	}	

	
function GetTileUrlBlaeu(a,b) {
	if (b > 18) {return 'niet.png';} else {return "/tiles/blaeu/" + 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 GetTileUrl_deventer(a,b) {return "http://www.hetutrechtsarchief.nl/kaartlayers/Layer_Deventer/" + TileToQuadKey(a.x, a.y, b) + '.png';}	


function zetbounds(){
	bounds = new GLatLngBounds();
	$("#locaties .toon a").each(function (i) {
		eval('pnt = new GLatLng(' + this.getAttribute('rel') + ')');
		bounds.extend(pnt); 
	});
	if (!bounds.isEmpty()) {
			zl = map.getBoundsZoomLevel(bounds);
			if (zl > 17) zl = 17;
			map.setCenter(bounds.getCenter(), zl);
	}
}

function zoek(){
		$("#zoekres").html('');
		zetzoekpunten(eId('zoekterm').value);
		var v = eId('zoekterm').value + ' Amersfoort NL';
		geocoder.setBaseCountryCode('nl');
		geocoder.getLocations(v, geocoder_gevonden);
}

function zetzoekpunten(q){
		map.clearOverlays();
		puntenweg = true;
		markers = []
		q = q.toLowerCase();
		$("#locaties span a").each(function (i) {
			if (this.innerHTML.toLowerCase().indexOf(q) > -1 || this.title.toLowerCase().indexOf(q) > -1) {
				eval('ll = new GLatLng(' + this.getAttribute('rel') + ')');
				if ($("#zoekres").html() == '')$("#zoekres").append('<h2>Gevonden locaties</h2>');
				$(this).clone().appendTo("#zoekres");
				href = this.href.replace(location.href, '');	 
				markers.push(createMarker(ll, this.innerHTML, href, false));				
			}
		});
		
}

function geocoder_gevonden(res){
	var zoekres = '';
	if (res.Placemark) {

	for (i=0; i < res.Placemark.length; i++){
		ll = res.Placemark[i].Point.coordinates[1] + ',' + res.Placemark[i].Point.coordinates[0];
		ka = kortAdres(res.Placemark[i].address, ll);
		address = ka.split(',');
		if (zoekres.toLowerCase().indexOf('>' + address[0].toLowerCase()) < 0
				&& ka.toLowerCase().indexOf('halte') < 0
				&& ka.toLowerCase().indexOf('station ') < 0
				&& address[0].indexOf('de ') != 0
				&& ka.indexOf('(') < 0
				&& res.Placemark[i].address.indexOf('Amersfoort') > -1
				&& address[0] != 'Amersfoort'
			) {
				point = eval('new GLatLng(' +  ll + ')');
				
				title = address[0].replace(/ \d+.*/g,'');
				url = "collecties/?q=" + escape(address[0]);
				markers.push(createMarker(point,  title, url, true));
				zoekres += '<a class="adri" href="' + url + '">' + ka.split(',')[0] + "</a>";

		}
		}
	}
	
	if (zoekres != '' )$("#zoekres").append('<h2>Gevonden adressen</h2>' + zoekres);
	if ($("#zoekres").html() == '') $("#zoekres").html('Niets gevonden...');
	
	var zoekbounds = new GLatLngBounds();
	for (var i=0; i<markers.length; i++){
			map.addOverlay(markers[i])
			zoekbounds.extend(markers[i].getPoint());
	}

		if (!zoekbounds.isEmpty()) {
				zl = map.getBoundsZoomLevel(zoekbounds);
				if (zl > 17) zl = 17;
				map.setCenter(zoekbounds.getCenter(), zl);
				
			$("#zoekres a").click(function(){
				doe(this.href); return false;
			});				
			
			if (markers.length == 1) GEvent.trigger(markers[0],'click');
		}	
	
}

function kortAdres(str,ll){
	ad = str.split(','); a  = ad[0];
	//if (a.indexOf('(') < 1) a = a + ', ' + ad[1].replace(/\d+/, '');
	a = a.replace('  ',' '); a = a.replace(', Netherlands','');	
	return a;
}



function groot(title, url){
	sluitballon();
	html = "<div class='balkje3'><a style='float:right' class='aknop' onclick='grootweg()'>&nbsp;</a>" + title + "</div>"
	html += '<iframe src="' + url + '" width="700" height="507" scrolling="auto" frameborder="0" allowtransparency="true"/>';
	$('#grootwindow').html(html);
	$('#grootwindow').slideDown(sp);
}

function grootweg(){
	$('#grootwindow').slideUp(sp, function(){$('#grootwindow').html('')});
}

function vergroot(o){
		groot(eId('detitel').innerHTML, '/collecties/vergroot.aspx?' +  o.getAttribute('rel') + '&title=' + escape(o.title) );

}

function doe(pad){
	$('#sofie').hide();
	hidecontextmenu();
	oorpad = pad;
	pad  = pad.replace(srvr, '');	 
	pad  = pad.replace(location.href, '');
	padl = pad.split('/');

	switch(padl.length)
	{
		case 1:
			id = '#' + pad;
			$('#menu div div:not(' + id + ' div)').slideUp(sp);
			$('#menu div:not(' + id + ')').removeClass();
			if (!$(id + '.uitgeklapt').removeClass().length) $(id).addClass('uitgeklapt');
			$(id + ' div').slideToggle(sp);
			
			if (puntenweg && pad != 'wandelingen' && pad != 'zoeken' ){
				$("#zoekres").html(''); eId('zoekterm').value = '';
				window.setTimeout(function() {
					$("#wandelingen span, #wandelingen i").removeClass( 'toon' );
					map.clearOverlays(); zetpunten();
				}, 1);
			}
			
			if ($("#menu .uitgeklapt").length==0) $('#sofie').show();
			
			break;
			
		case 2:
			
			switch(padl[0])
			{	
				case 'kaarten':
					
					sel = 'gt(2)';
					if (parseInt(padl[1], 10) + '' == 'NaN'){
						
						if (padl[1] == 'kaart') {$("body").addClass('kaartbg');} else {$("body").removeClass('kaartbg')}
						
						eval("map.setMapType("  + padl[1].toUpperCase() + ")");
						sel = 'lt(3)';
						}
						
					else if (padl[1] == '0'){
						if (window.cOV) map.removeOverlay(cOV); cOV = null;
						}

					else
						{
						if (window.cOV) map.removeOverlay(cOV);
						eval("cOV = OV" + padl[1]);
						if (map.getZoom() > 16) map.setZoom(16);
						map.addOverlay(cOV);
						}
						
					$('#kaarten div a:' + sel).removeClass();
					$('#kaarten div a[href$="' + pad + '"]').addClass('geselecteerd');
					
					break;	
					
				case 'locaties':
						
						for (var i=0; i<markers.length; i++){
							if (markers[i].url == pad || markers[i].url == oorpad)	{ GEvent.trigger(markers[i],'click'); break; };
						}
					break;	
					
				case 'ingezonden':
						for (var i=0; i<markers.length; i++){
							if (markers[i].url == pad || markers[i].url == oorpad)	{ GEvent.trigger(markers[i],'click'); break; };
						}
					break;						

				case 'collecties':
						
						for (var i=0; i<markers.length; i++){
							if (markers[i].url == pad || markers[i].url == oorpad)	{ GEvent.trigger(markers[i],'click'); break; };
						}
					break;	
				
				case 'tijdbalk':
					groot(padl[1], pad);
					break;
					
				case 'informatie':
					var titl = padl[1]; titl = titl.charAt(0).toUpperCase() + titl.substr(1);
					groot(titl, pad);
					break;
			
			}
			break;
			
		case 3:
			switch(padl[0])
			{		
			case 'wandelingen':
						if (!puntenweg) zetroutepunten( padl[1].replace('amersfoort-bierstad', 'r1228').replace('amersfoort-vestingstad', 'r1238') );
						
						for (var i=0; i<markers.length; i++){
							if (markers[i].url == pad || markers[i].url == oorpad)	{ GEvent.trigger(markers[i],'click'); break; };
						}
					break;	
			}
			break;		
			
	}
}



function title2url(str){
	str = str.toLowerCase();
	str = str.replace(/ /g, '-');
	return str;
}

function ki(obj){groot('Info',obj.parentNode.href)}

var data = {"parken": [
{"ll": "52.153556476218625,5.339269638061523", "v": "th_park_plantsoen_begraafplaats", "t": "Birkhoven - bosvijver"},
{"ll": "52.147500027311295,5.310258865356445", "v": "buurt", "t": "Birkt"},
{"ll": "52.14207485626463,5.3414154052734375", "v": "th_park_plantsoen_begraafplaats", "t": "Birkhoven"},
{"ll": "52.1372285135794,5.31489372253418", "v": "buurt", "t": "Vlasakkers"},
{"ll": "52.13095909247831,5.33935546875", "v": "th_park_plantsoen_begraafplaats", "t": "Nimmerdor"},
{"ll": "52.13572709391782,5.386476516723633", "v": "th_park_plantsoen_begraafplaats", "t": "Nimmerdor"},
{"ll": "52.12758693811187,5.325107574462891", "v": "buurt", "t": "Oude Kamp"},
{"ll": "52.12937842689608,5.372142791748047", "v": "tn_gebouw_huisnummer", "t": "Oud-Leusden"},
{"ll": "52.123687566476114,5.379180908203125", "v": "tn_gebouw_huisnummer", "t": "Rusthof"},
{"ll": "52.10576714900491,5.369911193847656", "v": "th_park_plantsoen_begraafplaats", "t": "Treek, den"},
{"ll": "52.13275044568151,5.406303405761719", "v": "th_park_plantsoen_begraafplaats", "t": "Lockhorsterbos"},
{"ll": "52.137597275579594,5.407934188842773", "v": "tg_straat_plein_water", "t": "Heiligenbergerbeek"},
{"ll": "52.14931704848983,5.398406982421875", "v": "th_park_plantsoen_begraafplaats", "t": "Randenbroek, Park"},
{"ll": "52.16789117696066,5.41102409362793", "v": "th_park_plantsoen_begraafplaats", "t": "Waterwingebied Rustenburg-Schuilenburg"},
{"ll": "52.18082661633686,5.387163162231445", "v": "th_park_plantsoen_begraafplaats", "t": "Schothorst, Stadspark"},
{"ll": "52.15518894321066,5.350770950317383", "v": "th_park_plantsoen_begraafplaats", "t": "Bokkeduinen"},
{"ll": "52.152187264194154,5.345664024353027", "v": "th_park_plantsoen_begraafplaats", "t": "Birkhoven"},
{"ll": "52.14009950850899,5.366177558898926", "v": "th_park_plantsoen_begraafplaats", "t": "Galgenberg "},
{"ll": "52.15018603240721,5.345191955566406", "v": "th_park_plantsoen_begraafplaats", "t": "Dierenpark Amersfoort"},
{"ll": "52.15495197590997,5.36433219909668", "v": "wijk", "t": "Soesterkwartier"},
{"ll": "52.13008973334755,5.354719161987305", "v": "tf_bedrijf_instelling", "t": "Hoge Kleij"}
  ]};