 #= require ./alert_hiding
 
 $(document).ready ->
+
+  ########################################################
+  # EVENTS
+  ########################################################
 
   #-------------------------------------------------------
   # Load current feed entries when clicking on a feed in the sidebar


    # Function to insert new entries in the list
    insert_entries = (entries, status, xhr) ->
      $(".icon-spin").removeClass("icon-spin").addClass "hidden"
      $("#loading").addClass "hidden"
      $("#feed-entries").removeClass "hidden"
      # Show and enable Refresh button
      $("#refresh-feed").removeClass("hidden").removeClass("disabled")
      # Unsubscribe and Folder Management buttons are shown and enabled only if reading a single feed

    # Creating a new folder adds this feed to it
    $("#new_folder_feed_id").val(feed_id)

    show_feed_title this
    loading_entries this

    # Load the entries via Ajax
    $("#feed-entries").load feed_path, null, insert_entries

  ########################################################
  # COMMON FUNCTIONS
  ########################################################

  #-------------------------------------------------------
  # While loading entries hide the entries list,show the spinner and  show "Loading" message
  #-------------------------------------------------------
  loading_entries = (feed)->
    $("#feed-entries").empty().addClass "hidden"
    $("#start-info").addClass "hidden"
    $("#loading").removeClass "hidden"
    $(".icon-spinner", feed).addClass("icon-spin").removeClass "hidden"

  #-------------------------------------------------------
  # When entries have loaded hide the spinner and "Loading" message, show the entries list
  #-------------------------------------------------------
  entries_loaded = (feed)->
    $(".icon-spin").removeClass("icon-spin").addClass "hidden"
    $("#loading").addClass "hidden"
    $("#feed-entries").removeClass "hidden"

  #-------------------------------------------------------
  # Show the feed title and link it to the feed URL
  #-------------------------------------------------------
  show_feed_title = (feed)->
    # Show the feed title
    feed_title = $(feed).attr "data-feed-title"
    $("#feed-title a").text feed_title
    $("#feed-title").removeClass "hidden"
    feed_url = $(feed).attr "data-feed-url"
    $("#feed-title a").attr("href", feed_url)