jQuery(document).ready(function($) {
  
  var autoHide = function(collections, max, tpl) {
    
    this.store = collections;
    this.max   = max;
    this.tpl   = tpl;
    this.init();

  };

  autoHide.prototype = {
    
    init: function() {
    
      this.hiddenBlock = this.store.slice(this.max, this.store.length);

      this.link = $( this.tpl || "<a class='dashed shortcut'>Далее</a>" ).
        attr("href", "#").
        appendTo( this.store.eq(this.max-1) ).
        click( $.proxy(this.onClick, this) );

      return this.onHide();

    }, // init

    onClick: function(evt) {
      
      evt.preventDefault();

      if (this.hidden) {
        this.onShow();
      } else {
        this.onHide();
      }

    }, // onClick

    onShow: function() {
      
      this.hidden = false;
      this.store.show();
      this.link.hide();
      return this;

    }, // onShow

    onHide: function() {
      
      this.hidden = true;
      this.hiddenBlock.hide();      
      this.link.show();
      return this;

    } // onHide

  }; // autoHide

  new autoHide( $("div.terms .list-in li"), 9);
  
});
