symantec.community = {};

$(document).ready(function() {
  symantec.community.setup_community_feed_filter();
});

/**
 * Sets up the behavior for the community feed content type filter
 */
symantec.community.setup_community_feed_filter = function() {
  $('.community-feed-filter').change(function() {
    var community = $(this).attr('id').split('-')[3];
    var post_data = {content_type: $(this).val(), community_id: community};
    var $destination = $('#community-feed-items-wrapper');
    $destination.html('<div class="ajax-loading">Loading...</div>');
    $.post(Drupal.settings.basePath + 'community-feed-items', post_data, function(response) {
      var response_data = eval('(' + response + ')');
      if (response_data['status']) {
        var output = (response_data['data']) ? response_data['data'] : '<div class="community-feed-items-empty">No items match your filter selection.</div>';
        $destination.html(output);
      }
    });
  });
}