﻿

function ClassControl()
{
    this.Initialize = function(obj)
    {
        this.Areal = false
    	this.CurrentLink = false
        this.MarkerMarge = 0
        this.toggleControls = true;
        this.Map = obj;
        this.onZoom();
    }
	
	this.PrintMap = function()
	{
	    window.print()
	}

	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(hl, type)
	{
	    document.getElementById("TabHYBRID").style.fontWeight = "";
	    document.getElementById("TabSATELLITE").style.fontWeight = "";
	    document.getElementById("TabNORMAL").style.fontWeight = "";
	    hl.style.fontWeight = "bold";
	
		if (type == 'NORMAL')
		{
		    this.Areal = false;
		    this.MarkerMarge = 0;
		    document.getElementById('ControlDiv').className = 'Control';
		    document.getElementById('ControlDiv').style.height = 195;
		}
		else
		{
		    this.Areal = true;
		    this.MarkerMarge = 14;
		    document.getElementById('ControlDiv').className = 'ControlAreal';
		    document.getElementById('ControlDiv').style.height = 204;
		}
		this.onZoom()
	    this.Map.setMapType(eval('G_' + type + '_MAP'))
	    this.Map.checkResize();
	}
	
	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) / 5)
		this.Map.setZoom(z)
	}
	
	this.ClickSlider = function(event, obj)
	{
        y = 4 - this.MarkerMarge
        if (event.offsetY) {
		    y = event.offsetY - y
		} else {
		    y = (event.layerY) - y
		}
		if (y < 2 - this.MarkerMarge) y = 2 - this.MarkerMarge
		if (y > 72) y = 72
		this.SetSliderPixels(y)
		z = 17 - Math.round((y - 3) / 5)
		this.Map.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-3) * 5
		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 = mapGMapControl.getCenter()
		    GeoData.Set(center.lng(), center.lat(), this.Map.getZoom())
		}
		if (this.Map.getZoom() <= 2) this.ZoomIn()
	}

	this.onZoom = function()
	{
		z = this.Map.getZoom()
		this.SetSliderZoomlevel(z)
	}

	this.ZoomIn = function()
	{
		z = this.Map.getZoom()
		if (z >= 20) return
		this.Map.zoomIn()
	}

	this.ZoomOut = function()
	{
		z = this.Map.getZoom()
		if (z <= 2) return
		this.Map.zoomOut()
	}
	
	this.ClickCenter = function()
	{
       this.Map.returnToSavedPosition();
//	   if (mapGMapControlResponse) {
//	        mapGMapControl.setCenter(new GLatLng(mapGMapControlResponse.Lat, mapGMapControlResponse.Lng ), mapGMapControlResponse.Zoom);
//	   }
	}
	
	this.ToggleControls = function() 
	{
        if (this.toggleControls) {
            document.getElementById("KaartTypeDiv").style.display = "none";
            document.getElementById("ControlDiv").style.display = "none";
            document.getElementById("LegendaSpan").style.display = "none";
            this.toggleControls = false;
        } else {
            document.getElementById("KaartTypeDiv").style.display = "";
            document.getElementById("ControlDiv").style.display = "";
            document.getElementById("LegendaSpan").style.display = "";
            this.toggleControls = true;
        }
    }
    
    this.Route = function()
	{
	   a = document.getElementById("TextRoute").value;
	   if (a.length > 0) {
	     r = "from: " + a + routeLatLng;
         gdir.load(r, { "locale": "nl_NL" });
       }
	}
	
	
}

function StopSlide()
{
    Control.StopSlide()
}

document.onmouseup = StopSlide

