/* 
 * Javascript functions to use in conjunction with attractions DB
 */

/**
 * Marks nearest attractions as markers on the map object passed in.
 *
 * @parameter map The google map object
 * @parameter point The google latlong value for the marker
 * @parameter text The string of text which will appear in the bubble
 */
function createMarker(map, point, text){
    var marker = new GMarker(point);

    GEvent.addListener(marker, 'click', function(){
        map.openInfoWindowHtml(point, text);
    });

    return marker;
}

/**
 * Marks nearest attractions as markers on the map object passed in.
 *
 * @dependencies jQuery
 * @parameter map The google map object
 * @parameter limit The limit to the number of attractions returned, null if no limit desired.
 */
function setMarkers(map, lat, lon, radius, limit)
{
    //Do ajax call to get attractions data for markers
    $.getJSON( '/attraction/ajaxCalls.php', {action: 'getNearestAttractions', lat: lat, lon: lon, radius: radius, limit: limit}, function(data){
        for( var i = 0; i < data.length; i++ ){
            var point = new GLatLng(data[i].latitude, data[i].longitude);
            var text = '<div style="width: 210px"><b>'+data[i].name+'</b><br/>'+data[i].shortcopy+'</div>';
            map.addOverlay(createMarker(map, point, text));
        }
    });
}


