﻿// JavaScript Document



var panPercentage = 0.5;


function zoomIn() {
map.setZoom(map.getZoom() + 1);
}



function zoomOut() {
map.setZoom(map.getZoom() - 1);
}


function setMapType(mapType) {
	map.setMapType(mapType);
}

function aroundTheWorldLngSpan(NE,SW) {
	if (SW > NE) {
		NE = NE + 360;			
	}
	return Math.abs(NE - SW);
}	


function aroundTheWorldLngPan(lng) {
	if (lng < -180) {
		lng = lng + 360;			
	}
	else if (lng > 180) {
		lng = lng - 360;
	}
	return lng;
}	


function limitNS(lat) {
	if (lat > 85) {
		lat = 85;
	}
	else if (lat < -85) {
		lat = -85;
	}
	return lat;
}


function lngSpan() {
	var bounds = map.getBounds(); // the boundary coordinates for the current view
	var southWest = bounds.getSouthWest(); // the South-West corner of the boundary
	var northEast = bounds.getNorthEast(); // the North-East corner of the boundary
	return aroundTheWorldLngSpan(northEast.lng(), southWest.lng());
}

function latSpan() {
	var bounds = map.getBounds(); // the boundary coordinates for the current view
	var southWest = bounds.getSouthWest(); // the South-West corner of the boundary
	var northEast = bounds.getNorthEast(); // the North-East corner of the boundary
	return Math.abs(northEast.lat() - southWest.lat());		
}

function panWest () {
	map.panTo(new GLatLng(map.getCenter().lat(), aroundTheWorldLngPan(map.getCenter().lng() - (lngSpan() * panPercentage))));
}

function panEast () {
	map.panTo(new GLatLng(map.getCenter().lat(), aroundTheWorldLngPan(map.getCenter().lng() + (lngSpan() * panPercentage))));
}

function panNorth () {
	map.panTo(new GLatLng(limitNS(map.getCenter().lat() + (latSpan() * panPercentage)), map.getCenter().lng()));
}

function panSouth () {
	map.panTo(new GLatLng(limitNS(map.getCenter().lat() - (latSpan() * panPercentage)), map.getCenter().lng()));
}


function fademaptools()
{
	var algo = document.getElementById( "algo" );
	algo.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
}
function unfademaptools()
{
	var algo = document.getElementById( "algo" );
	algo.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
}


     
      // == Some global variables ==
      var YSLIDERLENGTH = 55;       // maximum length that the knob can move (slide height minus knob height)
      var MAXZOOM = 19

      // == Create a Custom GControl ==
      function YSliderControl() { }
      YSliderControl.prototype = new GControl();

      // == This function positions the slider to match the specified zoom level ==
      YSliderControl.prototype.setSlider = function(zoom) {
        var top = Math.round((YSLIDERLENGTH-YSLIDERLENGTH/MAXZOOM*zoom));
        this.slide.top = top;
        this.knob.style.top = top+"px";
        //GLog.write("Map was zoomed to:"+zoom+" new Knob position:"+top);
      }

      // == This function reads the slider and sets the zoom level ==
      YSliderControl.prototype.setZoom = function() {
        var z=Math.round(this.slide.top*MAXZOOM/YSLIDERLENGTH);
        this.map.setZoom(MAXZOOM-z);
        //GLog.write("New knob position:"+this.slide.top+" new zoom: "+z);
      }

      // == This gets called bu the API when addControl(new YSlider()) is used ==
      YSliderControl.prototype.initialize = function(map) {
        // obtain Function Closure on a reference to "this"
        var that=this;
        // store a reference to the map so that we can call setZoom() on it
        this.map = map;

        // create the background graphic as a <div> containing an image
        var container = document.getElementById("pugwash");
        container.style.width="19px";
        container.style.height="74px";
        container.innerHTML='<div style="position:relative; width: 19px;"><img id="slide" class="noborder"  src="http://www.fuerteventura.com/maps/yslide3.gif"></div>';

        // create the knob as a GDraggableObject
        this.knob = document.createElement("img"); 
		this.knob.style.left ="0px";
		this.knob.style.border ="0px";
		this.knob.id = "ball";		
        this.knob.src = "http://www.fuerteventura.com/maps/yknob3.gif";
        container.appendChild(this.knob);
        this.slide=new GDraggableObject(this.knob, {container:container});

        // attach the control to the map
      

        // Listen for other things changing the zoom level and move the slider
		that.setSlider(thismapzoom);
        GEvent.addListener(map, "zoomend", function(a,b) {that.setSlider(b)});

        // Listen for the slider being moved and set the zoom level
        GEvent.addListener(this.slide, "dragend", function() {that.setZoom()});

        return container;
      }

      // == Set the default position for the control ==

