// setup for smith maps

var Map = new Map();
//var MapControl = new MapControl(Map);
Map.loadOnMove = false;
//Map.getLocationUrl = '/get_map_location.php';
Map.iconPath = '/images/map';

function createIcon(image)
{
	var icon = new GIcon();
	icon.image = Map.iconPath + '/' + image;
	icon.iconSize = new GSize(34, 38);
	icon.iconAnchor = new GPoint(12, 34);
	icon.infoWindowAnchor = new GPoint(12, 34);
	return icon;
}

// set type icons
Map.setTypeDefault('icon', createIcon('caviste.png'));
Map.setTypeValue('Restaurant', 'icon', createIcon('restaurant.png'));
Map.setTypeValue('Wine Bar', 'icon', createIcon('wine-bar.png'));

// set type zoom settings
Map.setTypeDefault('minZoom', 12);
Map.setTypeDefault('maxZoom', 17);

Map.setTypeValue('Hotel', 'minZoom', 10);

Map.setTypeValue('Destination', 'minZoom', 0);
Map.setTypeValue('Destination', 'maxZoom', 9);

Map.setTypeDefault('click', showOverlay);

var activeMarker = false;

//var infoTemplate = new Template('\
var infoTemplate = $.template('\
<div class="info-bg"></div>\
<div class="place">\
	<div class="image" ${image_style}>\
		<a href="${link}">${image}</a>\
	</div>\
	<div class="details">\
		<a id="close" "href="#" onclick="return closeOverlay();">close</a>\
		<h2><a href="${link}">${title}</a></h2>\
		<p>${address}</p>\
		<p>${desc}</p>\
	</div>\
</div>\
<div class="links">\
	<a class="arrow" href="${link}">more info</a>\
</div>\
');

function showOverlay(markerKey)
{
	if (activeMarker)
	{
		closeOverlay();
	}

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

	if (!activeMarker) return;

	activeMarker.hide();
	activeMarker.overlay = new InfoBox(activeMarker, 438, 193, 'map-info-box', infoTemplate, 211, -7);

	Map.setActiveKey(activeMarker.key);
	//selectTab(typeToTab(activeMarker.place.type));
	Map.getMap().addOverlay(activeMarker.overlay);
	Map.getMap().panTo(activeMarker.getPoint());
}

function closeOverlay()
{	
	
	if (activeMarker)
	{
		
		Map.getMap().removeOverlay(activeMarker.overlay);
		activeMarker.show();
		
		if (link = $($(activeMarker.place.key + '-link')))
		{
			link.removeClass('active');
		}
	}
	Map.setActiveKey(false);
	activeMarker = false;
	return false;
}


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




