var Map = new Map();	
Map.getPlacesUrl = '/get_map_countries.php';
Map.getLocationUrl = '/get_map_location.php';
Map.iconPath = '/images/mms-maps/icons';

Map.lat = 30;
Map.lng = 0;
Map.zoom = 1;
Map.showTabs = false;
Map.reloadOnMove = false;

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

Map.setTypeDefault('icon', icon);
Map.setTypeDefault('minZoom', 0);
Map.setTypeDefault('maxZoom', 17);
Map.setTypeDefault('click', showOverlay);

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><a href="#{country_link}">#{name}</a></h2>\
		<ul>#{cities}</ul>\
	</div>\
</div>\
');



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

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

	activeMarker.overlay = new InfoBox(activeMarker, 375, 187, 'map-info-box small country', infoTemplate, 173, -6);

	Map.setActiveKey(activeMarker.key);

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

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


window.onload = function() {
	Map.load();
	Map.getMap().addControl(new GSmallZoomControl()); 
	populate_quick_links();
	GEvent.addListener(Map.getMap(), "zoomend", closeOverlay);
}

window.onunload = function() {
	GUnload()
}
