       while @subscriptions.length >= @maxSubscriptions
         @unsubscribe @subscriptions.order[0]
       true
-  
+
   # Called from the Meteor.publish call made during init, this publishes the paginated collection
   #
   # "this" will be the pagination instance
   # "page" is the page number to publish
   # "sub" is the publish handler object which (the "this" object when the function passed to Meteor.publish is called)
-  
+
   publish: (page, sub) ->
     check page, Number
     check sub, Match.Where (s) ->

    @[(if Meteor.isServer then "server" else "client") + "Init"]()
    @registerInstance()
    @
    
  error: (code, msg) ->
    msg = code  if !code?
    throw new Meteor.Error code, msg

  # Server initialisation
  
  serverInit: ->
    @setMethods()
    self = @
    
    # Remove the per-connection settings when a client disconnects from the server
    
    Meteor.onConnection (connection) =>
      connection.onClose =>
        delete @userSettings[connection.id]
        
    # Publish the collection that we're paginating, taking a page number as a parameter.
        
    Meteor.publish @id, (page) ->
      self.publish.call self, page, @
  
  # Client initialisation
  
  clientInit: ->
    @requested = {}
    @received = {}

@__Pages = class Pages

  settings:

    #settingName: [canBeMadeAvailableToTheClient, expectedTypes(s), defaultValue]

    dataMargin: [true, Number, 3]
    divWrapper: [true, Match.OneOf(
      Match.Optional(String)
