var map;
function initializeMap() {
	if(GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		map.size = new GSize(430,370);
		map.setMapType(G_NORMAL_MAP);
		map.setCenter(new GLatLng(latitude, longitude), 13);
		map.setUIToDefault();
		
		
		// hide tab 3 after map generated
		// bug using style=display:none on div tag
		document.getElementById("tab3").style.display = "none";
		mainHotelMarker();
		
	}
}

function mainHotelMarker() {
		// add a hotel marker
		var hotelIcon = new GIcon(G_DEFAULT_ICON);
		hotelIcon.image = imageUrl+"star.png";
		hotelIcon.iconSize = new GSize(32, 32);
		hotelMarkerOptions = { icon:hotelIcon };

		var hotel = new GLatLng(latitude, longitude);
		var hotelMarker = new GMarker(hotel, hotelMarkerOptions);
		// add event to this marker
		var tooltip = new Tooltip(hotelMarker,hotelTitle,4,hotelImage);
		hotelMarker.tooltip = tooltip;

		map.addOverlay(hotelMarker);
		map.addOverlay(tooltip);

		GEvent.addListener(hotelMarker,'mouseover',function(){
			this.tooltip.show();
		});
		GEvent.addListener(hotelMarker,'mouseout',function(){
			this.tooltip.hide();
		});
	
}

function clearMap() { 
	map.clearOverlays();
	map.setCenter(new GLatLng(latitude, longitude), 13);
	mainHotelMarker();
} 


function displayMarker(lon, lat, info, image) {
	// add a marker
	var icon = new GIcon(G_DEFAULT_ICON);
	if(image) {
		icon.image = image;
		icon.iconSize = new GSize(22, 22);
	}
	markerOptions = { icon:icon };
	var landmark = new GLatLng(lat, lon);
	var marker = new GMarker(landmark, markerOptions);
	var tooltip = new Tooltip(marker,info,4);
	marker.tooltip = tooltip;
	
	map.addOverlay(marker);
	map.addOverlay(tooltip);
	
	GEvent.addListener(marker,'mouseover',function(){
		this.tooltip.show();
	});
	GEvent.addListener(marker,'mouseout',function(){
		this.tooltip.hide();
	});

	// draw line from original point
	var polyline = new GPolyline([new GLatLng(latitude, longitude),  new GLatLng(lat, lon)], "#ff0000", 2);
	map.addOverlay(polyline);	
	
	// move map
	map.panTo(new GLatLng(lat, lon));
}

function displayHotel(lon, lat, info, image, url) {
	var point = new GLatLng(lat, lon);
	var marker = new GMarker(point);
	var tooltip = new Tooltip(marker,info,4,image,url);
	marker.tooltip = tooltip;
	
	map.addOverlay(tooltip);
	tooltip.show();
	// zoom in
	map.setZoom(16);
	// move map
	map.panTo(new GLatLng(lat, lon));
}
