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
		detailMarker 			= new GMarker(new GLatLng(Yas, Xas))
		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()
			
	}



	

	
	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