
		var KuyperMap = {	
				
			map: null,
						
			custommap : null,
			custommap1 : null,
			custommap2 : null,
			custommap3 : null,
			
			tilelayers: null,
			
			transparencyControl : null,
			
			transparency : 2,
			lastTransparency : 2,
			
			kuyperOverlay : null,
			
			fillAllowed: true,
			
			OnTransparencyChange: function(newValue)
			{			                
        KuyperMap.transparency = newValue;
        KuyperMap.tilelayers[0].getOpacity = function() {return 1 - (Math.abs(4 - KuyperMap.transparency)/4)};
        if (newValue > 4 && KuyperMap.map.getCurrentMapType() != G_SATELLITE_MAP)
        { 
        	KuyperMap.map.setCenter(KuyperMap.map.getCenter(),KuyperMap.map.getZoom(),G_SATELLITE_MAP);
        };
        if (newValue < 4 && KuyperMap.map.getCurrentMapType() != G_NORMAL_MAP)
        { 
        	KuyperMap.map.setCenter(KuyperMap.map.getCenter(),KuyperMap.map.getZoom(),G_NORMAL_MAP);
        };
        // a redraw doesn't work: apparently the opacity value gets cached
        // need to explicitly re-add the overlay for the value to be updated
        KuyperMap.map.removeOverlay(KuyperMap.kuyperOverlay);
        KuyperMap.map.addOverlay(KuyperMap.kuyperOverlay);

        //KuyperMap.Redraw(); 
			},
			
			GotoRoadMapView: function()
				{
				
					this.lastTransparency = this.transparency;
					this.map.setCenter(this.map.getCenter(),this.map.getZoom(),G_NORMAL_MAP);
 					KuyperMap.map.removeOverlay(KuyperMap.kuyperOverlay);	
 					$('mapopts1').hide();
 					$('mapopts2').hide();
 				},
			
			GotoKuyperMapView: function()
				{
					
				this.lastTransparency = this.transparency;
					KuyperMap.OnTransparencyChange(4);
					KuyperMap.map.removeOverlay(KuyperMap.kuyperOverlay);	
					this.map.setCenter(this.map.getCenter(),this.map.getZoom(),this.custommap);
 					$('mapopts1').show();
 					$('mapopts2').hide();
	 				this.fillAllowed = true;
			},
			
			GotoSatelliteView: function()
				{
					
					this.lastTransparency = this.transparency;
					this.map.setCenter(this.map.getCenter(),this.map.getZoom(),G_SATELLITE_MAP);
 					KuyperMap.map.removeOverlay(KuyperMap.kuyperOverlay);	
  				$('mapopts1').hide();
 					$('mapopts2').hide();
				},
			
			GotoHybridView: function()
				{
				
        	this.OnTransparencyChange(this.lastTransparency);
 					$('mapopts2').show();
 					$('mapopts1').hide();
 					this.fillAllowed = false;
				},
			
			InitializeSingle:function()
			{		    
             // create the slider control	
				this.transparencyControl = new Control.Slider('handle1','track1',{
                        sliderValue:KuyperMap.transparency,
                        onChange:KuyperMap.OnTransparencyChange,
                        range:$R(0,8)
                        
                    }
                );

              

   			this.map = new GMap2(document.getElementById("KuyperGMap"));
   			
        var customUI = this.map.getDefaultUI();
        customUI.controls.maptypecontrol  = false;
        customUI.controls.menumaptypecontrol  = false;
        this.map.setUI(customUI);
		      // ====== Create a copyright entry =====
		      var copyright = new GCopyright(1,
		          new GLatLngBounds(new GLatLng(51.237847,3.262939),new GLatLng(52.784834,5.482422) ),
		          10, '<a style="color:#588642;" href="http://www.the-end-of-the.net/topography/Kuyper/terms">Kuypers Gemeente-Atlas</a>');

		      // ============================================================
		      // ====== Create a copyright collection =====
		      // ====== and add the copyright to it   =====
		      var copyrightCollection = new GCopyrightCollection('Map Data:');
		      copyrightCollection.addCopyright(copyright);

	      // ============================================================
	      // == Write our own getTileUrl function ========
	      // In this case the tiles are names like  8053/5274-3.png      
	 
	      // ============================================================
	      // ===== Create the GTileLayer =====
	      // ===== and apply the CustomGetTileUrl to it
	      this.tilelayers = [new GTileLayer(copyrightCollection,5,14)]; 
	      // make this Tile Layer available for zoom levels 11 to 14
	      this.tilelayers[0].getTileUrl = KuyperMap.CustomGetTileUrl;
	      
	  
	      // ============================================================
	      // === If we know the copyright, return it, otherwise look for the G_NORMAL_MAP copyright =====      
	      this.tilelayers[0].getCopyright = function(a,b) {	 
							var c= copyrightCollection.getCopyrightNotice(a,b);
						
				     	if (document.getElementById('ust_cb').checked)
							{
								c = G_NORMAL_MAP.getTileLayers()[0].getCopyright(a,b);
							};            
			        return c;
			      }
	    
	      // ============================================================
	      // ===== Create the GMapType =====
	      // ===== and add it to the map =====

            this.tilelayers[0].getOpacity = function() {return 1};





	      this.custommap = new GMapType(this.tilelayers, new GMercatorProjection(15), "Kuyper",{});
	     // this.custommap1 = new GMapType(this.tilelayers, new GMercatorProjection(15), "Kuyper kaart opgevuld met wegenkaart",{});
	     // this.custommap2 = new GMapType(this.tilelayers, new GMercatorProjection(15), "Kuyper kaart opgevuld met luchtfoto's",{});
	     // this.custommap3 = new GMapType(this.tilelayers, new GMercatorProjection(15), "Kuyper kaart opgevuld met terreinkaart",{});
	      
	     // this.map.addMapType(G_PHYSICAL_MAP);
        	      
       this.map.addMapType(this.custommap);
      //  this.map.addMapType(this.custommap1);
       // this.map.addMapType(this.custommap2);
       // this.map.addMapType(this.custommap3);
        
      //  var mapControl = new GHierarchicalMapTypeControl();
      //  mapControl.addRelationship(this.custommap, this.custommap1, 'opvullen met wegenkaart')
      //  mapControl.addRelationship(this.custommap, this.custommap2, "opvullen met luchtfoto's")
      //  mapControl.addRelationship(this.custommap, this.custommap3, 'opvullen met terreinkaart')
	      
		   // this.map.addControl(mapControl);
	
				var centerLoc = new GLatLng(52.09364042859117, 5.119972229003906);
				
					
				if (window.location.search != '')
				{
						var s = window.location.search.replace('?','&');
						var qp = s.split('&');
						for (var i = 0; i < qp.length; i++)
						{
							var av = qp[i].split('=');
							if (av[0] == 'll' && av.length == 2)
							{
								if (av[1].indexOf(',') != -1)
								{
									cc = av[1].split(','); 
									centerLoc = new GLatLng(cc[0], cc[1]); 
								}
							}
							
						};
						
				};
			
				
	      this.map.setCenter(centerLoc, 12, this.custommap);
	      this.kuyperOverlay = new GTileLayerOverlay(this.tilelayers[0]);
	      
          //  this.map.addOverlay(this.kuyperOverlay);
	      
		        
		    MarkerCollection.InitializeMarkers(this.map);
        
			},
			
			OpenInfoWindow : function(marker,markerKey)
			{
					marker.openInfoWindowHtml('<div style="font-size:75%;width:300px;height:140px;padding-right:3px;>Bezig met laden...</div>');
					//alert(markerKey);
					var req = GXmlHttp.create();
                      req.open("GET", "/geo/" + markerKey + ".terwen", true);
                      req.onreadystatechange = function() {
          	
					  if (req.readyState == 4) {
					    marker.openInfoWindowHtml('<div style="font-size:65%;width:300px;margin-top:-3px;">Uit: <i>Het Koningrijk der Nederlanden, voorgesteld in eene reeks beschrijvingen</i> door J. L. Terwen, 1858</div><div style="font-size:75%;width:300px;height:140px;padding-right:3px;overflow-y:scroll;overflow-x:hide;">' + req.responseText + '</div>');
					  }
					 };
					
                     req.send(null);
			},
			
			OpenImageWindow : function(marker,markerKey, sText, iWidth, iHeight, bIsNotTerwen, imageAlt)
			{   
  			if (!imageAlt)
  			{
  			 imageAlt = sText;
        }
			   if (bIsNotTerwen)
			   {
					marker.openInfoWindowHtml('<div style="font-size:65%;padding-right:3px;"><img width="' + iWidth + '" height="' + iHeight + '" alt="' + imageAlt + '" src="http://www.the-end-of-the.net/geo/' + markerKey + '.jpg"/><br/>' + sText + '</div>');
			   }
			   else
			   {
					marker.openInfoWindowHtml('<a onclick="window.open(this.href);return false" href="http://www.the-end-of-the.net/geo/' + markerKey + '.jpg" style="display:block;font-size:65%;padding-right:3px;"><img style="border-style:none;" width="' + iWidth + '" height="' + iHeight + '" alt="' + imageAlt + '" src="http://www.the-end-of-the.net/geo/' + markerKey + '.terwen.jpg"/><br/>' + sText + '</a>');
					}
			},
		
		
		    

      
      Redraw:
      	function(){
      		this.map.setCenter(this.map.getCenter());
      	},
      	
			MoveTo: 
				function(fltLat, fltLong){
					var targetPoint = new GLatLng(fltLat, fltLong);
					if (this.map.getBounds().contains(targetPoint))
					{
						this.map.panTo(targetPoint);
						
					}
					else
					{
						this.map.setCenter(targetPoint,13);
								
					};
				},
				
			CustomGetTileUrl:
				function(a,b){
					if (CustomTileSet.HasTile(a,b))
					{
					  return "http://map.the-end-of-the.net/kuyper/" + b  + "/" + a.x+"/"+a.y+".png";
					}
					else 
					{
						if (document.getElementById('ust_cb').checked && KuyperMap.fillAllowed)
							{
								return G_NORMAL_MAP.getTileLayers()[0].getTileUrl(a,b);
							}
							else
							{
								if (document.getElementById('uat_cb').checked && KuyperMap.fillAllowed)
									{
										return G_SATELLITE_MAP.getTileLayers()[0].getTileUrl(a,b);
									}
								else
									{
										return "http://www.xs4all.nl/~kievit66/kuyper_map/witte_tegel.png";
									};
							}
	        }
      	}											
			};


	
