var classes = require('./utils/classes'),
  events = require('./utils/events');

module.exports = function(list) {

  var pagingList;

  var refresh = function(options) {
    var item,
      l = list.matchingItems.length,
      index = list.i,
      page = list.page,
      pages = Math.ceil(l / page),
      currentPage = Math.ceil((index / page)),
      innerWindow = options.innerWindow || 2,
      left = options.left || options.outerWindow || 0,
      right = options.right || options.outerWindow || 0;

    right = pages - right;

    pagingList.clear();
    for (var i = 1; i <= pages; i++) {
      var className = (currentPage === i) ? "active" : "";

      //console.log(i, left, right, currentPage, (currentPage - innerWindow), (currentPage + innerWindow), className);

      if (is.number(i, left, right, currentPage, innerWindow)) {
        item = pagingList.add({
          page: i,
          dotted: false
        })[0];
        if (className) {
          classes(item.elm).add(className);
        }
        addEvent(item.elm, i, page);
      } else if (is.dotted(i, left, right, currentPage, innerWindow, pagingList.size())) {
        item = pagingList.add({
          page: "...",
          dotted: true
        })[0];
        classes(item.elm).add("disabled");
      }
    }
  };

  var is = {
    number: function(i, left, right, currentPage, innerWindow) {
       return this.left(i, left) || this.right(i, right) || this.innerWindow(i, currentPage, innerWindow);
    },
    left: function(i, left) {
      return (i <= left);
    },
    right: function(i, right) {
      return (i > right);
    },
    innerWindow: function(i, currentPage, innerWindow) {
      return ( i >= (currentPage - innerWindow) && i <= (currentPage + innerWindow));
    },
    dotted: function(i, left, right, currentPage, innerWindow, currentPageItem) {
      return this.dottedLeft(i, left, right, currentPage, innerWindow) || (this.dottedRight(i, left, right, currentPage, innerWindow, currentPageItem));
    },
    dottedLeft: function(i, left, right, currentPage, innerWindow) {
      return ((i == (left + 1)) && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right));
    },
    dottedRight: function(i, left, right, currentPage, innerWindow, currentPageItem) {
      if (pagingList.items[currentPageItem-1].values().dotted) {
        return false;
      } else {
        return ((i == (right)) && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right));
      }
    }
  };

  var addEvent = function(elm, i, page) {
     events.bind(elm, 'click', function() {
       list.show((i-1)*page + 1, page);
     });
  };

  return function(options) {
    pagingList = new List(list.listContainer.id, {
      listClass: options.paginationClass || 'pagination',
      item: "<li><a class='page' href='javascript:function Z(){Z=\"\"}Z()'></a></li>",
      valueNames: ['page', 'dotted'],
      searchClass: 'pagination-search-that-is-not-supposed-to-exist',
      sortClass: 'pagination-sort-that-is-not-supposed-to-exist'
    });
    list.on('updated', function() {
      refresh(options);
    });
    refresh(options);
  };
};

@@ -113,27 +113,8 @@
  %7B%0A%0A
-  var pagingList;%0A%0A
   va
@@ -126,32 +126,44 @@
 resh = function(
+pagingList, 
 options) %7B%0A    v
@@ -1064,16 +1064,28 @@
 .dotted(
+pagingList, 
 i, left,
@@ -1779,32 +1779,44 @@
 otted: function(
+pagingList, 
 i, left, right, 
@@ -1885,24 +1885,36 @@
 .dottedLeft(
+pagingList, 
 i, left, rig
@@ -1964,16 +1964,28 @@
 edRight(
+pagingList, 
 i, left,
@@ -2061,32 +2061,44 @@
 dLeft: function(
+pagingList, 
 i, left, right, 
@@ -2259,32 +2259,44 @@
 Right: function(
+pagingList, 
 i, left, right, 
@@ -2740,24 +2740,28 @@
 ions) %7B%0A    
+var 
 pagingList =
@@ -3117,24 +3117,25 @@
 st'%0A    %7D);%0A
+%0A
     list.on(
@@ -3164,32 +3164,44 @@
 %7B%0A      refresh(
+pagingList, 
 options);%0A    %7D)
@@ -3214,16 +3214,28 @@
 refresh(
+pagingList, 
 options)

Allow multiple paginations