 #  autoComplete.apply()
 class root.GmapAutocomplete extends Autocomplete
 
-  constructor: (@selector, @gmap)->
+  constructor: (selector, @gmap)->
+    super selector
     @gmap.onSucceed.push (address)=>
-      $(@selector).val address
+      @$el.val address
 
   source: (request, response) =>
     @gmap.searchGeocodes request.term, (results)->

    @_addKeyDownHandlers()

  syncWithMap: ()->
    @gmap.setMarker('address', $(@selector).val()) if $(@selector).val()

  _addKeyDownHandlers: ()->
    $(@selector).bind 'keydown', (event)=>
      if event.keyCode == 13
        @gmap.setMarker  'address', $(_this.selector).val()
        $(@selector).autocomplete "disable"
      else
        $(@selector).autocomplete "enable"


  change: ()=>
  minChars: 2

  constructor: (selector)->
    @$el = $(selector)

  apply: ()->
    @$el.autocomplete
      source: @source
      select: @select
      change: @change
