 Meteor.subscribe( "assigned_posts" )
 
 #Template variables/functions
-min_posts = 0
+min_posts = 999
 
 graduated = (tag, post) ->
   return post.tags[tag].users.length >= 2

    placed = 0
    for tag,info of post.tags
      if graduated(tag, post)
        addGroupName(post, tag)
        if groups[tag]?
          groups[tag].posts.push(post)
        else
          groups[tag] = {'posts': [post]}
        placed++
      else if placed == 0
        addGroupName(post, 'Incubator')
        groups['Incubator'].posts.push(post)
        placed++
      count++
    if count == 0
      addGroupName(post, 'Incubator')
      groups['Incubator'].posts.push(post)
  groupList = []
  for name,info of groups


_.extend( Template.stream,
  posts: ->
    return (Posts.find( 'parent_id': undefined ).map (post) -> {'post':post, 'group':""})
  new: true
)

_.extend( Template.post,
  content: -> 
    showdownConverter = new Showdown.converter()
    postContentHtml = showdownConverter.makeHtml(@post.content)
    return postContentHtml
  groups: -> 
    children = Posts.find( parent_id: @post._id )
    numChildren = children.count()
    if numChildren == 0
      return []
    else if numChildren < min_posts
      return [{'name': "All Replies", 'posts': children.fetch()}]
    else
      return makeGroups(children)
  identifier: -> @post._id
  groupname: -> @group
  events: {
    "click button[name='replySubmit']": (event) ->
      if !event.isImmediatePropagationStopped()
        replyTextBox = document.getElementById("replyText-#{ @post._id }-#{ @group }")#Bryan thinks there's a way to do this without traversing the DOM.
        event.stopImmediatePropagation()
        replyContent = replyTextBox.value
        console.log("ID of Post you're replying to: #{ @post._id }-#{ @group }")
        console.log("Reply content: #{replyContent}")
        replyID = Posts.insert(
          {
            content: replyContent,
            parent_id: @post._id,
            instance_id: @post.instance_id
          }
        )
        console.log("ID of new post: "+replyID)
        replyTextBox.value = '' #clear the textbox for giggles -- should probably do this only if the post succeeds.
  }
  
)

_.extend( Template.group,
  name: -> @name
  posts: -> {'post':post, 'group':@name} for post in @posts
)

_.extend( Template.notifications,
