/**
 * D3R Ltd
 *
 * LICENSE
 *
 * This source file is subject to version 1.0 of the D3R Software
 * license, that is bundled with this package in the file LICENSE, and
 * is available through the world-wide-web at the following URL:
 * http://d3r.com/license.txt. If you did not receive
 * a copy of the D3R license and are unable to obtain it
 * through the world-wide-web, please send an email to license@d3r.com
 * so we can mail you a copy immediately.
 * @copyright   Copyright (c) 2007 D3R Ltd (http://d3r.com)
 * @license     http://d3r.com/license.txt
 */


function MapControl(map)
{
	this.minY 				= 24;
	this.maxY				= 150;
	this.map 				= map; 
	this.rangeY				= false;
	this.zoomUnit			= false;
	this.slider				= false;
	
	
	var that = this;
	
	this.load = function()
	{
		that.rangeY = that.maxY - that.minY;
		that.zoomUnit = that.rangeY / 17;
		
		var initZoom = that.map.getMap().getZoom();
				
		Element.show('zoom-pointer');
				
		that.slider = new Control.Slider('zoom-pointer','zoom-track', 
									{
										axis: 'vertical',
										onChange: that.sliderChange,
										sliderValue: initZoom,
										range:$R(17, 0),
										values: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
									}); 
		GEvent.addListener(map.getMap(), "zoomend", function() { 
		    that.updateZoom();
		});
	}
	
	
	this.returnToSaved = function()
	{
		that.map.getMap().returnToSavedPosition();
		that.updateZoom();
		return false;
	}
	
	this.panUp = function ()
	{
		that.map.getMap().panDirection(0, 1);
		return false;
	}
	
	this.panDown = function ()
	{
		that.map.getMap().panDirection(0, -1);
		return false;
	}
	
	this.panLeft = function ()
	{
		that.map.getMap().panDirection(1, 0);
		return false;
	}
	
	this.panRight = function ()
	{
		that.map.getMap().panDirection(-1, 0);
		return false;
	}
	
	
	this.zoomIn = function ()
	{
		that.map.getMap().setZoom(that.cleanZoom(that.map.getMap().getZoom() + 1))
		that.updateZoom();
		return false;
	}
	
	this.zoomOut = function ()
	{
		that.map.getMap().setZoom(that.cleanZoom(that.map.getMap().getZoom() - 1))
		that.updateZoom();
		return false;
	}
	
	this.updateZoom = function ()
	{
		that.slider.setValue(that.map.getMap().getZoom());
	}
	
	this.sliderChange = function(zoom)
	{
		that.map.getMap().setZoom(zoom);
	}
	
	this.cleanZoom = function (value)
	{
		value = Math.round(value);

		if (value < 0)
		{
			value = 0;
		}

		if (value > 17)
		{
			value = 17;
		}

		return value;
	}

	
}