/**
 * Plaats Maps object
 */
$.plaatsMapsJS = {
	/**
	 * Variable to store map
	 */
	map: null,
	geoCoder: null,
	reversegeocoder: null,

	/**
	 * Variables to store overlay data
	 */
	overlays: null,
	selectedOverlay: null,
	clickedOverlay: null,
	currentOverlay: null,
	hoverOverlayIndex: -1,
	enablePhotosByZoomLevel: false,	
	totalMapMarkers: 0,
	proccessedMapMarkers: 0,

	/**
	 * Array with zoomlevels
	 */
	zoomLevels: {
		country: 7,
		province: 8,
		community: 10,
		town: 13
	},


	/**
	 * Array with colors
	 */
	colors: {
		normal: "#f00",
		hover: "#0f0",
		select: "#00f"
	},


	/**
	 * Opacity of overlays
	 */
	opacity: 0.37,


	/**
	 * Variable to store markers
	 */
	markers: new Array(),
	
	
	/**
	 * Variable to store the photo markers
	 */
	photoMarkers: new Array(),
	
	
	/**
	 * Variable to store the map markers
	 */
	adMarkers: new Array(),
	zooMarkers: new Array(),
	amusementMarkers: new Array(),
	holidayMarkers: new Array(),
	
	pointBuffer: null,
	
	/**
	 * The selected photo ID
	 */
	photoSelectedId: null,


	/**
	 * Used to keep track of open infowindows
	 */
	openInfoWindow: null,


	/**
	 * Initialize the plaatsMaps object and load the Google map
	 */
	init: function() {
		// Check if Google maps object exists
		if(typeof GMap2 == 'undefined') {
			alert('GoogleMaps is not loaded!');
			return false;
		}
		// Check if browser is compatible
		if (!GBrowserIsCompatible()) {
			alert('Browser not capable of showing GoogleMaps!');
			return false;
		}

		// Load Google map
		var mapOptions = {
    		googleBarOptions : { 
    			style : "new",       
    			adsOptions: {
        			channel: "3030876387",
        			adsafe: "high",
/*        			resultList : document.getElementById('results'),
        			linkTarget : G_GOOGLEBAR_LINK_TARGET_BLANK,
        			searchFormHint : "Zoek op de kaart",*/
        			language: "nl"
      			}
			}
  		}
	
		this.map = new GMap2(document.getElementById("gmap"), mapOptions);


		// Set the center of the map to the Netherlands and show it at a decent zoom level
		this.map.setCenter(new GLatLng(52.21, 5.6), 7);
		
		// Disable dragging of map
		this.map.disableDragging();

		// Bind the unload function
		$(document).bind("unload", function() {
			GUnload();
		});
	},

	
	/**
	 * Enable local search
	 */
	enableGoogleBar: function() {
		this.map.enableGoogleBar();
	},
	
	/**
	 * Enable adsense
	 */
	enableAdSense: function() {
		var publisherID = 'pub-0752905126364364';
      	var adsManagerOptions = {
        	maxAdsOnMap : 3,
        	style: 'adunit',
        	channel: '3030876387'  
      	};
      	adsManager = new GAdsManager(this.map, publisherID, adsManagerOptions);
      	adsManager.enable();		
	},
	

	/**
	 * Change map type
	 */
	setMapType: function(mapType) {
		if (mapType == 'normal') {
			this.map.setMapType(G_NORMAL_MAP);
		}
		else if (mapType == 'satellite') {
			this.map.setMapType(G_SATELLITE_MAP);
		}
	},


	/**
	 * Enable map controls (disabled by default)
	 */
	enableControls: function() {
		// Enable continuous and scrollwheel zoom
		this.map.enableContinuousZoom();
		this.map.enableScrollWheelZoom();
		
		// Enable dragging of map
		this.map.enableDragging();

  	    // Add a large zoom and position controller
		this.map.addControl(new GLargeMapControl());
	},


	/**
	 * Get the overlay coordinates using a xmlHttpRequest
	 */
	getOverlays: function(locationType, provinceId) {
		// Get the overlays using a JSON call
		var params = (provinceId != null) ? locationType + '/' + provinceId : locationType;
		$.getJSON("/locatie/kaart-overlays/" + params, function(overlays) {
			var overlaysLength = overlays.length;
			for (var i=0; i < overlaysLength; i++) {
				var polygons = [];
				$.each(overlays[i].boundaries, function(k, v) {
					var coords = [];
					var valLength = v.length;
					for (var j=0; j < valLength; j++) {
						// Create the coordinate object for Google maps
						coords[j] = new GLatLng(v[j].latitude, v[j].longitude);
					}
					// Add polygons to locations
					polygons[k] = new GPolygon(coords, "#fff", 1, 1, $.plaatsMapsJS.colors.normal, $.plaatsMapsJS.opacity);
				});
				overlays[i]["polygons"] = polygons;
			}

			// If this is called for the first time, also display the overlays on the map
			if ($.plaatsMapsJS.overlays == null) {
				// Save all polygons
				$.plaatsMapsJS.overlays = overlays;

				// Show overlays on the map
				$.plaatsMapsJS.showOverlays(locationType, provinceId);
			}
		});
	},


	/**
	 * Show overlays on the Google map
	 */
	showOverlays: function(locationType, provinceId) {
		// If there are no saved overlays, retrieve them
		if (this.overlays == null) {
			this.getOverlays(locationType, provinceId);
			return;
		}

		// Add all overlays to the map
		var overlaysLength = this.overlays.length;
		for (var i=0; i < overlaysLength; i++) {
			var polygonsLength = this.overlays[i].polygons.length;
			for (var j=0; j < polygonsLength; j++) {
				this.map.addOverlay(this.overlays[i].polygons[j]);
			}
		}

		// Bind click event
		GEvent.addListener(this.map, "click", function(overlay, point) {
			$.plaatsMapsJS.clickOverlay(overlay, point)
		});

		GEvent.addListener(this.map, "mousemove", function(point) {
		    $.plaatsMapsJS.hoverOverlay(point)
		});

		// Change cursor to a pointer in the map area
		$('#gmap').css('cursor','pointer');
	},


	/**
	 * Select overlay on the Google map
	 */
	selectOverlay: function(overlayColor) {
		// If no overlay is clicked, return
		if (this.overlays == null || this.currentOverlay == null) { return }

		// Reset all overlays
		this.resetOverlays();

		var currentPolygonLength = this.currentOverlay.polygons.length;
		for (var i=0; i < currentPolygonLength; i++) {
			// Make the clicked overlay active
			this.map.removeOverlay(this.currentOverlay.polygons[i]);
			this.currentOverlay.polygons[i].color = overlayColor;
			this.map.addOverlay(this.currentOverlay.polygons[i]);
		}
	},


	/**
	 * Handle the click on an overlay
	 */
	clickOverlay: function(overlay, point) {
		// If no overlay is clicked, return
		if (overlay == null || this.overlays == null) { return }

		// If a province overlay is clicked, go to the community overview
		var overlaysLength = this.overlays.length;
		for (var i=0; i < overlaysLength; i++) {
			var polygonsLength = this.overlays[i].polygons.length;
			for (var j=0; j < polygonsLength; j++) {
				if (overlay == this.overlays[i].polygons[j]) {
					this.currentOverlay = this.overlays[i];
					this.selectOverlay(this.colors.select);
					setTimeout('$.plaats.moveToUrl("/gemeenten-overzicht/' + this.currentOverlay.name +'")', '100');
					return;
				}
			}
		}
	},


	/**
	 * Handle the mouse movements
	 */
	hoverOverlay: function(point) {

	    var newHoverOverlayIndex = -1;
	    for (var i=0; i < this.overlays.length; i++) {
	        for (var j=0; j < this.overlays[i].polygons.length; j++) {
	            var vertexCount = this.overlays[i].polygons[j].getVertexCount();
	            var leftCount = 0;

	            for (var k=0; k < vertexCount; k++) {
	                var s = this.overlays[i].polygons[j].getVertex(k);
	                var e = this.overlays[i].polygons[j].getVertex((k+1)%vertexCount);

    	            // Test for edges that have one vertex below and vertex above
    	            // the mouse pointer.
	                if ((s.y < point.y && e.y > point.y) || (s.y > point.y && e.y < point.y)) {
	                    var t = (point.y - s.y) / (e.y - s.y);
	                    var x = (e.x - s.x)*t;

	                    // Count the edges that have the intersection point with the mouse_y axis
	                    // left from the mouse pointer.
	                    if (x < point.x - s.x) {
	                        leftCount++;
	                    }
	                }
	            }

	            // If the number of counted edges is odd, the mouse pointer is inside the polygon.
	            if (leftCount % 2 == 1) {
	                newHoverOverlayIndex = i;
	            }
	        }
	    }

        if (newHoverOverlayIndex != this.hoverOverlayIndex) {

            // Remove the old highlighted overlay, if any.
            if (this.hoverOverlayIndex != -1) {
                for (var j=0; j < this.overlays[this.hoverOverlayIndex].polygons.length; j++) {
       				this.map.removeOverlay(this.overlays[this.hoverOverlayIndex].polygons[j]);
    				this.overlays[this.hoverOverlayIndex].polygons[j].color = this.colors.normal;
    				this.map.addOverlay(this.overlays[this.hoverOverlayIndex].polygons[j]);
                }
            }

            // Highlight the new overlay, if any.
            this.hoverOverlayIndex = newHoverOverlayIndex;
            if (this.hoverOverlayIndex != -1) {
                for (var j=0; j < this.overlays[this.hoverOverlayIndex].polygons.length; j++) {
                    this.map.removeOverlay(this.overlays[this.hoverOverlayIndex].polygons[j]);
        			this.overlays[this.hoverOverlayIndex].polygons[j].color = this.colors.hover;
        			this.map.addOverlay(this.overlays[this.hoverOverlayIndex].polygons[j]);
                }
            }
        }
	},


	/**
	 * Reset selected overlay or all overlays
	 */
	resetOverlays: function(clearOverlays) {
		if (clearOverlays) {
			// Remove all overlays
			this.map.clearOverlays();
			this.selectedOverlay = null;
			this.clickedOverlay = null;
		}
		else if (this.selectedOverlay != null) {
			var selectedPolygonLength = this.selectedOverlay.polygons.length;
			for (var i=0; i < selectedPolygonLength; i++) {
				// Remove the previous selected overlay
				this.map.removeOverlay(this.selectedOverlay.polygons[i]);
				this.selectedOverlay.polygons[i].color = this.colors.normal;
				this.map.addOverlay(this.selectedOverlay.polygons[i]);
			}
		}
	},


	/**
	 * Center the map on a location
	 */
	centerOnLocation: function(locationName, locationType) {

		// Determine the zoom level using the location type
		var zoomLevel = (locationType == '') ? this.zoomLevels.country : this.zoomLevels[locationType];

		// Load the geoCoder to get the coordinates based on a location
		if($.plaatsMapsJS.geoCoder == null) {
			$.plaatsMapsJS.geoCoder = new GClientGeocoder();
		}
		if ($.plaatsMapsJS.geoCoder) {
			// Get latitude and longitude using a location
			$.plaatsMapsJS.geoCoder.getLatLng(locationName + ', Nederland', function(point) {
				if (point) {
					// Set map zoom and pan to the location
					$.plaatsMapsJS.map.setZoom(zoomLevel);
					$.plaatsMapsJS.map.panTo(point);

					if (locationType == 'town') {
						var icon = $.plaatsMapsJS.createIcon();
						var marker = new GMarker(point, icon);
						$.plaatsMapsJS.map.addOverlay(marker);
					}
					
					if ($.plaatsMapsJS.enablePhotosByZoomLevel) {
						// Handle changes in the zoom-level
						GEvent.addListener($.plaatsMapsJS.map, 'moveend', $.plaatsMaps.retrievePhotoMarkers);
						
						// Retrieve the photo markers now
						$.plaatsMapsJS.retrievePhotoMarkers();
					}
				}
			});
		}
	},


	/**
	 * Center the map on a point
	 */
	centerOnPoint: function(point, locationType) {

		// Determine the zoom level using the location type
		var zoomLevel = (locationType == '') ? this.zoomLevels.country : this.zoomLevels[locationType];

		// Set map zoom and pan to the location
		$.plaatsMapsJS.map.setZoom(zoomLevel);
		$.plaatsMapsJS.map.panTo(point);
					
		if ($.plaatsMapsJS.enablePhotosByZoomLevel) {
			// Handle changes in the zoom-level
			GEvent.addListener($.plaatsMapsJS.map, 'moveend', $.plaatsMapsJS.retrievePhotoMarkers);
			
			// Retrieve the photo markers now
			$.plaatsMapsJS.retrievePhotoMarkers();
		}
	},


	/**
	 * Create a marker on the map
	 */
	createMarker: function(locationName, url, photoCount) {
		// Load the geoCoder to get the coordinates based on a location
		if($.plaatsMapsJS.geoCoder == null) {
			$.plaatsMapsJS.geoCoder = new GClientGeocoder();
		}
		if ($.plaatsMapsJS.geoCoder) {
			// Get latitude and longitude using a location
			$.plaatsMapsJS.geoCoder.getLatLng(locationName + ', Nederland', function(point) {
				if (point) {
					// Set html used in infowindow
					locationName = locationName.split(',');
					var html = '<span class="head"><strong>' + locationName[0] + '</strong></span><div class="balloon"><ul><li><a href="/' + url + '/">Home</a></li><li><a href="/' + url + '/alles-over/">Alles over</a></li>'
					
					if (photoCount != undefined) {
						html += '<li><a href="/' + url + '/fotos/">Foto\'s';
						if (photoCount > 0) {
							html += ' (' + photoCount + ')';
						}						
						html += '</a></li>';
					}
					
					html += '</ul></div>';

					// Create marker icon
					var icon = $.plaatsMapsJS.createIcon();

					// Set marker
					var markerCount = $.plaatsMapsJS.markers.length;
					$.plaatsMapsJS.markers[markerCount] = {
						name: locationName,
						url: url,
						point: point,
						marker: new GMarker(point, icon),
						open: false,
						html: html
					};

					// Add the marker to the map
					$.plaatsMapsJS.map.addOverlay($.plaatsMapsJS.markers[markerCount].marker);

					// Add handling of click events
					GEvent.addListener($.plaatsMapsJS.markers[markerCount].marker, "click", function() {
						$.plaatsMapsJS.showInfoWindow(markerCount);
					});
				}
			});
		}
	},


	/**
	 * Create icon used as marker
	 */
	createIcon: function() {
		var icon = new GIcon();
		icon.image            = '/images/mapmarker.png';
		icon.iconSize         = new GSize(46, 32);
		icon.shadowSize       = new GSize(27, 20);
		icon.iconAnchor       = new GPoint(12, 34);
		icon.infoWindowAnchor = new GPoint(12, 2);

		return icon;
	},
	
	
	retrievePhotoMarkers: function() {
		// Get the map boundaries in latitude/longitude
		var bounds = $.plaatsMapsJS.map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
			
		// Create the list parameters
		var params = {
			'list[latitudemin]': southWest.lat(),
			'list[latitudemax]': northEast.lat(),
			'list[longitudemin]': southWest.lng(),
			'list[longitudemax]': northEast.lng()
		};
		
		// Retrieve the zoom-level photos
		$.ajax({
			type: 'POST',
			url: '/' + $.plaats.locationUri + '/fotos/list/',
			data: params,
			dataType: 'json',
			success: function(data) {
				// Add the retrieved photos to the map
				if (data.success) {
					var oldPhotos = $.plaatsMapsJS.photoMarkers;
					var oldPhotosCount = oldPhotos.length;
					
					// Hide the old markers
					for (var i = 0; i < oldPhotosCount; ++i) {
						if(oldPhotos[i]) {
							oldPhotos[i].hide();
						}
					}
					
					// Create the new markers
					$.plaatsMapsJS.createPhotoMarkers(data.photos);
				}
			}
		});
	},
	
	
	/**
	 * Create photo markers
	 *
	 * @todo use photo location
	 */
	createPhotoMarkers: function(photos) {
		var photosCount = photos.length;
		
		for (var i = 0; i < photosCount; ++i) {
			// Do not create a marker for the selected photo, which has already been
			// added to the map earlier
			if (photos[i].id != $.plaatsMapsJS.photoSelectedId) {
				$.plaatsMapsJS.photoMarkers[i] = $.plaatsMapsJS.createPhotoMarker(photos[i].id, photos[i].formattedtitle, photos[i].latitude, photos[i].longitude, photos[i].formattedtownname);
			}
		}
	},


	/**
	 * Create a photo marker on the map
	 */
	createPhotoMarker: function(id, title, latitude, longitude, town) {
		// Have the selected photo on the front
		var zIndex = (id == $.plaatsMapsJS.photoSelectedId) ? 2 : 1;
		
		// Add the photo to the map as a marker
		var photoMarker = new GMarker(new GLatLng(latitude.replace(',', '.'), longitude.replace(',', '.')), {icon: $.plaatsMapsJS.createPhotoIcon(id), 'title': 'Klik op de foto voor meer details.', zIndexProcess: function(marker) { return zIndex; }});
		$.plaatsMapsJS.map.addOverlay(photoMarker);
		
		// Add handling of click events on the photo marker, in which case one
		// should be redirected to the photo page
		GEvent.addListener(photoMarker, 'click', function() {
			window.location = '/' + town + '/fotos/' + id + '/' + title + '/';
		});
		
		return photoMarker;
	},


	/**
	 * Create photo icon used as marker
	 */
	createPhotoIcon: function(id) {		
		// Determine if this is the selected photo
		var selectedPhoto = ($.plaatsMapsJS.photoSelectedId == id);
		
		var icon = new GIcon();		
		var iconDirectory = selectedPhoto ? 'iconbig' : 'icon';		
		icon.image      = '/var/' + id.substr(0, 2) + '/' + iconDirectory + '/' + id + '.png';
		icon.iconSize   = selectedPhoto ? new GSize(60, 67) : new GSize(41, 46);
		icon.iconAnchor = new GPoint(20, 7);

		return icon;
	},


	/**
	 * Show info window
	 */
	showInfoWindow: function(markerId) {
		// Update old status
		if (this.openInfoWindow != markerId) {
			this.markers[markerId].open = false;
		}

		// If clicked on the same (open) window, it has to be closed
		if (!this.markers[markerId].open) {
			this.markers[markerId].marker.openInfoWindowHtml(this.markers[markerId].html);
			this.markers[markerId].open = true;
			this.openInfoWindow = markerId;
		} else {
			this.markers[markerId].marker.closeInfoWindow();
			this.markers[markerId].open = false;
			this.openInfoWindow = null;
		}
	},
	
	/**
	* Looks for a point by given address
	*/
	geocode: function(address){
		if($.plaatsMapsJS.geoCoder == null) {
			$.plaatsMapsJS.geoCoder = new GClientGeocoder();
		}
		if ($.plaatsMapsJS.geoCoder) {
	    	$.plaatsMapsJS.geoCoder.getLatLng(address.toString(), function(point) {
		     	if (!point) {
		      		alert(address + " niet gevonden.");
		      	}
		        else {
		         	$.plaatsMapsJS.map.setCenter(point, 13);
		          	placemarker = new GMarker(point, {draggable: true});
		          	$.plaatsMapsJS.map.addOverlay(placemarker);
		          	$('#longitude').val(point.lng());
					$('#latitude').val(point.lat());
					GEvent.addListener(placemarker, "dragend", function () {
		    			var point = placemarker.getPoint();
		    			$.plaatsMapsJS.reverseGeocode(point);
		    		});
		        }
	      	});
  		}
	},
	
	reverseGeocode: function(point) {
		if($.plaatsMapsJS.reversegeocoder == null) {
			$.plaatsMapsJS.reversegeocoder = new GReverseGeocoder($.plaatsMapsJS.map);
		}
		if($.plaatsMapsJS.reversegeocoder) {
			GEvent.addListener($.plaatsMapsJS.reversegeocoder, "load",	function(placemark) {
								
				var townname = $.plaatsMapsJS.reversegeocoder.getPlacemarkProperty(placemark, 'DependentLocalityName');
				if(townname != null) {
					// If the reversegeocoder loads and returns a placemark get the townname form that placemark
					$('#townname').val(townname);
				}
			});
			
			// Handle a reverse geocode error
			GEvent.addListener($.plaatsMapsJS.reversegeocoder, "error", function() {
					$('#townname, #longitude, #latitude').val('');
			});
			// Reversegeocode
			$.plaatsMapsJS.reversegeocoder.reverseGeocode(point);
		}
	},
	
	/**
	 * Create a Map icon
	 */
	createMapIcon: function(image) {				
		var icon = new GIcon();			
		icon.image      = image;
		icon.iconSize   = new GSize(43, 26);
		icon.iconAnchor = new GPoint(12, 0);

		return icon;
	},
	
	
	/**
	 * Create a Marktplaats icon
	 */
	createMarktplaatsMapIcon: function(image) {				
		var icon = new GIcon();			
		icon.image      = image;
		icon.iconSize   = new GSize(19, 19);
		icon.iconAnchor = new GPoint(9, 0);

		return icon;
	},
	

	/**
	 * Create a marker on the map
	 */
	createMapMarker: function(id, locationName, image, type, url, latitude, longitude) {
		// Set html used in infowindow
		locationName = locationName.split(',');
		var html = '<span class="head"><strong>' + locationName + '</strong></span><div class="balloon"><ul><li><a href="' + url + '/">Bekijk</a></li></ul></div>';
		
		// Create marker icon
		if(type == 'photo') {
			var icon = $.plaatsMapsJS.createPhotoIcon(id);
		}
		else if(type == 'ad') {
			var icon = $.plaatsMapsJS.createMarktplaatsMapIcon(image);
		}
		else {
			var icon = $.plaatsMapsJS.createMapIcon(image);
		}
		
		point = new GLatLng(latitude, longitude);
		
		var marker = new GMarker(point, icon);
		// Add handling of click events on the photo marker, in which case one
		// should be redirected to the photo page
		
		// Set marker
		var mapMarker = {
			name: locationName,
			url: url,
			point: point,
			marker: marker,
			open: false,
			html: html,
			type: type
		};
		
		GEvent.addListener(mapMarker.marker, 'click', function() {
			$.plaatsMapsJS.map.openInfoWindowHtml(mapMarker.point,mapMarker.html);
		});
							
		if(type == 'photo') {
			var photos = $.plaatsMapsJS.photoMarkers;
			var photosCount = photos.length;
			$.plaatsMapsJS.photoMarkers[photosCount] = mapMarker.marker;
		} else if(type == 'ad') {
			var ads = $.plaatsMapsJS.adMarkers;
			var adCount = ads.length;
			$.plaatsMapsJS.adMarkers[adCount] = mapMarker.marker;
		} else if(type == 'amusement') {
			var amusements = $.plaatsMapsJS.amusementMarkers;
			var amusementCount = amusements.length;
			$.plaatsMapsJS.amusementMarkers[amusementCount] = mapMarker.marker;
		} else if(type == 'zoo') {
			var zoos = $.plaatsMapsJS.zooMarkers;
			var zooCount = zoos.length;
			$.plaatsMapsJS.zooMarkers[zooCount] = mapMarker.marker;
		} else if(type == 'holiday') {
			var holidays = $.plaatsMapsJS.holidayMarkers;
			var holidayCount = holidays.length;
			$.plaatsMapsJS.holidayMarkers[holidayCount] = mapMarker.marker;
		}
		
		var markerCount = $.plaatsMapsJS.markers.length;
		$.plaatsMapsJS.markers[markerCount] = mapMarker;
		// Add the marker to the map
		$.plaatsMapsJS.map.addOverlay(mapMarker.marker);
		
		if(!$('#chkZoos').attr('checked') && type =='zoo') {
			$.plaatsMapsJS.markers[markerCount].marker.hide();
		}
		if(!$('#chkAds').attr('checked') && type =='ad') {
			$.plaatsMapsJS.markers[markerCount].marker.hide();
		}
		if(!$('#chkAmusements').attr('checked') && type =='amusement') {
			$.plaatsMapsJS.markers[markerCount].marker.hide();
		}
		if(!$('#chkHolidays').attr('checked') && type =='holiday') {
			$.plaatsMapsJS.markers[markerCount].marker.hide();
		}
		if(!$('#chkPhotos').attr('checked') && type =='photo') {
			$.plaatsMapsJS.markers[markerCount].marker.hide();
		}
	},
	
	/**
	 * Zoom out until atleast on of the markers is shown
	 */
	zoom: function ( markers ) {
		var markerCount = markers.length;
		if(markerCount > 0) {
			var zoomlevel = $.plaatsMapsJS.map.getZoom();
			for(var i=0;i<markerCount;++i) {
				if($.plaatsMapsJS.map.getBounds().contains(markers[i].getLatLng()) || zoomlevel <= $.plaatsMapsJS.zoomLevels.country) {
					return;
				} 
			}
			
			$.plaatsMapsJS.map.setZoom(zoomlevel - 1);
			$.plaatsMapsJS.zoom( markers );
		}
	},
	
	zoomAll: function () {
		if($('#chkZoos').attr('checked')) {
			$.plaatsMapsJS.zoom( $.plaatsMapsJS.zooMarkers );
		}
		if($('#chkAds').attr('checked')) {
			$.plaatsMapsJS.zoom( $.plaatsMapsJS.adMarkers );
		}
		if($('#chkAmusements').attr('checked')) {
			$.plaatsMapsJS.zoom( $.plaatsMapsJS.amusementMarkers );
		}
		if($('#chkHolidays').attr('checked')) {
			$.plaatsMapsJS.zoom( $.plaatsMapsJS.holidayMarkers );
		}
		if($('#chkPhotos').attr('checked')) {
			$.plaatsMapsJS.zoom( $.plaatsMapsJS.photoMarkers );
		}
	}
};

// Initialize the Plaats maps object
$(document).ready(function() {
	$.plaatsMapsJS.init();
});