var arrMarkers=new Array();

function getMarkerData(params)
	{

	var poiurl='/php/poidata.php';
 
 $.ajax({
	 url:poiurl,
	 type: "get",
	 data: params,
	 dataType: "json",
	 error: function(xhr, desc, exceptionobj) {
		 alert("There was a problem loading the map data. Please try again later.");
	 },
	 success:function(json)
	 { 
			 //now we have an array of poi
			$.each(json.poi, function(i,poiItem)
			{
	
				var tmpAddress='';
				tmpAddress=addAddressLine(poiItem.strAddress1) + addAddressLine(poiItem.strTown) + isEmpty(poiItem.strPostCode);
					var imageThumb=isEmpty(poiItem.strExtImageURLTh);
					
				if(imageThumb==null||imageThumb=="") {imageThumb=isEmpty(poiItem.strImageThumb)};
				if(poiItem.strCategory!='Cottage' && imageThumb!="") {imageThumb="/hotels/images/"+ poiItem.lngpoiID + "/" + imageThumb};
				arrMarkers.push([poiItem.strCategory,poiItem.decLat,poiItem.decLng,poiItem.strName,tmpAddress,poiItem.strTelephone,poiItem.strBookingURL,poiItem.lngpoiID,imageThumb]);
			
			});
	
			 addMarkersToMap();
	 }
 });
		
	}//end get markerdata
	
	
	function addMarkersToMap() {
	for (i=0;i<arrMarkers.length;i++)
		{
	var html="<div class='iw-container'>";
		
		 if(arrMarkers[i][8]!="") {
			 
			 html+="<div class='iw-img'>";
			 if(arrMarkers[i][6]!=''&&arrMarkers[i][6]!=null)
			 {
					 html+="<a href='" + getSeoUrl(arrMarkers[i][3],arrMarkers[i][7],arrMarkers[i][0],arrMarkers[i][6]) + "'>";
			 }
				 html+="<img src='" + arrMarkers[i][8] + "' alt='"+ arrMarkers[i][3] +"' width='108' height='80'/>";
			  if(arrMarkers[i][6]!=''&&arrMarkers[i][6]!=null)
			 {
				 html+="</a>";
			 }
			 html+="</div>"}
		 
		 html+="<p><strong>" + arrMarkers[i][3] + "</strong></p>"

		html+="<p>" + arrMarkers[i][4];
		if(arrMarkers[i][5]!=''&&arrMarkers[i][5]!=null)
		{
			html+= "<br>Tel: " + arrMarkers[i][5];
		}
		html+= "</p>";
		if(arrMarkers[i][6]!=''&&arrMarkers[i][6]!=null)
		{
				html+="<p><a href='" + getSeoUrl(arrMarkers[i][3],arrMarkers[i][7],arrMarkers[i][0],arrMarkers[i][6]) + "'>More info and book online</a></p>";
		}
		else {
			 if (arrMarkers[i][0]=='Camping')
			{
				html+="<p><a href='campsites.htm#" + arrMarkers[i][0] + arrMarkers[i][7] + "'>More details...</a></p>";
			}
			else
			{
				html+="<p><a href='" + getSeoUrl(arrMarkers[i][3],arrMarkers[i][7],arrMarkers[i][0],arrMarkers[i][6]) + "'>More details...</a></p>";
			}						 
		}
		html+='</div>';
		var point=new google.maps.LatLng(arrMarkers[i][1], arrMarkers[i][2]);
		
	  var marker = new google.maps.Marker({ 
        position: point, 
        map: abermap, 
        title: arrMarkers[i][3], 
        content: html 
                //, zIndex: beach[3] 
    });   
        
        var infowindow = new google.maps.InfoWindow({   
                content: ""
        }); 
        
        google.maps.event.addListener(marker, 'click', function() {  
                infowindow.setContent(this.content); 
                infowindow.setPosition(this.getPosition()); 
                infowindow.open(abermap, this);   
        });  
		} //end for loop
		} //end add markers
		
		
function getSeoUrl(poiname,poiid,poitype,poibookingurl)
{
	var seourl='';
	if(poibookingurl!=''&&poibookingurl!=null)
	{
		seourl=poiname.replace(/\s+/g,"-");
		seourl=seourl.toLowerCase()+"-"+poiid;
		if(poitype.toLowerCase()=='hotel')
		{
			seourl='/hotels/'+seourl+'.htm';
		}
		else if (poitype.toLowerCase()=='guesthouse')
		{
			seourl='/guesthouse/'+seourl+'.htm';
		}
		else if (poitype.toLowerCase()=='cottage')
		{
			seourl='/cottages/'+seourl+'.htm';
	    }
		return seourl;
	}
	else if (poitype.toLowerCase()=='hotel')
	{
		seourl='/hotels-abergavenny.htm#Hotel'+poiid;
		return seourl;
	}
	else if (poitype.toLowerCase()=='guesthouse')
	{
		seourl='/guesthouses.htm#Guesthouse'+poiid;
		return seourl;
	}
	return "";
}
