/**
 * This class is deprecated and may be removed in further versions. Please use the 'Map3'-class instead (Google Maps API Version 3).
 *
 * @deprecated
 */

function Map(divID, switchable) {
	this.divID = divID;
	this.initialized = false;
	this.mapInitialized = false;
	this.gmap = null;
	this.location = '';
	this.coordinates = null;
	this.switchable = switchable;
}

/**
 * Initializes the map.
 */
Map.prototype.init = function(coordinates) {
	this.initialized = true;
	
	// init on/off button
	if (this.switchable) {
		var onButton = document.getElementById(this.divID+'OnButton');
		if (onButton) {
			// show
			onButton.className = onButton.className.replace(/hidden/, '');
			// set event
			onButton.onclick = GEvent.callback(this, this.show);
		}
		var offButton = document.getElementById(this.divID+'OffButton');
		if (offButton) {
			// show
			offButton.className = onButton.className.replace(/hidden/, '');
			// set event
			offButton.onclick = GEvent.callback(this, this.hide);
		}
	}
	else {
		// show div
		document.getElementById(this.divID).className = document.getElementById(this.divID).className.replace(/hidden/, '');
		
		// init map
		this.initMap(coordinates);
	}
}

/**
 * Initializes the map.
 */
Map.prototype.initMap = function(coordinates) {
	this.mapInitialized = true;
	
	// init gmap
	this.gmap = new GMap2(document.getElementById(this.divID+'Canvas'));
	
	// set start coordinates
	this.gmap.setCenter(coordinates, GMAP_ZOOM);

	// mark coordinates
	this.gmap.addOverlay(new GMarker(coordinates));

	// set map type
	this.gmap.addMapType(G_PHYSICAL_MAP);
	if (GMAP_TYPE == 'map') this.gmap.setMapType(G_NORMAL_MAP);
	else if (GMAP_TYPE == 'satellite') this.gmap.setMapType(G_SATELLITE_MAP);
	else if (GMAP_TYPE == 'hybrid') this.gmap.setMapType(G_HYBRID_MAP);
	else if (GMAP_TYPE == 'physical') this.gmap.setMapType(G_PHYSICAL_MAP);
	
	// set options
	if (GMAP_ENABLE_DRAGGING == 1) this.gmap.enableDragging(); else this.gmap.disableDragging();
	if (GMAP_ENABLE_SCROLL_WHEEL_ZOOM == 1) this.gmap.enableScrollWheelZoom(); else this.gmap.disableScrollWheelZoom();
	if (GMAP_ENABLE_DOUBLE_CLICK_ZOOM == 1) this.gmap.enableDoubleClickZoom(); else this.gmap.disableDoubleClickZoom();
	
	// add controls
	if (GMAP_ENABLE_OVERVIEW_MAP_CONTROL == 1) this.gmap.addControl(new GOverviewMapControl());
	if (GMAP_ENABLE_SCALE_CONTROL == 1) this.gmap.addControl(new GScaleControl());
	
	// add map control
	if (GMAP_MAP_CONTROL != 'off') {
		if (GMAP_MAP_CONTROL == 'small') this.gmap.addControl(new GSmallMapControl());
		else if (GMAP_MAP_CONTROL == 'large') this.gmap.addControl(new GLargeMapControl());
		else if (GMAP_MAP_CONTROL == 'zoom') this.gmap.addControl(new GSmallZoomControl());
	}
	
	// add type control
	if (GMAP_MAPTYPE_CONTROL != 'off') {
		if (GMAP_MAPTYPE_CONTROL == 'normal') this.gmap.addControl(new GMapTypeControl());
		else if (GMAP_MAPTYPE_CONTROL == 'dropdown') this.gmap.addControl(new GMenuMapTypeControl());
		else if (GMAP_MAPTYPE_CONTROL == 'hierarchical') this.gmap.addControl(new GHierarchicalMapTypeControl());
	}
		
	// set unload function
	window.onunload = GUnload;
}


/**
 * Sets the location of the map.
 */
Map.prototype.setLocation = function(location) {
	this.location = location;
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(location, GEvent.callback(this, this.setCoordinates));
}

/**
 * Sets the coordinates of the map.
 */
Map.prototype.setCoordinates = function(coordinates) {
	if (coordinates) {
		this.coordinates = coordinates;
		
		// init map
		if (!this.initialized) {
			this.init(coordinates);
		}
		else {	
			// set coordinates
			this.gmap.setCenter(coordinates, GMAP_ZOOM);
			
			// mark coordinates
			this.gmap.addOverlay(new GMarker(coordinates));
		}
	}
}

/**
 * Shows the map.
 */
Map.prototype.show = function() {
	document.getElementById(this.divID).className = document.getElementById(this.divID).className.replace(/hidden/, '');
	
	if (!this.mapInitialized) {
		this.initMap(this.coordinates);
	}
}

/**
 * Hides the map.
 */
Map.prototype.hide = function() {
	document.getElementById(this.divID).className += ' hidden';
}
