       @checkMaximum()
 
     checkMaximum: ->
-      if @options.maximum && @files.length >= @options.maximum
+      if @maximumReached()
         @$input.prop('disabled', true)
       else
         @$input.prop('disabled', false)
+
+    maximumReached: ->
+      @options.maximum && @files.length >= @options.maximum
+
+
 
     addFilesContainer: ->
       @$filesContainer = $('<div class="attachinary_container">')

      @$input.attr('multiple', true) if @options.maximum > 1
      @$input.fileupload(options)


    bindEventHandlers: ->
      @$input.bind 'fileuploaddone', (event, data) =>
        setTimeout (=> @addFile(data.result)), 0 # let 'fileuploadalways' finish

      @$input.bind 'fileuploadstart', (event) =>
        @$input = $(event.target)  # important! changed on every file upload
        $form = @$input.closest('form')
        $submit = $form.find('input[type=submit]')

        @$input.addClass 'uploading'
        $form.addClass  'uploading'

        @$input.prop 'disabled', true
        if @config.disableWith
          $submit.data 'old-val', $submit.val()
          $submit.val  @config.disableWith
          $submit.prop 'disabled', true

      @$input.bind 'fileuploadalways', (event) =>
        $form = @$input.closest('form')
        $submit = $form.find('input[type=submit]')

        @$input.removeClass 'uploading'
        $form.removeClass  'uploading'

        @$input.prop 'disabled', false
        if @config.disableWith
          $submit.val  $submit.data('old-val')
          $submit.prop 'disabled', false

    addFile: (file) ->
      if !@options.accept || $.inArray(file.format, @options.accept) != -1

    index: 0
    config:
      disableWith: 'Uploading...'
      indicateProgress: true
      invalidFormatMessage: 'Invalid file format'
      template: """
        <ul>
