/* jQuery List Preview 0.1
 * Matt Cegielka
 * matthewcegielka@akauk.com
 */

(function($) {
    $.fn.listPreview = function(settings) {
      var config = {
        'count': 2, // Number of items to show universally
        'selector': '> div', // Selector for items within the collection
        'showText':'Show', // Text to display on the control when items are hidden
        'hideText':'Hide', // Text to display on the control when items are shown
        'open':false, // Start open, rather than closed
        'speed':"fast" // Animation speed, jQuery style
      };
      if (settings) $.extend(config, settings);

      this.each(function() {
          $(config.selector, this).slice(config.count).wrapAll('<div class="listpreview-container" />');
          $('> .listpreview-container', this).after('<div class="listpreview-actions"><a href="#">' + ((config.open)?config.hideText:config.showText) + '</a></div>');

          var act = $('.listpreview-actions a', this);
          var wrap = $('.listpreview-container', this);
          if (!config.open) {wrap.hide();}

          act.live('click', function() {
              wrap.slideToggle(config.speed, function() { if ($(this).is(':visible')) { act.text(config.hideText); } else { act.text(config.showText); } });
              return false;
            });

          return this;
        });
    }
  })(jQuery);

