$(document).ready(function() {
  $('#showErrors').click( function() {
    $('#errorData').fadeIn(600);
  });

  if($('#searchWat').length != 0) {
	  if($('#searchWat').val().length == 0) {
	  	$('#searchWat').focus();
  	} else {
	  	$('#searchWaar').focus();
  	}
  }

  if($('#googleMap').length != 0) {
	  initialize();
	}

  if($('#parsetime').length != 0) {
	  $('#parsetime').click( function(){
	  	$('#querylog').fadeIn();
  	})
	}

	if($('#fotos').length != 0) {
		var imagepath = 'http://www.regio-link.nl/images/lightbox/';
		$('#fotos a').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.8,
			containerResizeSpeed: 350,
			imageLoading: imagepath+'loading.gif',
			imageBtnClose: imagepath+'sluiten.png',
			imageBtnPrev: imagepath+'vorige.png',
			imageBtnNext: imagepath+'volgende.png',
			txtImage: 'Afbeelding',
			txtOf: 'van de'
		});
  };
});

function initialize() {
	var styleArray = [
	  {
	    featureType: "poi.business",
	    elementType: "labels",
	    stylers: [
	      { visibility: "off" }
	    ]
	  }
	];

  var mapOptions = {
    zoom: 7,
    center: new google.maps.LatLng(52.2,5.3),
    styles: styleArray,
    navigationControl: true,
    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("googleMap"), mapOptions);

  setMarkers(map,locations);
}

function addMarker(location) {
  marker = new google.maps.Marker({
    position: location,
    map: map
  });
  markersArray.push(marker);
}

// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
  }
}

// Shows any overlays currently in the array
function showOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(map);
    }
  }
}

// Deletes all markers in the array by removing references to them
function deleteOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
    markersArray.length = 0;
  }
}
