var map;
var infoWindows = [];

function initializeMap() {
	var mapOptions = {
		zoom: zoomLevel,
		center: new google.maps.LatLng(hotels[0][1], hotels[0][2]),
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		mapTypeControl: false
	}

	map = new google.maps.Map(document.getElementById("map"), mapOptions);

	setMarkers(map, hotels);
	google.maps.event.addListener(map, 'click', function() {closeInfoWindows()});
}

function setMarkers(map, hotels) {
	var image = new google.maps.MarkerImage(
		'images/icon-marker.png',
		new google.maps.Size(25, 23),
		new google.maps.Point(0,0),
		new google.maps.Point(0, 25)
	);

	for (var i = 0; i < hotels.length; i++) {
		var hotel = hotels[i];
		var myLatLng = new google.maps.LatLng(hotel[1], hotel[2]);

		var marker = new google.maps.Marker({
			id: i,
			position: myLatLng,
			map: map,
			icon: image,
			title: hotel[0],
			zIndex: hotel[3]
		});

		google.maps.event.addListener(marker, 'click', function() {
			closeInfoWindows();

			var infoWindow = new google.maps.InfoWindow({
				content: hotels[this.id][4],
				maxWidth: 200
			});

			infoWindows.push(infoWindow);

			infoWindow.open(map,this);
		});
	}
}

function closeInfoWindows() {
	for(i=0; i<infoWindows.length; i++) {
		infoWindows[i].close();
	}
}

$(document).ready(function(){
	//initialize google map
	initializeMap();

	var infoWindow = new google.maps.InfoWindow({
		content: hotels[0][4],
		position: new google.maps.LatLng(hotels[0][1], hotels[0][2]),
		pixelOffset: new google.maps.Size(12,-23),
		maxWidth: 200
	});

	infoWindows.push(infoWindow);

	infoWindow.open(map);
});

