       Kandan.Helpers.Utils.browserTabFocused = false
     )
 
-
   initBroadcasterAndSubscribe: ()->
     Kandan.broadcaster = eval "new Kandan.Broadcasters.#{@options().broadcaster.name}Broadcaster()"
     Kandan.broadcaster.subscribe "/channels/*"
-    @registerAppEvents()
 
   initTabs: ()->
     $('#kandan').tabs({

    , @options().timestamp_refresh_interval)

  init: ->
    initializer = @createCallback 3, =>
      Kandan.registerPlugins()
      Kandan.Plugins.initAll()
      Kandan.initChatArea(Kandan.Helpers.Channels.getCollection())
      Kandan.initTabs()
      Kandan.Widgets.initAll()
      Kandan.Helpers.Channels.scrollToLatestMessage()
      Kandan.Plugins.Mentions.initUsersMentions(Kandan.Helpers.ActiveUsers.all())
      Kandan.Plugins.Emojis.attachToChatbox()
      return

    new Kandan.Collections.Channels().fetch {
      success: @onFetchChannels(initializer)
    }
    new Kandan.Collections.ActiveUsers().fetch {
      success: @onFetchActiveUsers(initializer)
    }
    new Kandan.Collections.Users().fetch {
      success: @onFetchUsers(initializer)
    }
    @registerUtilityEvents()
    @initBroadcasterAndSubscribe()

  createCallback: (limit, callback)->
    finishedCalls = 0
    -> callback() if ++finishedCalls == limit

  onFetchChannels: (callback) ->
    (channels) =>
      Kandan.Helpers.Channels.setCollection(channels)
      callback()

    chatArea = new Kandan.Views.ChatArea({channels: channels})
    $(".main-area").append(chatArea.render().el)

  onFetchChannels: (callback) ->
    (channels) ->
      Kandan.Helpers.Channels.setCollection(channels)
      callback()

  onFetchActiveUsers: (callback) ->
    (activeUsers) ->
      if not Kandan.Helpers.ActiveUsers.collectionHasCurrentUser(activeUsers)
        activeUsers.add([Kandan.Helpers.Users.currentUser()])
      Kandan.Helpers.ActiveUsers.setFromCollection(activeUsers)
      callback()

  onFetchUsers: (callback) ->
    (users) ->
      Kandan.Helpers.Users.setFromCollection(users)
      callback()

  registerUtilityEvents: ()->
