function filter_properties() {
    properties = $('.property')
    properties.hide();
    $('#filters input:checked').each(function(i) {
        properties = properties.filter('.'+this.id);
    });
    if (!$('#capacity #sleeps1-4').attr('checked')) {
        properties = properties.not('.capacity_1').not('.capacity_2').not('.capacity_3').not('.capacity_4');
    }
    if (!$('#capacity #sleeps5-6').attr('checked')) {
        properties = properties.not('.capacity_5').not('.capacity_6');
    }
    if (!$('#capacity #sleeps7-8').attr('checked')) {
        properties = properties.not('.capacity_7').not('.capacity_8');
    }
    if (!$('#capacity #sleeps9-10').attr('checked')) {
        properties = properties.not('.capacity_9').not('.capacity_10');
    }
    if (!$('#capacity #sleeps11plus').attr('checked')) {
        properties = properties.not('.capacity_11plus');
    }
    if (properties.length==0) {
        $('#propertylist-caption').text('Sorry. No properties match your criteria.')
    } else {
        $('#propertylist-caption').text('The following '+((properties.length==1)?' property matched':properties.length+' properties match')+' your criteria:')
    }
    properties.each(function(i) {
        if (i%3==0) {
            $(this).addClass('left').removeClass('middle').removeClass('right').show();
        } else if (i%3==1) {
            $(this).removeClass('left').addClass('middle').removeClass('right').show();
        } else if (i%3==2) {
            $(this).removeClass('left').removeClass('middle').addClass('right').show();
        }
    })
}

$(document).ready(function() {
    $("#usefulLinks input").change(function() {
        filter_properties();
    });
    $("#capacity-reset").click(function() {
        $('#capacity input').attr({'checked':true});
        filter_properties();
        return false;
    });
    $("#filters-reset").click(function() {
        $('#filters input').attr({'checked':false});
        filter_properties();
        return false;
    });
});