var activePop = false;
var activeLink = false;

function showMapList(_this) {
	_this = $(_this);
	var mapList = $('#map-list');
	
	activeLink = true;
	
	var clientWidth = parseInt($(document.body).width());
	var width = parseInt(mapList.width());
	
	var left = parseInt(_this.offset().left);
	if (left + width > clientWidth) {
		left = clientWidth - width - 25;
	}
	var top = parseInt(_this.offset().top) + parseInt(_this.height());
	
	mapList.css('left', left + 'px');
	mapList.css('top', top + 'px');
	
	mapList.show();
}

function hideMapList() {
	var mapList = $('#map-list');
	
	mapList.hide();
}

$(function() {
	var mapList = $('#map-list');
	
	mapList.mouseover(function() {
		activePop = true;
	});
		
	mapList.mouseout(function() {
		activePop = false;
	});
	
	$(document.body).click(function() {
		if (!activePop && !activeLink) {
			hideMapList();
		}
		
		if (activeLink) {
			activeLink = false;
		}
	});
});
