$(document).ready(function() {
  // API "get" to pull current category's slides
  var category = escape(location.pathname.replace(/,/g, '%2C'));
  pixelsilk2.ajaxPost("/api2/getListItems", {
    path: "/category-slides/",
    fields: ["Link", "Image", "Title"],
    filters: [{field: "Category", comparison: "eq", value: category}],
    filterrel: "",
    sorts: [{field: "SortOrder", direction: "Ascending"}],
    pagesize: "1000",
    page: "1"
  }, function(json) {
    if ( json.length ) {
      var html = '';
      html += '<ul>';
      for ( i = 0; i < json.length; i++ ) {
        html += '<li>';
        if ( json[i].Link != '' ) {
          html += '<a href="' + json[i].Link + '"><img src="' + json[i].Image + '?w=645&h=289" width="645" height="289" alt="' + json[i].Title + '" /></a>';
        } else {
          html += '<img src="' + json[i].Image + '?w=645&h=289" width="645" height="289" alt="' + json[i].Title + '" />';
        }
        html += '</li>';
      }
      html += '</ul>';
      
      $("#categorySlides").append(html);
      $("#categorySlidesContainer").show();

      if ( i > 1 ) {
        var auto = true;
        var showControls = true;
      } else {
        var auto = false;
        var showControls = false;
      }
      $("#categorySlides").easySlider({
        continuous: true,
        controlsShow: showControls,
        auto: auto,
        pause: 8000,
        numeric: true,
        numericId: 'categorySlidesControls'
      });
    }
    
    $('#categorySlidesControls li:not(:last)').each(function() {
      $(this).after('<li class="separator">|</li>');
    });  
  });
});
