$(function() {
    $('#vendor_cards').infinitescroll({

      navSelector   : "#vendor_nav", // selector for the paged navigation (it will be hidden)
      nextSelector  : "#vendor_nav a.next", // selector for the NEXT link (to page 2)
      itemSelector  : "#vendor_cards div.placard_holder", // selector for all items you'll retrieve
      loading       : {img: site_url + "assets/spinner.gif", msgText: "grabbing vendors...", finishedMsg: null}
    }, function(elements) {
        $(this).find('.premium_card .placard:not(\'.cycler\')').each(function() {
          $(this).createCycle();
        });
    }); 
    
    $('.premium_card .placard').each(function() {
      $(this).createCycle();
    });
    
    $(document).click(function() {
        $('.filters ul').hide();
    });
    
    $('.filter_label').click(function(e) {
        $('.filters ul').removeClass('current');
        ul = $(this).parent().find('ul');
        ul.toggle();
        if (ul.is(':visible')) {
            ul.addClass('current');
        }
        $('.filters ul:not(\'.current\')').hide();
        return false;
    });
    
    $('.filters select').change(function() {
      window.location = $(this).val();
    });
});

jQuery.fn.createCycle = function() {
  
  if ($('ul li', $(this)).length < 2) {
    $(this).children('.next, .prev').css({display: 'none'});
    return false;
  }
  
  
    
    $(this).addClass('cycler');
    
    $(this).children('.next, .prev').css({opacity: 0});
    
    
    
    $(this).children('ul').cycle({ 
        fx:     'fade', 
        sync: true,
        speed:  'fast', 
        timeout: 0, 
        next: $(this).children('a.next'),
        prev: $(this).children('a.prev')
    });
    
    $(this).mouseenter(function() {    
        $(this).children('cite').fadeAway();
        $(this).children('a').fadeForward();
        
        
    }).mouseleave(function() {
        $(this).children('cite').fadeForward();
        $(this).children('a').fadeAway();
        
    });
    
    
}


jQuery.fn.fadeAway = function() {
  return this.animate({marginTop: '+=20', opacity: 0}, 300);
};

jQuery.fn.fadeForward = function() {
  return this.animate({marginTop: '-=20', opacity: 1}, 300);
};
