var googleSrc;

if (location.href.substring(0,5) == "https") {
	googleSrc = "https://maps-api-ssl.google.com/maps?file=api&amp;v=2&amp;oe=utf-8&amp;client=gme-traveli&amp;sensor=false";
}
else {
	googleSrc = "http://maps.google.com/maps?file=api&amp;v=2&amp;oe=utf-8&amp;client=gme-traveli&amp;sensor=false";
}

document.write('<script type="text/javascript" language="javascript" src="' + googleSrc + '"></script>');



//**********************************************************************
// Name			: loadHotelMap
// Description	: Renders a Google Map for the hotel located at the
//				  specified coordinates inside the specified <div>.
// Input		: mapDivName - Name of the <div> section where the map
//							   should be placed
//				  hotelCoordinates - Comma-separated string containing
//									 the latitude and longitude of the
//									 hotel for which a map is to be
//									 rendered
//				  width - If specified, the width of the map; height must
//						  also be provided or this value will be ignored.
//				  height - If specified, the height of the map; width must
//						   also be provided or this value will be ignored
// Output		: N/A
//**********************************************************************
function loadHotelMap(mapDivName, hotelCoordinates, width, height) {
	if (hotelCoordinates != null && GBrowserIsCompatible()) {
		var coordinates = hotelCoordinates.split(",");
		var lat = parseFloat(coordinates[0]);
		var lng = parseFloat(coordinates[1]);
		var	point = new GLatLng(lat,lng);

		var map = null;
		if (width != null && height != null) {
			map = new GMap2(document.getElementById(mapDivName), {size:new GSize(width,height)});
		}
		else {
			map = new GMap2(document.getElementById(mapDivName));
		}
		map.setCenter(point, 11);
		map.setMapType(G_HYBRID_MAP);
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
		map.addControl(new GSmallMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.addOverlay(new GMarker(point));
	}
}

/**
 * Loads google map & marks all hotels in the map.
 * Also set marker bubbles for all hotels.<br><br>
 * Note: The function uses mapiconmaker.js<br>
 * Please make sure the js is included.
 *
 * @param string mapBox: ID of 'div' element that holds the map
 * @param string destCode: Destination code
 * @return
 */
function loadGMap( mapBox, destCode ) {

	destCode = destCode.toLowerCase();
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById(mapBox));
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
		map.addControl(new GSmallMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(0,0), 13);

		var baseIcon = new GIcon();
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);

		function sortOrder(marker, b) {
			return (100 - marker.importance);
		}

		function createMarker (point, code, name, number) {
			var iconOptions = {};
			iconOptions.primaryColor = "#ff776b";
			iconOptions.strokeColor = "#202020";
			iconOptions.label = number+"";
			iconOptions.labelColor = "#000000";
			iconOptions.addStar = false;
			var icon = MapIconMaker.createLabeledMarkerIcon(iconOptions);
			var marker = new GMarker(point, {icon:icon, title:name, zIndexProcess:sortOrder});
			marker.importance = number;
			GEvent.addListener(marker, "click", function() {
				var linkhtml = '<a target="_parent" hr' + 'ef=\'javascript:goToHotelInfo("'+code.toUpperCase()+'","'+destCode.toUpperCase()+'")\' class="style31">';
				var endlinkhtml = '</a>';
				var imghtml = '<div style="width:109px;height:100px;"><' + 'img border="0" width="109" height="100" '
							+ 'src="/images/hotel/' + destCode + '/' + destCode + '_' + code + '_tn.jpg" '
							+ 'onError="this.src=\'/images/layout/mt.gif\'"'
							+ 'style="border: 1px solid #006699;"></div>';
				var linktexthtml = 'View Hotel Details';

				var html = '<div class="giw"><div '
							+ 'class="giw-label bubbletop" style="padding: 0 0 4px 0;">'
							+ linkhtml + '<b>'+name+'</b>' + endlinkhtml
							+ '</div><div class="giw-img bubblecontent" style="padding: 0 0 4px 0;">'
							+ linkhtml + imghtml + endlinkhtml
							+ '</div><div class="giw-detail bubblebottom">'
							+ linkhtml + linktexthtml + endlinkhtml
							+ '</div>';
				marker.openInfoWindowHtml(html, {maxWidth: 225});
			});
			return marker;
		}

		function setMarkers() {
			var bounds = new GLatLngBounds();
			var hObj = null;
			for( var i = 0; i < hotelMapData.length; i++ ) {
				hObj = hotelMapData[i];
				var code = hObj.code;
				var name = hObj.name;
				var lat = hObj.latitude;
				var lng = hObj.longitude;
				if( lat != 0 && lng != 0){
					var point = new GLatLng(lat,lng);
					var marker = createMarker(point, code.toLowerCase(), name, (i+1));
					map.addOverlay(marker);
					bounds.extend(point);
					map.setCenter(point, 13);
				}
			}
			map.setZoom(map.getBoundsZoomLevel(bounds));
			map.setCenter(bounds.getCenter());
		}
		setMarkers();
	}
}

function GUnload() {
};


window.onunload = GUnload;