(function() {
	'use strict';

	function initMap(config) {
		var element = document.getElementById(config.mapId);
		if (!element || !window.google || !window.google.maps) {
			return;
		}

		var map = new window.google.maps.Map(element, {
			zoom: config.zoom > 0 ? config.zoom : 0,
			mapTypeId: window.google.maps.MapTypeId[config.mapStyle] || window.google.maps.MapTypeId.ROADMAP,
			scrollwheel: config.scrollable,
			draggable: config.draggable
		});
		var bounds = new window.google.maps.LatLngBounds();
		config.markers.forEach(function(item) {
			var position = new window.google.maps.LatLng(item.lat, item.lng);
			var marker = new window.google.maps.Marker({position: position, map: map, title: item.title});
			bounds.extend(position);
			if (item.url) {
				marker.addListener('click', function() { window.location.href = item.url; });
			}
		});
		if (config.markers.length > 1) {
			map.fitBounds(bounds);
		} else if (1 === config.markers.length) {
			map.setCenter(new window.google.maps.LatLng(config.markers[0].lat, config.markers[0].lng));
			if (config.zoom > 0) {
				map.setZoom(config.zoom);
			}
		}
	}

	(window.seovaultseoLocalMaps || []).forEach(initMap);
}());
