// $cmignore
// start when DOM fully loaded
$(document).ready(function() {
  // check if there is more than one item, and if not,
  // just exit out
  if (a.featured.length == 1) { return false; }
  
  // counter to keep track of what item we are on
  var counter = 0;
  
  // append previous and next links to featured box
  $('#featured > p:last-child').after('<a id="featured-prev" href="#">Previous</a>');
  $('#featured-prev').after('<a id="featured-next" href="#">Next</a>');
  
  // assign onclick event handlers to each link
  $("#featured-prev").bind("click", function() {
    counter--;
    if (counter < 0) { counter = a.featured.length - 1; }
    
    // fade out, swap content, fade back in
    $('#featured > h4, #featured > img, #featured > p').fadeOut("fast", function() {
      $('#featured > h4, #featured > p').empty();
      $('#featured > h4').append(a.featured[counter].heading);
      $('#featured > img').attr({ src: a.featured[counter].imgsrc, alt: a.featured[counter].heading });
      $('#featured > p:eq(0)').append(a.featured[counter].intro);
      if (a.featured[counter].url != "") {
          $('#featured > p:eq(1)').append('<a href="' + a.featured[counter].url + '">Learn more</a>');
      }
    }).fadeIn("fast");
    
    // cancel the link from going anywhere
    return false;
  });
  
  $("#featured-next").bind("click", function() {
    counter++;
    if (counter > a.featured.length - 1) { counter = 0; }
    
    // fade out, swap content, fade back in
    $('#featured > h4, #featured > img, #featured > p').fadeOut("fast", function() {
      $('#featured > h4, #featured > p').empty();
      $('#featured > h4').append(a.featured[counter].heading);
      $('#featured > img').attr({ src: a.featured[counter].imgsrc, alt: a.featured[counter].heading });
      $('#featured > p:eq(0)').append(a.featured[counter].intro);
      if (a.featured[counter].url != "") {
          $('#featured > p:eq(1)').append('<a href="' + a.featured[counter].url + '">Learn more</a>');
      }
    }).fadeIn("fast");
    
    // cancel the link from going anywhere
    return false;
  });
  
});
// $/cmignore

