var oldHotspotMarker;
var mapObj;
var remarkText = '';

function repositionCenterMarker(latLng)
{
	// Remove old hotspot marker
	if (oldHotspotMarker != null)
		mapObj.removeOverlay(oldHotspotMarker);
		
	var point = new GLatLng(latLng.lat(), latLng.lng());
	var newHotspotMarker = new GMarker(point, getIconByHotspotChargeType(isFreeArray[0]));
	
	oldHotspotMarker = newHotspotMarker;
	mapObj.addOverlay(newHotspotMarker);
}

function init() {
	
	// Create map
	var map = new GMap2(document.getElementById('map'));
	map.setCenter(new GLatLng(lonLatArray[1], lonLatArray[0]), 16);
    map.addControl(new GLargeMapControl()); 
    map.addControl(new GMapTypeControl());
	mapObj = map;

	// Create custom marker
	function createMarker(point, isFree) {
		var marker = new GMarker(point, getIconByHotspotChargeType(isFree));
		return marker;
	}
	
	// Click to reposition hotspot marker
	GEvent.addListener(map, 'click', function(overlay, latLng) {
		if (latLng) {					
			repositionCenterMarker(latLng);
			document.Form1.TextBoxLongitude.value = latLng.lng();
			document.Form1.TextBoxLatitude.value = latLng.lat();
		}
	});
	
	var point;
	if (document.Form1.TextBoxLongitude.value != '')
		point = new GLatLng(document.Form1.TextBoxLatitude.value, 
							document.Form1.TextBoxLongitude.value);
	else
		point = new GLatLng(lonLatArray[1], lonLatArray[0]);

	// Add hotspot markers
	var marker = createMarker(point, isFreeArray[0]);
	oldHotspotMarker = marker
	map.addOverlay(marker);
}

function getIconByHotspotChargeType(chargeType) {

	// Icon for unknown hotspot
	var icon = new GIcon();
	icon.iconWidth = 20;
	icon.iconHeight = 20;
	icon.iconAnchor = new GPoint(9, 9);
	icon.infoWindowAnchor = new GPoint(16, 0);
	
	switch (chargeType) {
		case '0': // For-Fee
			icon.image = 'images/ForFeeHotspot.gif';		
			break;
		case '1': // Free
			icon.image = 'images/FreeHotspot.gif';
			break;
		case '2': // FON
			icon.image = 'images/FonHotspot.gif';
			break;
		default: // Unknown
			icon.image = 'images/UnknownHotspot.gif';
			break;
	}

	return icon;
}
