var ds_Plugin_Gmaps = NetManagerBase.extend({
					   
	options: {
		zoomlevel: 11,
		mapSizeX: 658,
		mapSizeY: 526
	},
	
	map: null,
	mapControl: null,
	mapControlPosition: null,
	mapTypeControl: null,
	mapTypeControlPosition: null,
	geocoder: null,
	reverseGeocoder: null,
	locationMarker: null,
	markerManager: null,
	numMarkers: 0,
	polyGons: [],
	bounds: null,
	point: null,
	points: [],
	formHolder: null,
	mode: null,
	COFactorGt1200: 0.13,
	COFactorLt1200: 0.10,
	calculatorObject: null,
	currentProject: null,
	markerBaseIcon: null,
	
	
	initialize: function(options) {
		
		this.setOptions(options);
		this.geocoder = new GClientGeocoder();
		this.markerBaseIcon = new GIcon();
	  this.markerBaseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	  this.markerBaseIcon.iconSize = new GSize(24, 24);
	  this.markerBaseIcon.shadowSize = new GSize(41, 34);
	},
	
	initMap: function() {
		
		if (GBrowserIsCompatible()) {
			//console.log(this.options.mapSizeX);
			this.map = new GMap2($('gmap'), { size: new GSize(this.options.mapSizeX,this.options.mapSizeY) });
			this.map.setMapType(G_HYBRID_MAP);

	        //this.map.setCenter(new GLatLng(-59.175928,-52.558594), this.options.zoomlevel);
	        this.map.setCenter(new GLatLng(69.675, 26.338), this.options.zoomlevel);
	        
	        this.mapControl = new ExtLargeMapControl();
	        this.mapControlPosition = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,20));
	        this.map.addControl(this.mapControl, this.mapControlPosition);
	        
	        this.mapTypeControl = new GMapTypeControl();
	        this.mapTypeControlPosition = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,20));
	        this.map.addControl(this.mapTypeControl, this.mapTypeControlPosition);
	        
	        this.map.enableDoubleClickZoom();
	        
	        this.markerManager = new MarkerManager(this.map, { borderPadding: 50, maxZoom: 15, trackMarkers: true });
	        
        	if (this.mode === 'edit') { 
        		this.map.setZoom(this.formHolder.getElement('input[name=zoomlevel]').value);
        		
        		//this.placeMarker(this.formHolder.getElement('input[name=title_from]').value, new GLatLng(this.formHolder.getElement('input[name=latitude_from]').value, this.formHolder.getElement('input[name=longitude_from]').value));
        		//this.placeMarker(this.formHolder.getElement('input[name=title_to]').value, new GLatLng(this.formHolder.getElement('input[name=latitude_to]').value, this.formHolder.getElement('input[name=longitude_to]').value));
        		$('totalDistanceInput').value = this.formHolder.getElement('input[name=amount_km]').value;

        		//console.log(this.formHolder.getElement('input[name=latitude_from]').value);
        		//console.log(this.formHolder.getElement('input[name=longitude_from]').value);
        		//console.log(this.formHolder.getElement('input[name=title_from]').value);
        		//console.log(this.formHolder.getElement('input[name=latitude_to]').value);
        		//console.log(this.formHolder.getElement('input[name=maptype]').value);
        	}
		} else {
			alert('Helaas is uw browser niet geschikt voor Google Maps.');
		}   
	},
	
	
	initWizardMap: function() {
		
		
		if (GBrowserIsCompatible()) {
			this.map = null;
			this.map = new GMap2($("mapContainer"), { size: new GSize(this.options.mapSizeX,this.options.mapSizeY) });
			this.map.setMapType(G_HYBRID_MAP);

	        this.map.setCenter(new GLatLng(51.49198,3.618816), this.options.zoomlevel);
	        
	        this.mapControl = new ExtLargeMapControl();
	        this.mapControlPosition = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10));
	        this.map.addControl(this.mapControl, this.mapControlPosition);
	        
	        this.mapTypeControl = new GMapTypeControl();
	        this.mapTypeControlPosition = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
	        this.map.addControl(this.mapTypeControl, this.mapTypeControlPosition);
	        
	        this.markerManager = new MarkerManager(this.map, { borderPadding: 50, maxZoom: 15, trackMarkers: true });
	        
		} else {
			alert('Helaas is uw browser niet geschikt voor Google Maps.');
		}  
	},
	
	initDistanceCalculator: function() {
		
		this.bounds = new GLatLngBounds();
		this.point  = null;
		this.points = [];
	},
	
	getAmountCC: function ( amount_km ) {
		return (amount_km > 1200) ? parseInt(amount_km * this.COFactorGt1200 * 1.3) : parseInt(amount_km * this.COFactorLt1200 * 1.3);
	},
	
	loadGeocoder: function (sAddress) {
		
		var divContainer	= new Element('div').setProperty('id','container');
		var divMessage 		= new Element('div').setProperty('id','message').inject(divContainer);
		var divContent 		= new Element('div').setProperty('id','content').inject(divContainer);
		var divMapContainer = new Element('div').setProperty('id','mapContainer').inject(divContent);
		
		if (!this.geocoder) {
			alert('Er is een probleem met de verbinding met Google.');
		} else {
			this.geocoder.getLatLng(sAddress, this.setMapPoint.bind(this));				
		}
		
		return divContainer;
    },

    setFromFlightFinder: function(point) {
    	$('locationFinderInput').removeClass('loading');
    	if (point) {
    		this.point = point;
        	this.placeMarker(this.point, new GLatLng(this.point.lat(), this.point.lng()));
        }
    },
    
	placeMarker: function (overlay, latlng) {
		var iSubtotalFlight = 0;
		/* create base marker */
		
        
        if(this.numMarkers === 0) {
        	this.numMarkers = this.markerManager.getMarkerCount(1);
        }
		
		if (latlng) {   
            
            if(this.numMarkers === 0) {
            	/* create icon */
            	this.markerBaseIcon.image = '/images/front/plane_up.png';
            	
            	this.startLocationMarker = new GMarker(latlng, {draggable: true, icon: this.markerBaseIcon, bouncy: true, autopan:true});
            	
            	this.markerManager.addMarker(this.startLocationMarker, this.options.zoomlevel);
            	
            	this.geocoder.getLocations(latlng, this.setFlightFrom.bind(this));
            	
            	GEvent.addListener(this.startLocationMarker, "dragend", this.onDistanceMarkerDragEnd.bind(this));
            	
            	this.bounds.extend(this.startLocationMarker.getPoint());
            	
            	$('locationFinderLabel').setText('Geef uw aankomst luchthaven op');
            	$('locationFinderInput').setProperty('value', 'plaatsnaam, land').blur();
            	
            	
            } else {
            	this.markerBaseIcon.image = '/images/front/plane_down.png';
            	this.endLocationMarker = new GMarker(latlng, {draggable: true, icon: this.markerBaseIcon, bouncy: true, autopan:true});
            	
            	this.markerManager.addMarker(this.endLocationMarker, this.options.zoomlevel);
            	
            	this.geocoder.getLocations(latlng, this.setFlightTo.bind(this));
            	
            	GEvent.addListener(this.endLocationMarker, "dragend", this.onDistanceMarkerDragEnd.bind(this));
            	
			    this.bounds.extend(this.endLocationMarker.getPoint());
            	
            	this.distancePlot = new GPolyline([
		          this.startLocationMarker.getLatLng(),
		          this.endLocationMarker.getLatLng()
		        ], "#00A5D9", 4, 1, {});
		        
		        this.map.addOverlay(this.distancePlot);
		        this.totalDistanceKM = this.distancePlot.getLength()  / 1000;
		        $('totalDistanceInput').setProperty('value', this.totalDistanceKM.round() + 'KM.');
		        
		        this.formHolder.getElement('input[name=amount_km]').setProperty('value', this.totalDistanceKM.round());
		        iSubtotalFlight = this.getAmountCC(this.totalDistanceKM.round());
		        this.formHolder.getElement('input[name=amount_cc]').setProperty('value', iSubtotalFlight);
		        this.calculatorObject.calculateVliegtuigCoins();
		        
		        
		        this.map.setZoom(this.map.getBoundsZoomLevel(this.bounds));
   				var clat = (this.bounds.getNorthEast().lat() + this.bounds.getSouthWest().lat()) / 2;
	      	    var clng = (this.bounds.getNorthEast().lng() + this.bounds.getSouthWest().lng()) / 2;
	      	    this.map.setCenter(this.bounds.getCenter());
				
								
            }
        	this.markerManager.refresh();
        	this.numMarkers = this.numMarkers + 1;
		}
			    
	},
	
	
    setFlightFrom: function(response) {
    	
    	var outputText = 'n.v.t.';
    	if (!response || (response.Status.code !== 200 && response.Status.code !== 602)) {
		    alert("Er is een fout opgetreden: " + response.Status.code);
	    } else {
			if (!$defined(response.Placemark)) {
					this.formHolder.getElement('input[name=latitude_from]').setProperty('value', this.startLocationMarker.getPoint().lat().toFixed(14));
			    	this.formHolder.getElement('input[name=longitude_from]').setProperty('value', this.startLocationMarker.getPoint().lng().toFixed(14));
					this.formHolder.getElement('input[name=title_from]').setProperty('value', outputText);
			} else {
		    		this.point = response.Placemark[0];
		    		
	   				this.formHolder.getElement('input[name=latitude_from]').setProperty('value', this.startLocationMarker.getPoint().lat().toFixed(14));
				    this.formHolder.getElement('input[name=longitude_from]').setProperty('value', this.startLocationMarker.getPoint().lng().toFixed(14));
				    
				    if ($defined(this.point.AddressDetails.Country && response.Status.code !== 602)) {
				    	if ($defined(this.point.AddressDetails.Country.AdministrativeArea)) {
						    if ($defined(this.point.AddressDetails.Country.AdministrativeArea.Locality)) {
								outputText = this.point.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
						    } 
				    	} 
					    if ($defined(this.point.AddressDetails.Country.CountryName)) {
							outputText += ', ' + this.point.AddressDetails.Country.CountryName;
					    } 
				    } 
				    this.formHolder.getElement('input[name=title_from]').setProperty('value',outputText);
				    if (this.map.getZoom() !== 'NaN') {
				    	this.options.zoomlevel = this.map.getZoom();
				    	this.options.mapType   = this.map.getCurrentMapType() ;
			        	this.formHolder.getElement('input[name=zoomlevel]').setProperty('value', this.options.zoomlevel.toInt());
			        	this.formHolder.getElement('input[name=maptype]').setProperty('value', this.getMapType().getName());
				    } 
				    
			    	this.startLocationMarker.openInfoWindowHtml('<div class="item">' +
			    													'<h3>Informatie</h3>' +
			    													'<p> ' +
				    													'<img src="/images/front/plane_up.png" width="24" height="24" border="0" />' +
				    													'Uw vertrek luchthaven' +
			    													'</p>' +
			    													'<p> ' + outputText + '</p>' +
		    													'</div>');	
						
			}
			
    	}
    },
    
    
    setFlightTo: function(response) {
    	
    	var outputText = 'n.v.t.';
    	if (!response || (response.Status.code !== 200 && response.Status.code !== 602)) {
		    alert("Er is een fout opgetreden: " + response.Status.code);
	    } else {
			if (!$defined(response.Placemark)) {
					this.formHolder.getElement('input[name=latitude_to]').setProperty('value', this.endLocationMarker.getPoint().lat().toFixed(14));
			    	this.formHolder.getElement('input[name=longitude_to]').setProperty('value', this.endLocationMarker.getPoint().lng().toFixed(14));
					this.formHolder.getElement('input[name=title_to]').setProperty('value', outputText);
			} else {
		    		this.point = response.Placemark[0];
		    		
	   				this.formHolder.getElement('input[name=latitude_to]').setProperty('value', this.endLocationMarker.getPoint().lat().toFixed(14));
				    this.formHolder.getElement('input[name=longitude_to]').setProperty('value', this.endLocationMarker.getPoint().lng().toFixed(14));
				    
				    if ($defined(this.point.AddressDetails.Country && response.Status.code !== 602)) {
				    	if ($defined(this.point.AddressDetails.Country.AdministrativeArea)) {
						    if ($defined(this.point.AddressDetails.Country.AdministrativeArea.Locality)) {
								outputText = this.point.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
						    } 
				    	} 
					    if ($defined(this.point.AddressDetails.Country.CountryName)) {
							outputText += ', ' + this.point.AddressDetails.Country.CountryName;
					    } 
				    } 
				    this.formHolder.getElement('input[name=title_to]').setProperty('value',outputText);
				    if (this.map.getZoom() !== 'NaN') {
				    	this.options.zoomlevel = this.map.getZoom();
				    	this.options.mapType   = this.map.getCurrentMapType() ;
			        	this.formHolder.getElement('input[name=zoomlevel]').setProperty('value', this.options.zoomlevel.toInt());
			        	this.formHolder.getElement('input[name=maptype]').setProperty('value', this.getMapType().getName());
				    } 
				    
			    	this.endLocationMarker.openInfoWindowHtml('<div class="item">' +
			    													'<h3>Informatie</h3>' +
			    													'<p> ' +
			    														'<img src="/images/front/plane_down.png" width="24" height="24" border="0" />' +
			    														'Uw aankomst luchthaven:' +
			    													'</p>' +
			    													'<p> ' + outputText + '</p>' +
			    													'<p> ' +
			    														'<img src="/images/cms/icon_info_24.gif" width="24" height="24" border="0" />' +
			    														'<span> ' + this.totalDistanceKM.round() + ' </span>' +
			    														' KM' +
			    													'</p>' +
		    													'</div>');	
					
	   				$('locationFinderHolder').empty().setText('De afstand is berekend, eventueel kunt u de iconen nog slepen naar een exactere locatie.');
		    													
			}
    	}	
    },
    
   
	
	onDistanceMarkerDragEnd: function() {
		var iSubtotalFlight = 0;
		if (this.numMarkers === 2) {
			this.map.removeOverlay(this.distancePlot);
			this.distancePlot = new GPolyline([
			          this.startLocationMarker.getLatLng(),
			          this.endLocationMarker.getLatLng()
			        ], "#00A5D9", 4, 1, {geodesic:true});
			        
        	this.map.addOverlay(this.distancePlot);
        	
        	var km = this.distancePlot.getLength() / 1000;
        	km = km.round();
        	$('totalDistanceInput').setProperty('value', km + ' KM.');
        	this.formHolder.getElement('input[name=amount_km]').setProperty('value', km);
        	
        	iSubtotalFlight = this.getAmountCC(km);
        	
		    this.formHolder.getElement('input[name^=amount_cc]').setProperty('value', iSubtotalFlight);
		    
		    this.calculatorObject.calculateVliegtuigCoins();
		}
	},
	
	
    
    setMapPoint: function(point) {
    	
        if (!point) {
        	var icon = new Element('span').addClass('errorIcon').inject($('message'));
        	var message = new Element('p').setText("Het adres kon helaas niet worden gevonden, probeer een plaats in de buurt").inject($('message'));
        	$('mapContainer').setStyle('display','none');
        } else {
        	this.initMap();
        	
        	this.map.removeControl(this.mapControl);
        	this.map.removeControl(this.mapTypeControl);
        	
        	this.mapControl = new ExtLargeMapControl();
	        this.map.addControl(this.mapControl);
	        
	        this.mapTypeControl = new GMapTypeControl();
	        this.map.addControl(this.mapTypeControl);
        	
        	this.point = point;
        	
        	var icon = new Element('span').addClass('infoIcon').inject($('message'));
        	var message = new Element('p').setText("Het adres is gevonden, controleer of dit juist is.").inject($('message'));
        	
        	this.map.clearOverlays();
            this.map.setCenter(this.point, this.options.zoomlevel.toInt());
            this.locationMarker = new GMarker(this.point, {draggable:true, bouncy:true});
        	this.map.addOverlay(this.locationMarker);
        	
        	/*var ed = tinyMCE.get('gmaps_text');
			if (ed.getContent() !== '') {
		    	this.locationMarker.openInfoWindowHtml(ed.getContent());	
		    }*/
            
            GEvent.addListener(this.locationMarker, "dragend", this.onMarkerDragEnd.bind(this));
	        
            $('Latitude').setProperty('value', this.locationMarker.getPoint().lat().toFixed(14));
        	$('Longitude').setProperty('value', this.locationMarker.getPoint().lng().toFixed(14));
        }
        
   },
   
   onZoom: function(oldZoomlevel, newZoomlevel) {
   		
		if (newZoomlevel !== 'NaN') {
	    	this.options.zoomlevel = newZoomlevel.toInt();
        	$('zoomlevel').setProperty('value', this.options.zoomlevel.toInt());
	    } else {
	    	this.options.zoomlevel = newZoomlevel.toInt();
	    	$('zoomlevel').setProperty('value', 11);
	    }
	    
	    alert(this.options.zoomlevel);
   	
   },
   
   onMarkerDragEnd: function(latlng) {
   		
   		if ($('Latitude').getProperty('value') !== this.locationMarker.getPoint().lat().toFixed(14)	||
   			$('Longitude').getProperty('value') !== this.locationMarker.getPoint().lng().toFixed(14)) {
   			if (latlng !== null) {
   				
   				oWizard = this.getWizard('gmap');
   				oWizard.setStatus({icon:'loading', text: 'Bezig met ophalen lokatie gegevens van Google'});
   				
			    this.geocoder.getLocations(latlng, this.setNewAddress.bind(this));
		    }
		}

    },
    
    setNewAddress: function(response) {
    	
    	if (!response || (response.Status.code !== 200 && response.Status.code !== 602)) {
		    alert("Er is een fout opgetreden: " + response.Status.code);
	    } else {
	    	oWizard = this.getWizard('gmap');
			oWizard.setStatus({icon:'info', text: 'Lokatie is gevonden'});
			if (!$defined(response.Placemark)) {
				if (!confirm('Er zijn voor deze lokatie geen NAW gegevens gevonden, wilt u doorgaan?')) {
					this.map.setCenter(this.point, this.map.getZoom());
		            this.locationMarker.setLatLng(this.point);
					oWizard.setStatus({icon:'info', text: 'Het adres is teruggezet.'});
				} else {
					$('Latitude').setProperty('value', this.locationMarker.getPoint().lat().toFixed(14));
			    	$('Longitude').setProperty('value', this.locationMarker.getPoint().lng().toFixed(14));
			    	$('address').setProperty('value', 'n.v.t.');
			    	$('city').setProperty('value', 'n.v.t.');
		    		$('country').setProperty('value', 'n.v.t.');
				}
			} else {
		    	if (confirm('Het adres is gewijzigd naar: ' + response.Placemark[0].address + ' \n Wilt u deze lokatie opslaan?')) {
		    		this.point = response.Placemark[0];
		    		
	   				$('Latitude').setProperty('value', this.locationMarker.getPoint().lat().toFixed(14));
				    $('Longitude').setProperty('value', this.locationMarker.getPoint().lng().toFixed(14));
				    
				    
				    if ($defined(this.point.AddressDetails.Country && response.Status.code !== 602)) {
				    	if ($defined(this.point.AddressDetails.Country.AdministrativeArea)) {
						    if ($defined(this.point.AddressDetails.Country.AdministrativeArea.Locality.DependentLocality)) {
						   		if ($defined(this.point.AddressDetails.Country.AdministrativeArea.Locality.DependentLocality.Thoroughfare)) {
									$('address').setProperty('value', this.point.AddressDetails.Country.AdministrativeArea.Locality.DependentLocality.Thoroughfare.ThoroughfareName);
						   		} else {
							    	$('address').setProperty('value', 'n.v.t.');
							    }
						    } else {
						    	$('address').setProperty('value', 'n.v.t.');
						    }
						    if ($defined(this.point.AddressDetails.Country.AdministrativeArea.Locality)) {
								$('city').setProperty('value', this.point.AddressDetails.Country.AdministrativeArea.Locality.LocalityName);
						    } else {
						    	$('city').setProperty('value', 'n.v.t.');
						    }	
				    	} else {
				    		$('address').setProperty('value', 'n.v.t.');
				    		$('city').setProperty('value', 'n.v.t.');
				    	}
					    if ($defined(this.point.AddressDetails.Country.CountryName)) {
							$('country').setProperty('value', this.point.AddressDetails.Country.CountryName);
					    } else {
					    	$('country').setProperty('value', 'n.v.t.');
					    }
				    } else {
				    	$('address').setProperty('value', 'n.v.t.');
				    	$('city').setProperty('value', 'n.v.t.');
				    	if ($defined(this.point.AddressDetails.AddressLine)) {
				    		$('country').setProperty('value', this.point.AddressDetails.AddressLine);
				    	} else {
				    		$('country').setProperty('value', 'n.v.t.');
				    	}
				    }
				    
				    
				    if (this.map.getZoom() !== 'NaN') {
				    	this.options.zoomlevel = this.map.getZoom();
			        	$('zoomlevel').setProperty('value', this.options.zoomlevel.toInt());
				    } 
				    
				    oWizard.setStatus({icon:'info', text: 'Het adres is aangepast.'});
				    var ed = tinyMCE.get('gmaps_text');
				    if (ed.getContent() !== '') {
				    	this.locationMarker.openInfoWindowHtml(ed.getContent());	
				    }
				    
				    if(!window.ie) {
					    this.map.setCenter(this.point, this.map.getZoom());
					} 				    
	   			} else {
	   				if(!window.ie) {
					    this.map.setCenter(this.point, this.map.getZoom());
					} 				    
		            this.locationMarker.setLatLng(this.point);
					oWizard.setStatus({icon:'info', text: 'Het adres is teruggezet.'});
	   			}
			}
    	}	
    }, 
    
    
    
    draw: function(point) {
    	
		var givenRad = 50 * this.map.getZoom();
		var givenQuality = 40;
		var centre = point || this.map.getCenter();
		this.drawCircle(centre, givenRad, givenQuality);
    },
    
    drawCircle: function(center, radius, nodes, liColor, liWidth, liOpa, fillColor, fillOpa) {
    	
    	var latConv = center.distanceFrom(new GLatLng(center.lat()+0.1, center.lng()))/100;
		var lngConv = center.distanceFrom(new GLatLng(center.lat(), center.lng()+0.1))/100;
	
		//Loop 
		var points = [];
		var step = parseInt(360/nodes)||10;
		for(var i=0; i<=360; i+=step) {
			var pint = new GLatLng(center.lat() + (radius/latConv * Math.cos(i * Math.PI/180)), center.lng() + 
			(radius/lngConv * Math.sin(i * Math.PI/180)));
			points.push(pint);
			this.bounds.extend(pint); //this is for fit function
		}
		points.push(points[0]); // Closes the circle, thanks Martin
		fillColor = fillColor||liColor||"#00A5D9";
		liWidth = liWidth||2;
		
		this.polyGons.push(new GPolygon(points,liColor,liWidth,liOpa,fillColor,fillOpa, {clickable:true}));
		this.map.addOverlay(this.polyGons[this.numMarkers]);
		
		
    },
    
    
	redrawPolygons: function(center, radius, nodes, liColor, liWidth, liOpa, fillColor, fillOpa) {
		
		for (var i=0;i< this.polyGons.length; i++) {
			this.map.removeOverlay(this.polyGons[i]);
			
			var latConv = this.points[i].distanceFrom(new GLatLng(this.polyGons[i].lat()+0.1, this.polyGons[i].lng()))/100;
			var lngConv = this.points[i].distanceFrom(new GLatLng(this.polyGons[i].lat(), this.polyGons[i].lng()+0.1))/100;
		
			//Loop 
			var points = [];
			var step = parseInt(360/nodes)||10;
			for(var ii=0; ii<=360; ii+=step) {
				var pint = new GLatLng(this.points[i].lat() + (radius/latConv * Math.cos(ii * Math.PI/180)), this.points[i].lng() + 
				(radius/lngConv * Math.sin(ii * Math.PI/180)));
				points.push(pint);
				this.bounds.extend(pint); 
			}
			points.push(points[0]); 
			fillColor = fillColor||liColor||"#00A5D9";
			liWidth = liWidth||2;
			this.polyGons[i] = new GPolygon(points,liColor,liWidth,liOpa,fillColor,fillOpa, {clickable:true});
			this.map.addOverlay(this.polyGons[i]);
		}
	},
	
    
    fit: function() {
    	
		this.map.panTo(this.bounds.getCenter()); 
		this.map.setZoom(2);
		this.options.zoomlevel = 2;
		
	},
	
	zoomOut: function() {
		
		//GLog.write(paragraphs);
		//if(this.numMarkers > 6){
		this.map.zoomOut();
		
	},
	
	getZoomLevel: function() {
		return this.options.zoomlevel;
	},
	
	getMapType: function() {
		return this.map.getCurrentMapType();
	},
	
	setFormHolder: function(elm) {
		this.formHolder = elm;
	},
	
	addMarkers: function(aMarkers) {
		
		this.markerBaseIcon = new GIcon();
	    this.markerBaseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	    this.markerBaseIcon.iconSize = new GSize(24, 24);
	    this.markerBaseIcon.shadowSize = new GSize(41, 34);
		this.markerManager.clearMarkers();
		this.markerManager.refresh();
		$each(aMarkers, function(location, index) {
			
			var latlng = new GLatLng(location.Latitude,location.Longitude);
			var newMarker = new GMarker(latlng, {draggable: false, icon: this.markerBaseIcon, bouncy: true, autopan:true});
			/*GEvent.addListener(newMarker, "click", function() {
				newMarker.openInfoWindowHtml('<div class="item block">' +
												'<h3>' + location.title + ' </h3>' +
												'<p> ' +
													'<img src="/image/crop/iImageId/'+location.image_id+'/iWidth/50" width="50" height="50" border="0" style="float:left; padding:0px 5px 5px 0;" />' +
													location.gmaps_text +
												'</p>' +
												'<p class="button"><a href="/projecten/bekijk/'+location.url_segment+'" title="Klik hier om dit project te openen" alt="Klik hier om dit project te openen"><span class="icon view"></span><span class="value">Open project</span></a></p>' +
											'</div>');
			});
			
			if (location.Latitude === this.currentProject.Latitude && location.Longitude === this.currentProject.Longitude) {
				//GEvent.trigger(newMarker, 'click');
				newMarker.openInfoWindowHtml('<div class="item block">' +
												'<h3>' + location.title + ' </h3>' +
												'<p> ' +
													'<img src="/image/crop/iImageId/'+location.image_id+'/iWidth/50" width="50" height="50" border="0" style="float:left; padding:0px 5px 5px 0;" />' +
													location.gmaps_text +
												'</p>' +
												'<p class="button"><a href="/projecten/bekijk/'+location.url_segment+'" title="Klik hier om dit project te openen" alt="Klik hier om dit project te openen"><span class="icon view"></span><span class="value">Open project</span></a></p>' +
											'</div>');
				this.map.panTo(latlng);
			}*/
			
            this.markerManager.addMarker(newMarker, 0);
		}, this);
		
		
	},
	
	
	generateMap: function() {
		var divContainer	= new Element('div').setProperty('id','container');
		var divMessage 		= new Element('div').setProperty('id','message').inject(divContainer);
		var divContent 		= new Element('div').setProperty('id','MapContent').inject(divContainer);
		var divMapContainer = new Element('div').setProperty('id','mapContainer').inject(divContent);
		
		return divContainer;
	},
	
	resize: function() {
		this.map.checkResize();
	}
	
});

ds_Plugin_Gmaps.implement(new Options);