jQuery(document).ready(function ($) {
  // Reset filter
  $("#all-categories").click(function () {
    $.post(route_filter, {
      filter: -1,
      format: "raw"
    }, function (data) {
      // Get posts
      $.post(route_blog_posts, { format: "raw" }, function (response) {
        $(".posts").html(response);
      });
    });

    return false;
  });

  // Categories link
  $(".categories a, .post_category").unbind().click(function () {
    $.post(route_filter, {
      filter: $(this).attr("rel"),
      format: "raw"
    }, function (data) {
      // Get posts
      $.post(route_blog_posts, { format: "raw" }, function (response) {
        $(".posts").html(response);
      });

      // Scroll to top
      $('html').animate({scrollTop:0}, 'fast');
    });

    return false;
  });

  // Pagination links
  $("#pagination a").click(function () {
    var href = $(this).attr("href");

    $.post(href, { format: "raw" }, function (response) {
      $(".posts").html(response);
      $('html').animate({scrollTop:0}, 'fast');
    });

    return false;
  });
});