$(document).ready(function() {
    
    $(".load-venues-link").click(function(e) {
            e.preventDefault();
            load_venues( $(this).attr('href') );
    });
      
    $(".wheelchair-filter-checkbox").click( update_filter );
    
    $("[rel='tooltip']").tooltip();
    
    $('#loadmorevenues-button').click(function(){ 
        load_venues( $(this).data("current-url"), $(this).data("next-page") );
    });
    
});

var load_venues = function(url, page) {
    if ( typeof page == "undefined" ) 
        page = 0

    // For the first page, clear the screen
    if ( page == 0 )
        $('#venues').html("")
        
    $load_div = $("<div>Loading venues from foursquare... <br/><img alt='Loading' src='/static/img/ajax-loader-big.gif'/><hr class='soften'></div>");
    
    $('#venues').append($load_div);
        
    $.ajax({
        url: "/foursquare/venues/" + url + "/" + page,
        success: function( html ) {
            $('#venues').append(html);
            $('#loadmorevenues').show();
            $('#loadmorevenues-button').data("next-page", ++page);
            $('#loadmorevenues-button').data("current-url", url);
            load_wheelmap_info();
        },
        error: function() {
            $('#venues').append("<p>There was a problem. We couldn't reach foursquare, sorry!</p>");
        },
        complete: function() {
            $load_div.remove();
        }
    });
}

var load_wheelmap_info = function() {
    $.each( $('div#venues>div.venue'), function(index, div) {
       
        // Load Wheelmap Node
        $.ajax({
        dataType: "json",
        url: "/wheelmap/nodes",
        data: {
            lat: $(div).data('lat'),
            lng: $(div).data('lng'),
            name: $(div).data('name')
        },
        success: function( r ) {
            if ( r.wheelmap ) {
                $(div).addClass("wheelchair-" + r.wheelchair);
                $(div).find('.nodeheadline').html(r.name);
                $(div).find('.wheelmapinfo>p').html("<a href='/static/img/" + r.wheelmap_id + "'>Wheelmap</a><br/>Wheelchair: " + r.wheelchair + "<br>Description: " + r.wheelchair_description);
                $(div).find('.map img.mapmarker').attr("src", "/static/img/" + r.wheelchair + ".png");
            } else {
                $(div).addClass("wheelchair-notfound");
                $(div).find('.nodeheadline').html("Not found on wheelmap");
                $(div).find('.wheelmapinfo>p').html("Look for it yourself on <a href='http://wheelmap.org/en/?lat="+$(div).data('lat')+"&lon="+$(div).data('lng')+"&zoom=17'>wheelmap</a>");
                $(div).find('.map img.mapmarker').attr("src", "/static/img/notfound.png");
            }
            // Hide the ones, that are not wanted
            update_filter();
        },
        error: function() {
            $(div).find('.nodeheadline').html("Error: There was a problem contacting wheelmap.");
        }
        });  
    });
};

var update_filter = function () {
    // Function for filtering the results by wheelchair status
    
    $(".wheelchair-filter-checkbox").each(function() {
        wheelchair_status = $(this).data("wheelchair")
        if ( $(this).is(":checked") ) {
            $(".wheelchair-" + wheelchair_status).show();
        } else {
            $(".wheelchair-" + wheelchair_status).hide();
        }
    });
}



@@ -2015,27 +2015,44 @@
 a href='
-/static/img
+http://wheelmap.org/en/nodes
 /%22 + r.w
@@ -2116,16 +2116,70 @@
 hair + %22
+ %3Ca class='edit-wheelchair-status' href='#'%3E%5BEdit%5D%3C/a%3E
 %3Cbr%3EDesc
@@ -2843,24 +2843,57 @@
 e_filter();%0A
+            add_edit_popovers();%0A
         %7D,%0A 
@@ -3459,9 +3459,1094 @@
  %7D);%0A%7D%0A%0A
+var add_edit_popovers = function() %7B%0A    html = %22%3Cform class='form-horizontal'%3E%3Cdiv class='control-group'%3E%22;%0A    html += %22%3Clabel class='radio'%3E%3Cinput type='radio' name='weelchair-status-change' value='yes' checked%3Ewheelchair accessible%3C/label%3E%22;%0A    html += %22%3Clabel class='radio'%3E%3Cinput type='radio' name='weelchair-status-change' value='limited'%3Epartly wheelchair accessible%3C/label%3E%22;%0A    html += %22%3Clabel class='radio'%3E%3Cinput type='radio' name='weelchair-status-change' value='no'%3Enot wheelchair accessible%3C/label%3E%22;%0A    html += %22%3Clabel class='radio'%3E%3Cinput type='radio' name='weelchair-status-change' value='unknown'%3Eunknown status%3C/label%3E%22;%0A    html += %22%3C/div%3E%3C/form%3E%22;%0A    html += %22%3Cbutton class='btn cancel'%3ECancel%3C/button%3E %3Cbutton class='btn btn-primary'%3EUpdate%3C/button%3E%22%0A    %0A        %0A    $(%22.edit-wheelchair-status%22).each(function()%7B%0A        $this = $(this)%0A        $(this).popover(%7Bhtml: true, title: %22Wheelchair accessible?%22, content: html%7D);%0A        $(this).click(function(e)%7B %0A            e.preventDefault();%0A            $(this).popover(%22show%22); %0A        %7D);%0A    %7D);%0A    %0A%7D
 %0A

Correct Wheelmap link