var classControl = Class.create({
	initialize: function() {
		this.currentLink = false;
		this.markerMarginPlus = 0;
		this.markerMarginMin = 0;
		$('mapControlContainer').className = (settings.mapType == 'europe' ? 'EuropeControl' : 'control');
		if (settings.mapType=='europe') {
			this.markerMarginMin = 21;
		}
	},
	clickMapType: function(event) {
		control.setMapType(event.target.id.substr(3));
	},
		// Set the map according to current tab
	setMapType: function(type) {
		$('tabNORMAL').className = '';
		$('tabSATELLITE').className = '';
		$('tabHYBRID').className = '';
		$('tab' + type).className = 'currentTab';

		this.markerMarginMin = 0;
		this.markerMarginPlus = 0;
		var newClass = 'control';

		if (type != 'NORMAL') {
			newClass = newClass + 'Aerial';
			this.markerMarginPlus = 14;
		}
		if (settings.mapType == 'europe') {
			newClass = 'Europe' + newClass;
			this.markerMarginMin = 21;
		}
		$('mapControlContainer').className = newClass;
		this.onZoom();

		googleMap.setMapType(eval('G_' + type + '_MAP'));
	},
		// Registers all movements of the map
	slide: function(event) {
		if (!this.sliding) {
			return;
		}
		y = event.clientY - this.deltaY;
		this.setSliderPixels(y);
	},
		// Do some action on start of slide
	startSlide: function(event) {
		this.deltaY = event.clientY - $('slider').offsetTop;
		this.sliding = true;
		if (event.preventDefault) {
			event.preventDefault();
		}
		event.returnValue = false;
	},
		// Change variables when slide stops
	stopSlide: function() {
		if (!this.sliding) {
			return;
		}
		this.sliding = false;
		y = this.sliderPx - this.markerMarginPlus;
		if (y < 2 - this.markerMarginPlus) {
			y = 2 - this.markerMarginPlus;
		}
		if (y > 72 + this.markerMarginMin) {
			y = 72 + this.markerMarginMin;
		}
		z = 17 - Math.round((y - 3) / 7);
		googleMap.setZoom(z);
	},
		// Change the zoom level when clicking on the scale of the zoom slider
	clickSlider: function(event) {
		standardizeEvent(event);
		y = event.layerY - 4 - this.markerMarginPlus;
		if (y < 2 - this.markerMarginPlus) {
			y = 2 - this.markerMarginPlus;
		}
		if (y > 72 + this.markerMarginMin) {
			y = 72 + this.markerMarginMin;
		}
		this.setSliderPixels(y);
		z = 17 - Math.round((y - 3) / 7);
		googleMap.setZoom(z);
	},
		// Change the y-position of the slider by pixels
	setSliderPixels: function(y) {
		if (y < 2) {
			y = 2;
		}
		if (y > 72 + this.markerMarginPlus + this.markerMarginMin) {
			y = 72 + this.markerMarginPlus + this.markerMarginMin;
		}
		this.sliderPx = y;
		$('slider').style.top = y + 'px';
	},
		// Change the y-position of the slider by zoom level
	setSliderZoomlevel: function(z) {
		if (!$('slider')) {
			return;
		}
		this.sliderPx = 72 + this.markerMarginPlus - (z-7) * 7;
		$('slider').style.top = this.sliderPx + 'px';
	},
		// After zoom, set the position variables and refresh the markers
	zoomEnd: function() {
		this.onZoom();
		if (settings.mapType == 'europe') {
			if (googleMap.getZoom() <= 3) this.zoomIn();
		} else {
			if (googleMap.getZoom() <= 6) this.zoomIn();
		}
	},
		// After movement, set the position variables and refresh the markers
	moveEnd: function() {
		if (window.markers) {
			markers.refresh();
		}
	},
		// When zooming, change the slider position and close the tooltip
	onZoom: function() {
		z = googleMap.getZoom();
		this.setSliderZoomlevel(z);
		tooltip.close();
	},
		// Control the zoomlevel when zooming in
	zoomIn: function() {
		z = googleMap.getZoom();
		if (z >= 19) {
			return;
		}
		googleMap.zoomIn();

	},
		// Control the zoomlevel when zooming out
	zoomOut: function() {
		z = googleMap.getZoom();
		if (z <= (settings.mapType == 'europe' ? 4 : 7)) {
			return;
		}
		googleMap.zoomOut();
	},
		// When clicked on the center control, move the map to the start location
	clickCenter: function() {
		googleMap.setCenter(new google.maps.LatLng(settings.y, settings.x), settings.z);
	},
		// Zoom in with the mouse wheel
	wheelZoom: function(event) {
	}
});

var control = new classControl();

function stopSlide() {
	control.stopSlide();
}

document.onmouseup = stopSlide;