// JavaScript Document
/* Google map customization */
var color = [ { "stylers": [ { "saturation": -100 } ] },{ "featureType": "landscape", "stylers": [ { "lightness": -92 } ] },{ "featureType": "water", "stylers": [ { "lightness": -83 } ] },{ "featureType": "road", "stylers": [ { "lightness": -69 } ] },{ "featureType": "poi", "stylers": [ { "lightness": -81 } ] },{ "featureType": "water", "elementType": "labels.text", "stylers": [ { "lightness": 25 } ] },{ "elementType": "labels.text.stroke", "stylers": [ { "color": "#000" } ] },{ "elementType": "labels.text.fill", "stylers": [ { "color": "#949494" } ] },{ "featureType": "transit", "stylers": [ { "lightness": -75 } ] } ];

var googleMap = document.getElementById('googleMap');

var marker_position = new google.maps.LatLng(45.208724,19.844884);
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();

function calcRoute() {
  var start = new google.maps.LatLng(44.810378,20.431448);
  var end = new google.maps.LatLng(45.208724,19.844884);
  var request = {
      origin:start,
      destination:end,
      travelMode: google.maps.TravelMode.DRIVING
  };
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
}

function bindInfoWindow(marker, map, infoWindow, html) {
	google.maps.event.addListener(marker, 'click', function() {
		infoWindow.setContent(html);
		infoWindow.open(map, marker);
	});
}

function initialize() {
	var	polylineOptionsActual = new google.maps.Polyline({
			strokeColor: '#fff',
			strokeWeight: 5
	}),
	rendererOptions = {
		suppressMarkers: true,
    polylineOptions: polylineOptionsActual
	};
	
  directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
	
	var center_map = new google.maps.LatLng(45.202058,19.847059);
	var map_options = {
		center: center_map,
		zoom: 13,
		scrollwheel: false,
		disableDefaultUI: true,
		mapTypeControl: false,
		scaleControl: true,
		zoomControl: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	var map = new google.maps.Map(googleMap, map_options);
	map.setOptions({styles: color});
	
	var marker = new google.maps.Marker({
			position: marker_position,
			map: map,
			title:"Digital Night | Club Reset",
			icon : "http://homepage.rs/digitalnight/images/googlemap-icon.png"
	});
	
	var infoWindow = new google.maps.InfoWindow({maxWidth: 300});
	var tekst_info = "<h4 style='width:260px; margin-bottom:5px'>Digital Night | Club Reset</h4><p>Dr Ketrin Mekfeil 1<br>21208 Sremska Kamenica, Srbija</p>";
	bindInfoWindow(marker, map, infoWindow, tekst_info);

  directionsDisplay.setMap(map);
	calcRoute();
}


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

