
$(document).ready(function() {
	var radius = 20;
	var coords = [];
	var offset = [$('#map').offset().left, $('#map').position().top];

	$('#map .hilite').each(function() {
		var x = parseInt($(this).css('left')) + $(this).width() / 2;
		var y = parseInt($(this).css('top')) + $(this).height() / 2;
		coords.push([x - radius, y - radius, x + radius, y + radius]);
	});

	$('#map').mousemove(function(e) {
		var x = e.pageX - offset[0];
		var y = e.pageY - offset[1];
		for (var i = 0; i < coords.length; i++) {
			var c = coords[i];
			if (x > c[0] && x < c[2] &&
			    y > c[1] && y < c[3]) {
				var hilite = $('#map .hilite:nth-child(' + (i + 1) + ')').show();
				hilite.siblings().hide();
				var pid = $(hilite).attr('id').split('-')[2];
				$('#toimipiste-li-' + pid).addClass('active')
					.siblings().removeClass('active');
				return;
			}
		}
		$('.hilite', this).hide();
		$('#contact-section-map LI').removeClass('active');
	});

	$('#contact-section-map LI').hover(function() {
		$(this).addClass('active')
		var pid = $(this).attr('id').split('-')[2];
		$('#toimipiste-hilite-' + pid).show();
	}, function() {
		$(this).removeClass('active')
		$('#map .hilite').hide();
	});
});


