$(document).ready(function() {
    $('a[rel*=facebox]').facebox();

});

$(document).bind("afterReveal.facebox", function(){
	
	latitude = $('#centerLat').val();
	longitude = $('#centerLon').val();
	
	urlParameter = $('#urlParameters').val();

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

	hotelsOnThisPage = $('#hotelsCountOnThePage').val();

	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,urlParameter,mapPrice);

	}
	
	otherPlaces(map);
	
});

function attachInfo(map,hotelId,latitude,longitude,place,address,urlPlace,i,urlParameter,mapPrice)
{
	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 showPrice;
	showPrice = '';
	
	if(mapPrice)
		showPrice = mapPrice;

	var otherInfo = "<div style='width:250px; height:100px;'><div><b><a style='padding:0px; padding-bottom:5px; font-size:14px;line-height:18px;' href='"+domain+"/hotel/"+hotelId+"-"+urlPlace+"|"+urlParameter+"' >"+place+"</b></a></div><br><div class='address' style='font-size:12px;line-height:20px;'><strong>Address:</strong> "+address+"<br/><strong>Prices From:</strong> "+showPrice+" per night</div></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;font-size: 1em;height: 50px;position: relative;width: 150px;'><b>"+locationType+":</b> "+locationName+"</div>";
	
	google.maps.event.addListener(marker, 'click', function() {
	   infowindow.close();
	   infowindow.setContent(otherInfo);
	   infowindow.open(map,marker);
	});
}
