	function rsz(){
		div =  document.getElementById("map");
		div.style.width = (document.body.clientWidth - 205) + 'px';
		div.style.height =  (document.body.clientHeight - 45) + 'px';
		  	
	}

    function kaart() {
      if (GBrowserIsCompatible()) {
		rsz();
		window.onresize = rsz;
		
		  
        var map = new GMap2(document.getElementById("map"),{
                 mapTypes : [G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP]
              });
		oz=10;
        map.addControl(new GLargeMapControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,10)));
		
		map.addControl(new GOverviewMapControl(new GSize(150,150)));
		map.addControl(new GScaleControl());
		
    	
    	var copyright = new GCopyright(1,new GLatLngBounds(new GLatLng(41.920238025762, -5.5160760879517), new GLatLng(61.920238025762, 14.483923912048)), 0, "HMR");
    	var copyrightCollection = new GCopyrightCollection('Kaart 1832');
		copyrightCollection.addCopyright(copyright);
		
		var tilelayers = [new GTileLayer(copyrightCollection , 10, 19)];
		tilelayers[0].getTileUrl = CustomGetTileUrl;
		
		var custommap = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "1832", {errorMessage:"Geen detailkaart beschikbaar"});
		map.addMapType(custommap);
		
		co = location.hash.replace('#','').replace('%20','').replace('+','');
		if (co.indexOf(',') != -1){
        	eval("map.setCenter(new GLatLng(" + co + "), 19)");}
		else{
			map.setCenter(new GLatLng(51.92123719585688,4.487324953079224), 17);}
		map.setMapType(custommap);
		
		var mapControl = new GHierarchicalMapTypeControl();
        mapControl.clearRelationships();
        mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Straatnamen", false);
        map.addControl(mapControl,new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(oz,10)));		
		
		
		
		$("#loclijst p").each(function (i) {
			var $deze = $(this).children(); 
			if ($deze.eq(0).hasClass('geo')){
					var Nmarker = createMarker($deze.eq(0).html(), $deze.filter('a:eq(1)').html(), $(this).html());
					map.addOverlay(Nmarker);
			}
		});
		
		
		map.enableScrollWheelZoom();
		

		if (location.hash=='#puntopvragen' || document.location.toString().indexOf('puntopvragen') != -1){
			GEvent.addListener(map, "click", function(overlay, point) {	  	
			var	xyz = prompt('Aangeklikt punt:',point.toString());
			});
		}
      }
    }


     function createMarker(punt,title,html) {
		var icon = new GIcon();
		icon.image = '/grafiek/bouwhistorie/icoon.png';
		icon.iconSize = new GSize(32, 32);
		icon.iconAnchor = new GPoint(16, 16);
		icon.infoWindowAnchor = new GPoint(16, 16);
		
		eval("var point =  new GLatLng(" + punt.replace(';',',') + ")");

        var marker = new GMarker(point, {icon: icon, title: title});

        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html, {maxWidth : 275, maxHeight : 80});
        });

        return marker;
      }




	function CustomGetTileUrl(a,b) {
		var f = "/grafiek/kaart/" + TileToQuadKey(a.x, a.y, b) + '.gif';
		return f;
	}
	
	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; 
	}
