var detailMarker
var Markers
var GoogleMap 	= null;
var geocoder 	= null;


	//<![CDATA[
	
	function loadMap(id){
		// google map initialiseren
		GoogleMap = new GMap2(document.getElementById(id));
		
		if (!GBrowserIsCompatible()) return
			geocoder = new GClientGeocoder();
	
		if (window.Control){
			if (showZoom==1){
				GoogleMap.addControl(new GOverviewMapControl());
			}
		}
	
	
		if (showScale==1){
			GoogleMap.addControl(new GScaleControl());
		}
		
		
		// Locatie
		type = 'NORMAL'	
		if (document.getElementById('Kaart_X') && document.getElementById('Kaart_Y') && document.getElementById('Kaart_Z') && document.getElementById('Kaart_Type')){
			if (document.getElementById('Kaart_X').value != '') Xas = document.getElementById('Kaart_X').value
			if (document.getElementById('Kaart_Y').value != '') Yas = document.getElementById('Kaart_Y').value
			if (document.getElementById('Kaart_Z').value != '') Zas = parseInt(document.getElementById('Kaart_Z').value)
			if (document.getElementById('Kaart_Type').value != '') type = document.getElementById('Kaart_Type').value
		}
		
		if (document.getElementById('Tab'+type))
			document.getElementById('Tab'+type).id = 'CurrentTab'
		
		
		GoogleMap.setCenter(new GLatLng(Yas, Xas), Zas);
		if (type != 'NORMAL'){
			if (document.getElementById('CurrentTab')) Control.KlikKaartType(document.getElementById('CurrentTab'), type)
		}
	
		// Zoom
		if (window.Control) {
			GoogleMap.enableContinuousZoom()
			GoogleMap.enableDoubleClickZoom()
			//GEvent.addDomListener(document.getElementById("Googlemap"), "DOMMouseScroll", function(event) { Control.wheelZoom(event) }); // Firefox
			//GEvent.addDomListener(document.getElementById("Googlemap"), "mousewheel",     function(event) { Control.wheelZoom(event) }); // IE
			GEvent.addListener(GoogleMap, "zoomend", function(event) { Control.ZoomEnd(event) })
			GEvent.addListener(GoogleMap, "moveend", function(event) { Control.MoveEnd(event) })
			
			document.getElementById(id).oncontextmenu = new Function("return false")
		}
		
	
		// locatie bepalen op basis van coördinaten
		var icon 				= new GIcon();
		icon.image 				= iconImage;
		icon.iconSize 			= new GSize(imgWidth, imgHeight);
		icon.iconAnchor 		= new GPoint(corWidth, corHeight);
		icon.infoWindowAnchor 	= new GPoint(0, 0);
		detailMarker 			= new GMarker(new GLatLng(Yas, Xas), icon)
		GoogleMap.addOverlay(detailMarker);
		
		
		
		if (window.Control){
			Control.SetSliderZoomlevel(GoogleMap.getZoom())
		}
		if (window.GeoData){
			center = GoogleMap.getCenter()
			GeoData.Set(center.lng(), center.lat(), GoogleMap.getZoom())
		}
		
		if (window.Markers) Markers.Refresh()
		
		// var polygon, latlngs;
		
		// polygon = new GPolygon([
			// new GLatLng(52.08259499520418, 4.748272339302063),
			// new GLatLng(52.08296915414034, 4.748617708683014),
			// new GLatLng(52.083109256899576, 4.747987389564514),
			// new GLatLng(52.08272191290411, 4.747751355171204),
			// new GLatLng(52.08259499520418, 4.748272339302063)
		// ], "#5c7cad", 4, 1, "#5c7cad", 0.1);
		// GoogleMap.addOverlay(polygon);
		
		// polygon = new GPolygon([
			// new GLatLng(52.08378174402187, 4.744715094566345),
			// new GLatLng(52.08378833698273, 4.7436100244522095),
			// new GLatLng(52.08318837355755, 4.743631482124329),
			// new GLatLng(52.08378174402187, 4.744715094566345)
		// ], "#5c7cad", 4, 1, "#5c7cad", 0.1);
		// GoogleMap.addOverlay(polygon);
		
		// polygon = new GPolygon([
			// new GLatLng(52.081975236056685, 4.745712876319885),
			// new GLatLng(52.08233786213438, 4.743894338607788),
			// new GLatLng(52.081998312349405, 4.7438836097717285),
			// new GLatLng(52.081589530540604, 4.745723605155945),
			// new GLatLng(52.081975236056685, 4.745712876319885)
		// ], "#5c7cad", 4, 1, "#5c7cad", 0.1);
		// GoogleMap.addOverlay(polygon);
		
		// latlngs = []; 
			// latlngs.push(new GLatLng(52.0830400297088, 4.748389720916748));
			// latlngs.push(new GLatLng(52.0829773954913, 4.748657941818237));
			// latlngs.push(new GLatLng(52.083742186236364, 4.749355316162109));
			// latlngs.push(new GLatLng(52.08381470881636, 4.749054908752441));
			// latlngs.push(new GLatLng(52.08389052775125, 4.7490763664245605));
		// var line = new GPolyline(latlngs, "#adce00", 4); 
		// GoogleMap.addOverlay(line); 
		
		// latlngs = []; 
			// latlngs.push(new GLatLng(52.083778447541086, 4.744811654090881));
			// latlngs.push(new GLatLng(52.08409490858635, 4.745098650455475));
			// latlngs.push(new GLatLng(52.08419380220282, 4.745154976844788));
			// latlngs.push(new GLatLng(52.084472351377954, 4.74522739648819));
			// latlngs.push(new GLatLng(52.08445257279562, 4.745551943778992));
			// latlngs.push(new GLatLng(52.08443773885313, 4.745694100856781));
			// latlngs.push(new GLatLng(52.08434543865576, 4.7463297843933105));
			// latlngs.push(new GLatLng(52.0842696204937, 4.746847450733185));
			// latlngs.push(new GLatLng(52.08409820504378, 4.747874736785889));
			// latlngs.push(new GLatLng(52.083860859487714, 4.748918116092682));
			// latlngs.push(new GLatLng(52.08389547245992, 4.749057590961456));
		// var line = new GPolyline(latlngs, "#adce00", 4); 
		// GoogleMap.addOverlay(line);
		
		// latlngs = []; 
			// latlngs.push(new GLatLng(52.08203457507102, 4.745450019836426));
			// latlngs.push(new GLatLng(52.08209391400646, 4.745490252971649));
			// latlngs.push(new GLatLng(52.08204281659454, 4.745777249336243));
			// latlngs.push(new GLatLng(52.082532360362116, 4.746013283729553));
			// latlngs.push(new GLatLng(52.08279443714202, 4.746133983135223));
			// latlngs.push(new GLatLng(52.082993878188645, 4.74622517824173));
			// latlngs.push(new GLatLng(52.08346033599965, 4.746450483798981));
			// latlngs.push(new GLatLng(52.08380976409874, 4.746614098548889));
			// latlngs.push(new GLatLng(52.084264675826475, 4.746836721897125));
		// var line = new GPolyline(latlngs, "#adce00", 4); 
		// GoogleMap.addOverlay(line); 
		
		//var f = document.frm;
		// var t = document.createElement('textarea');
		//t.name = "points";
		//f.appendChild(t);
		
		//GEvent.addListener(GoogleMap, "click", function(overlay, point) {
			//f.points.value += "latlngs.push(new GLatLng"+point+");\n";
			//alert(point);
		//});
	}
	
	function getCoordinates(address) {
		var address = ""
		
		if (!GBrowserIsCompatible()) return
			geocoder = new GClientGeocoder();
			
			if (geocoder) {
				geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						//coördinaten ophalen
						Xas = setX
						Yas = setY
						Zas = setZ
						
						loadMap('Googlemap');
					}
					else {
						point = String(point)
						point = point.replace("(","")
						point = point.replace(")","")
						point = point.replace(" ","")
						var arPoint = point.split(",")
						
						//coördinaten van het adres ophalen
						Xas = Number(arPoint[1])
						Yas = Number(arPoint[0])
						Zas = setZ
						loadMap('Googlemap');
					}
				}
			);}
		
	}
	//]]>





var Control = new ClassControl()
Control.Initialize()

function ClassControl(){
	
    this.Initialize = function(){
        this.Areal = false
	    this.CurrentLink = false
        this.MarkerMarge = 0
    }
	
	
	this.MouseWheel = function(event){
		var zoomfactor
		if ( event.wheelDelta < 0 ) zoomfactor = -1
		if ( event.wheelDelta > 0 ) zoomfactor = 1
		var x = event.clientX - document.getElementById("Googlemap").offsetLeft
		var y = event.clientY - document.getElementById("Googlemap").offsetTop
		var point = new GPoint(x, y)
		GoogleMap.setCenter(GoogleMap.fromDivPixelToLatLng(point), GoogleMap.getZoom() + zoomfactor);

	}
	
	this.Click = function(event){}


	this.MouseoverImage = function(oImg){
		oImg.src = oImg.src.replace('-n.gif', '-h.gif')
	}


	this.MouseoutImage = function(oImg){
		oImg.src = oImg.src.replace('-h.gif', '-n.gif')
	}
	
	
	this.Dummy = function(){}


	this.KlikKaartType = function(linkje, type){
		if (this.CurrentLink == false)
		{
			this.CurrentLink = document.getElementById('CurrentTab')
			this.CurrentLink.id = ''
			this.CurrentClass = this.CurrentLink.className
		}
		if (type == "NORMAL"){
		    this.MarkerMarge = 0
		    this.Areal = false
		    document.getElementById('ControlDiv').className = 'Control'
		}
		else{
		    this.Areal = true
		    this.MarkerMarge = 14
		    document.getElementById('ControlDiv').className = 'ControlAreal'
		}
		this.onZoom()
		this.CurrentLink.className = this.CurrentClass
		this.CurrentLink = linkje
		
		this.CurrentClass = this.CurrentLink.className
		
		this.CurrentLink.className = this.CurrentClass + ' CurrentTab'
		
	    GoogleMap.setMapType(eval('G_' + type + '_MAP'))
		document.getElementById('Kaart_Type').value = type
	}
	
	
	
	this.Slide = function(event){
		if (!this.Sliding) return
		y = event.clientY - this.DeltaY
		this.SetSliderPixels(y)
	}
	
	
	this.StartSlide = function(event){
	    this.DeltaY = event.clientY - document.getElementById('Slider').offsetTop
		this.Sliding = true
	}
	
	
	this.StopSlide = function(){
		if (!this.Sliding) return
		this.Sliding = false
		y = this.SliderPx - this.MarkerMarge
		if (y < 2 - this.MarkerMarge) y = 2 - this.MarkerMarge
		if (y > 72) y = 72
		z = 17 - Math.round((y - 3) / 7)
		GoogleMap.setZoom(z)
	}
	
	
	this.ClickSlider = function(event){
		y = event.offsetY - 4 - this.MarkerMarge
		if (y < 2 - this.MarkerMarge) y = 2 - this.MarkerMarge
		if (y > 72) y = 72
		this.SetSliderPixels(y)
		z = 17 - Math.round((y - 3) / 7)
		GoogleMap.setZoom(z)
	}
	
	
	this.SetSliderPixels = function(y){
		if (y < 2) y = 2
		if (y > 72+this.MarkerMarge) y = 72+this.MarkerMarge
	    this.SliderPx = y
		document.getElementById('Slider').style.top = y + 'px'
	}


	this.SetSliderZoomlevel = function(z){
		this.SliderPx = 72+this.MarkerMarge - (z-7) * 7
		document.getElementById('Slider').style.top = this.SliderPx + 'px'
	}
	
	
	this.ZoomEnd = function(){
		this.onZoom()
		if (window.Markers) Markers.Refresh()
		if (window.Banner) Banner.AfterZoom()
		if (window.GeoData){
    		center = GoogleMap.getCenter()
		    GeoData.Set(center.lng(), center.lat(), GoogleMap.getZoom())
		}
		if (GoogleMap.getZoom() <= 6) this.ZoomIn()
		document.getElementById('Kaart_Z').value = GoogleMap.getZoom()
	}
	
	
	this.MoveEnd = function(){
		if (window.Markers) Markers.Refresh()
		if (window.Banner) Banner.AfterMove()
   		center = GoogleMap.getCenter()
		if (window.GeoData){
		    GeoData.Set(center.lng(), center.lat(), GoogleMap.getZoom())
		}
		document.getElementById('Kaart_X').value = center.lng()
		document.getElementById('Kaart_Y').value = center.lat()
	}


	this.onZoom = function(){
		z = GoogleMap.getZoom()
		this.SetSliderZoomlevel(z)
	}


	this.ZoomIn = function(){
		z = GoogleMap.getZoom()
		if (z >= 19) return
		GoogleMap.zoomIn()
	}


	this.ZoomOut = function(){
		z = GoogleMap.getZoom()
		if (z <= 7) return
		GoogleMap.zoomOut()
	}
	
	
	this.ClickCenter = function(){
	   // GoogleMap.setCenter(new GLatLng(Settings.y, Settings.x), Settings.z)
	    GoogleMap.setCenter(new GLatLng(Yas, Xas), Zas)
	}


	this.wheelZoom = function(event){
		if (event.detail){ // Firefox
			if (event.detail < 0){
				this.ZoomIn()
			}
			else if (event.detail > 0){
				this.ZoomOut()
			}
		}
		else if (event.wheelDelta){ // IE
			if (event.wheelDelta > 0){
				this.ZoomIn()
			}
			else if (event.wheelDelta < 0){
				this.ZoomOut()
			}
		}
	}
	
	
}


function StopSlide(){
    Control.StopSlide()
}



/* --- on...-functies --- */

window.onload = function(){
	getCoordinates(address);
};

window.onunload = GUnload;
document.onmouseup = StopSlide