 $.fn.autocomplete_collection.Constructor = AutocompleteCollection
 
 $ ->
-
   $('[data-provide="autocomplete-collection"]').each ->
     $this = $(@)
     return if $this.data('autocomplete-collection')

    beginswith = []
    caseSensitive = []
    caseInsensitive = []

    while item = items.shift()
      if @strings
        sortby = item
      else
        sortby = item[@options.property]
      if !sortby.toLowerCase().indexOf(@query.toLowerCase())
        beginswith.push(item)
      else if ~sortby.indexOf(@query)
        caseSensitive.push(item)
      else
        caseInsensitive.push(item)

    beginswith.concat(caseSensitive, caseInsensitive)

  highlighter: (item) ->
    item.replace new RegExp('(' + @query + ')', 'ig'), ($1, match) ->

        @process(@source)

  process: (results) ->
    @strings = false if results.length and typeof results[0] isnt "string"
    @query = @$element.val()
    return @hide() if !@query and typeof @source is "function"
    items = @sorter $.grep results, (item) =>
      item = item[@options.property] unless @strings
      item if @matcher(item)
    return @hide() if !items.length and !@options.otherOption
    @render(items.slice(0, @options.items)).show()

  matcher: (item) ->
