 )
 
 Handlebars.registerHelper('vis_tags', (context, object) ->
-  @my_tags = {test: 0}          #REMOVE
+  @my_tags = {test: 0}          #TODO: REMOVE
   ret = ""
   for tag in context
     ret += "<div class='tag"

        #sort by weight, then return list of names
        cmp_weight = (a,b) -> a.weight - b.weight
        res = sug_list.sort( cmp_weight ).map( (a) -> a.name )
        #console.log(res)
        Session.set("suggestions_#{ @_id }", res)
        
        event.stopImmediatePropagation()
        
    "click button[name='enter_tag']": (event) ->
      if not event.isImmediatePropagationStopped()
        tag_text = event.target.parentNode.getElementsByTagName(
          "textarea")[0].value
        if tag_text != "" # && not @my_tags[tag_text]?
          #add to @my_tags not @tags
          @tags[tag_text] ?= { users: [], weight: 0}
          @tags[tag_text].users.push(Meteor.call("get_user_id"))
          Posts.update(@_id, {$set: {tags: @tags}})
        event.stopImmediatePropagation()
        
    "click button[name='done_tagging']": (event) ->

            
          
        event.stopImmediatePropagation()
    ###
    "keydown textarea[name='tag_text']": (event) -> #Suppresses newline
      if not event.isImmediatePropagationStopped()
        switch event.keyCode
          when 13 #Enter
            event.preventDefault()
          
        event.stopImmediatePropagation()
    
    "keyup textarea[name='tag_text']": (event) ->
      if not event.isImmediatePropagationStopped()
      
        entered_text = event.target.value
        
        #TODO: modify for new HTML layout,
        #      or find less convoluted way to get particular elements
        suggested_tag = event.target.parentNode.parentNode.
          getElementsByTagName("div")[0].
          getElementsByTagName("form")[0]?.innerText
        
        switch event.keyCode
          when 13 #Enter
            ###TODO: Encapsulate this code so the click event calls it too
            if entered_text != "" #TODO: && not @my_tags[tag_text]?
              #TODO: add to @my_tags not @tags
              @tags[entered_text] ?= { users: [], weight: 0}
              @tags[entered_text].users.push(Session.get('user_id'))
              Posts.update(@_id, {$set: {tags: @tags}})
              #clear textbox and update suggestion filter
              event.target.value = ''
              Session.set("filter_text_#{ @_id }", '')
              Session.get("context_#{@_id}").invalidate()
            ###
            #Does this work?  It encapsulates the code pretty well
            #$("button[name='enter_tag']").click()
            Template.tagbox.add_tag(@tags, entered_text, event, @_id)
          when 37 #Left-arrow: ADD
            if suggested_tag?
              @tags[suggested_tag] ?= { users: [], weight: 0}
              @tags[suggested_tag].users.push(Session.get('user_id'))
              Posts.update(@_id, {$set: {tags: @tags}})
              Session.get("suggestions_#{ @_id }").remove(suggested_tag) #TODO: REMOVE
              Session.get("context_#{@_id}").invalidate()  #TODO: REMOVE
          when 39 #Right-arrow: REMOVE
            Session.get("suggestions_#{ @_id }").remove(suggested_tag)
            Session.get("context_#{@_id}").invalidate()
          else    #Update suggestions with new text
            Session.set("filter_text_#{ @_id }", entered_text)
            Session.get("context_#{@_id}").invalidate()
          
        event.stopImmediatePropagation()
    
    "click button[name='tagbutton']": (event) ->
      if not event.isImmediatePropagationStopped()
        Session.set("tagging_#{ @_id }", true)  #Display tagbox
        
        #MAKE SUGGESTIONS
        @my_tags = {} #TODO: REMOVE on schema change
        suggestions = {}
        #get graduated tags from siblings
        for post in Posts.find( 'parent_id': @parent_id ).fetch()
