class window.FlashMessage

  constructor: (@category, message) ->
    @messages = []
    @container = $("#flash-container")

    if message
      @messages.push(message)

  addMessage: (message) ->
    @messages.push(message)

  show: ->
    flashDiv = $("<div class='alert alert-#{@category}'><button type='button' class='close' data-dismiss='alert'>&times;</button>")
    for message in @messages
      flashDiv.append("<span class='message'>#{message}</span><br/>")

    setTimeout (->
      flashDiv.fadeOut()
      return
    ), 2000
    flashDiv.hide().appendTo(@container).fadeIn()
