var content = "<b>Hello!</b>";
var contentb = "<b>Hello B!</b>";
var bearImage = '/images/beer_icon.png';

var markers = new Object();

function mapOnload()
{
   
    var provincie = $('meta[name=provincie]').attr('value');
 
    var location = '/locatiesexport';

    if (provincie != undefined && provincie.length>0)
        location += '/'+provincie;
    
    $.getJSON(location,function(a){
        
        initMap(a);
    });

    


//var myLatLng = new google.maps.LatLng(52.2, 5.5);

}

function initMap(locations)
{
    
    var latlng = new google.maps.LatLng(52.2, 5.5);
    var zoom = 7;
    if (locations.longitude.length>0 && locations.latitude.length>0)
    {
        latlng = new google.maps.LatLng(locations.longitude, locations.latitude);
        zoom = 8;
    }
    var myOptions = {
        zoom: zoom,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


    for (var i = 0; i < locations.locaties.length; i++)
    {
        var location = locations.locaties[i];        
        createMarker(location.location_id, map, new google.maps.LatLng(location.latitude, location.longitude), location.title,location.description);
    }
    

}

function createMarker(locationId, map, latlng, label, html) {
    var contentString = '<b>'+label+'</b><br>'+html;
    var marker = new google.maps.Marker({
        icon: bearImage,
        position: latlng,
        map: map,

        title: label

    });
    markers[locationId]=marker;

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(contentString);
        infowindow.open(map,marker);
    });
    
}

var infowindow = new google.maps.InfoWindow(
{
    
});



