(function($){
	"use strict";

	google.maps.event.addDomListener(window, 'load', init);

	function init() {
		$('.GMap').each(setupMaps);
	}

	function setupMaps(){
		var markers = JSON.parse($(this).attr('data-settings'));
		$(this).removeAttr('data-settings');

		var mapOptions = {
			zoom: 9,
			scrollwheel: false,
			center: new google.maps.LatLng(45.271772, 19.831640),
			styles: [{"featureType":"administrative","elementType":"labels.text.fill","stylers":[{"color":"#444444"}]},{"featureType":"landscape","elementType":"all","stylers":[{"color":"#f2f2f2"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"poi","elementType":"labels.text","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"all","stylers":[{"saturation":-100},{"lightness":45}]},{"featureType":"road.highway","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road.arterial","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"all","stylers":[{"color":"#dbdbdb"},{"visibility":"on"}]}]
		},
		bounds = new google.maps.LatLngBounds(),
		map = new google.maps.Map(this, mapOptions);

		for( var i=0; i<markers.length; i++ ){
			var marker = new google.maps.Marker({
				'position': new google.maps.LatLng(
					markers[i].location.lat,
					markers[i].location.lng
				),
				'map': map,
				'title': markers[i].location.address,
				'icon': markers[i].icon
			});

			bounds.extend(marker.getPosition());
		}

		map.fitBounds(bounds);
	}
})(jQuery);