var searchMap = createMap();

function createMap() 
{
	
	var m = new Map();
	m.getPlacesUrl = '/search_results_new.php';
	m.getLocationUrl = '/get_map_location.php';
	m.iconPath = '/images/mms-maps/icons';
	
	m.lat = 30;
	m.lng = 0;
	m.zoom = 2;
	m.showTabs = false;
	m.reloadOnMove = false;
	m.autobound = true;
	m.setTypeDefault('icon', createIcon(m, 'mini.hotel.icon.png'));
	m.setTypeDefault('minZoom', 0);
	m.setTypeDefault('maxZoom', 17);
	m.setTypeDefault('click', showOverlay);

	return m;
}
////destination icon
//var icon = new GIcon();
//icon.image = searchMap.iconPath + '/icon.png';
//icon.iconSize = new GSize(7, 12);
//icon.iconAnchor = new GPoint(3, 12);
//icon.infoWindowAnchor = new GPoint(3, 12);

function createIcon(map, image)
{
	var icon = new GIcon();
	icon.image = map.iconPath + '/' + image;
	icon.iconSize = new GSize(18, 23);
	icon.iconAnchor = new GPoint(0, 23);
	icon.infoWindowAnchor = new GPoint(0, 23);
	return icon;
}



var activeMarker = false;

//var infoTemplate = new Template('\
//<div class="info-bg"></div>\
//<div class="info-main">\
//	<a id="close" "href="#" onclick="return closeOverlay();">close</a>\
//	<div class="info-content">\
//		<h2>#{name}</h2>\
//		<ul>#{cities}</ul>\
//	</div>\
//</div>\
//');

var infoTemplate = new Template('\
<div class="info-bg"></div>\
<div class="info-main">\
	<a id="close" "href="#" onclick="return closeOverlay();">close</a>\
	<div class="info-image"	style="background-image: url(#{image});">\
	</div>\
	<a class="photos-link" href="#{link}gallery">more photos</a>\
	<div class="info-content">\
		<h2><a href="#{link}">#{name}</a></h2>\
		<h3>#{location}, #{country}</h3>\
		<ul>\
			<li>#{highlight_1}</li>\
			<li>#{highlight_2}</li>\
			<li>#{highlight_3}</li>\
		</ul>\
		<p>#{address}</p>\
	</div>\
	<div class="info-footer">\
		<a class="book" href="#{booking_link}">book now</a>\
		<a href="#{link}">more info</a>\
<span class="fromprice">#{doubles_from}</span>\
	</div>\
</div>\
');

function showOverlay(markerKey)
{
	if (activeMarker)
	{
		closeOverlay();
	}
	
	patt = /[a-z]+_\d+/;

	if (markerKey != null && typeof(markerKey) != 'object')
	{
		activeMarker = searchMap.getMarker(markerKey);
	}
	else
	{
		activeMarker = this;
	}
	
	if (!activeMarker) return;
	
	activeMarker.hide();
	

	activeMarker.overlay = new InfoBox(activeMarker, 517, 212, 'map-info-box', infoTemplate, 240, -4);

	searchMap.setActiveKey(activeMarker.key);

	searchMap.getMap().addOverlay(activeMarker.overlay);
	point = searchMap.getMap().fromLatLngToDivPixel(activeMarker.getPoint());
	point.y = point.y - 90;
	newCenter = searchMap.getMap().fromDivPixelToLatLng(point);
	searchMap.getMap().panTo(newCenter);
}

function closeOverlay()
{		
	if (activeMarker)
	{
		searchMap.getMap().removeOverlay(activeMarker.overlay);
		activeMarker.show();
	}
	searchMap.setActiveKey(false);
	activeMarker = false;
	return false;
}





