// gewone kaartknop
function SetDefaultMapControl() {
}
SetDefaultMapControl.prototype = new GControl();
SetDefaultMapControl.prototype.initialize = function(gmap) {
  var container = document.createElement("div");
  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv);
  container.appendChild(zoomOutDiv);
  zoomOutDiv.appendChild(document.createTextNode("Kaart"));
  GEvent.addDomListener(zoomOutDiv, "click", function() {
    gmap.setMapType(G_MAP_TYPE);
  });
  gmap.getContainer().appendChild(container);
  return container;
}
SetDefaultMapControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(260, 7));
}
SetDefaultMapControl.prototype.setButtonStyle_ = function(button) {
  button.className = "mapTypeControl";
}

// sateliet kaartknop
function SetSatelliteMapControl() {
}
SetSatelliteMapControl.prototype = new GControl();
SetSatelliteMapControl.prototype.initialize = function(gmap) {
  var container = document.createElement("div");
  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv);
  container.appendChild(zoomOutDiv);
  zoomOutDiv.appendChild(document.createTextNode("Luchtfoto"));
  GEvent.addDomListener(zoomOutDiv, "click", function() {
    gmap.setMapType(G_SATELLITE_TYPE);
  });
  gmap.getContainer().appendChild(container);
  return container;
}

SetSatelliteMapControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(325, 7));
}
SetSatelliteMapControl.prototype.setButtonStyle_ = function(button) {
  button.className = "mapTypeControl";
}
// hybride kaartknop 
function SetHybridMapControl() {
}
SetHybridMapControl.prototype = new GControl();
SetHybridMapControl.prototype.initialize = function(gmap) {
  var container = document.createElement("div");
  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv);
  container.appendChild(zoomOutDiv);
  zoomOutDiv.appendChild(document.createTextNode("Beide"));
  GEvent.addDomListener(zoomOutDiv, "click", function() {
    gmap.setMapType(G_HYBRID_TYPE);
  });
  gmap.getContainer().appendChild(container);
  return container;
}

SetHybridMapControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(390, 7));
}
SetHybridMapControl.prototype.setButtonStyle_ = function(button) {
  button.className = "mapTypeControl";
}


// droombeek kaartknop
function SetDroombeekMapControl() {
}
SetDroombeekMapControl.prototype = new GControl();
SetDroombeekMapControl.prototype.initialize = function(gmap) {
  var container = document.createElement("div");
  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv);
  container.appendChild(zoomOutDiv);
  zoomOutDiv.appendChild(document.createTextNode("Droombeek"));
  GEvent.addDomListener(zoomOutDiv, "click", function(custommap) {
    gmap.setMapType(custommap);
  });
  gmap.getContainer().appendChild(container);
  return container;
}

SetDroombeekMapControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(390, 7));
}
SetDroombeekMapControl.prototype.setButtonStyle_ = function(button) {
  button.className = "mapTypeControl";
}


function clickZoomIn() {
	gmap.zoomIn();
}

function clickZoomOut() {
	gmap.zoomOut();
}

function clickPan(d_lat, d_lng) {
	gmap.panDirection(d_lat,d_lng);
}

function clickRestorePosition() {
	gmap.returnToSavedPosition();
}

function Verhaal( data ) {
  for( var d in data ) { this[d] = data[d]; }
}


function createMarker(point, pin, tekst, url) {
	var dummy = new GMarker(point, {icon: pin, title: tekst});
	if(url){
		GEvent.addListener(dummy, 'click', function() {
			window.location = url;
		});
	}
	return dummy;
}

function createIcon(theme) {
        var icon = new GIcon();
        icon.image = "/gfx/icon-" + theme + ".gif";
        icon.shadow = "/gfx/shadow-icon-" + theme + ".png";
	icon.iconSize = new GSize(24.0, 24.0);
	icon.shadowSize = new GSize(37.0, 24.0);
	icon.iconAnchor = new GPoint(12.0, 24.0);
	return icon;
}

function initPoint(pointData) {
	var point = new GLatLng(pointData.latitude, pointData.longitude);
	var icon = createIcon(pointData.category);
	var marker = createMarker(point, icon, pointData.title, pointData.href);
	var visible = false;

	pointData.show = function() {
		if (!visible) {
			gmap.addOverlay(marker);
			visible = true;
		}
 	}
	pointData.hide = function() {
		if (visible) {
			gmap.removeOverlay(marker);
			 visible = false;
 		}
 	}

	pointData.show();
}

function ToggleViz(obj) {
	for(id in verhalen) {
		if (verhalen[id].category == obj.value ) {
			if (obj.checked) {
				verhalen[id].show();
			} else {
				verhalen[id].hide();
			}
		}
	}
}

function TileToQuadKey(tile, zl) { 
	var url; 
	url = "/kaarten/"; 
	for (var i = zl; i > 0; i--){ 
		var mask = 1 << (i - 1); 
		var cell = 0; 
		if ((tile.x & mask) != 0) 
			cell++; 
		if ((tile.y & mask) != 0) 
			cell += 2; 
		url += cell; 
	} 
	url += ".png";
	return url; 
}

