markers = new Array();
infowindows = new Array();
var infowindow = new google.maps.InfoWindow();
$(function(){
	initialize();
})
function initialize()
{
	var latitude = document.getElementById('centerLat').value;
	var longitude = document.getElementById('centerLon').value;
	
	//var urlParameter = document.getElementById('urlParameters').value;

	var latLng = new google.maps.LatLng(latitude,longitude);
	
	var options = {
		zoom:12,
		zoomControl:true,
		mapTypeControl: true,
		mapTypeControlOptions: {
		style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
		},
		center: latLng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	var map = new google.maps.Map(document.getElementById('mapHotels'),options);

	var hotelsOnThisPage = document.getElementById('hotelsCountOnThePage').value;
	
	for(i=0; i<hotelsOnThisPage; i++)
	{
		var Id = 'hotelId_'+i;
		var lat = 'latitude_'+i;
		var lon = 'longitude_'+i;
		var hotelName = 'hotelName_'+i;
		var add = 'address_'+i;
		var pr			= 'mapPrice_'+i;	
		
		var hotelId = document.getElementById(Id).value;
		var latitude = document.getElementById(lat).value;		
		var longitude = document.getElementById(lon).value;
		var place = document.getElementById(hotelName).value;
		var address = document.getElementById(add).value;
		var mapPrice	= document.getElementById(pr).value;
		
		urlPlace = place.split(' ').join('-');	
		attachInfo(map,hotelId,latitude,longitude,place,address,urlPlace,i,'',mapPrice);
	}
	
	otherPlaces(map);
}

function attachInfo(map,hotelId,latitude,longitude,place,address,urlPlace,i)
{
	var marker = new google.maps.Marker({
		position: new google.maps.LatLng(latitude,longitude), 
		map: map,
		icon: site_url+'/assets/images/iconr'+(i+1)+'.png',
		title: place
	});
	
	var otherInfo = "<div><b><a style='padding:0px;font-size:12px;' href='"+domain+"/hotel/"+hotelId+"-"+urlPlace+"'></b></a></div><div class='address'>"+address+"</div>";
	
	google.maps.event.addListener(marker, 'click', function() {
	   infowindow.close();
	   infowindow.setContent(otherInfo);
	   infowindow.open(map,marker);
	});
	
}

function otherPlaces(map)
{
	var countSight = document.getElementById('countSight').value;
	
	for(i=0; i<countSight; i++)
	{
		var locName = 'locationName_'+i;
		var locType = 'locationType_'+i;
		var sightLat = 'sightLatitude_'+i;
		var sightLon = 'sightLongitude_'+i;
		
		var locationName = document.getElementById(locName).value;
		var locationType = document.getElementById(locType).value;		
		var sightLatitude = document.getElementById(sightLat).value;
		var sightLongitude = document.getElementById(sightLon).value;
		var zindex = -i;
		
		attachSightInfo(map,locationName,locationType,sightLatitude,sightLongitude,zindex);
	}
}

function attachSightInfo(map,locationName,locationType,sightLatitude,sightLongitude,i)
{
	var marker = new google.maps.Marker({
		position: new google.maps.LatLng(sightLatitude,sightLongitude), 
		map: map,
		icon: site_url+'/assets/images/greenBalloon.png',
		title: locationName,
		zIndex: i,
	});
	
	var otherInfo = "<div class='landmark' style='display: block;height: 20px;position: relative;width: 100px;'>"+locationType+": <b>"+locationName+"</b></div>";
	
	google.maps.event.addListener(marker, 'click', function() {
	   infowindow.close();
	   infowindow.setContent(otherInfo);
	   infowindow.open(map,marker);
	});
}
