// Show show/hide-buttons
$(document).ready(function() {
   $('.comment').prepend("<p class='hide' title='Skjul kommentaren'>[-]</p>");
});

// basic show and hide
 $(document).ready(function() {
   $('.comment .hide').click( function() {
    $(this).nextAll().toggle();
    if ($(this).next().is(':hidden')) {
      var numberOfCommentsHidden = $(this).parent().find(".comment").length + 1;
      if (numberOfCommentsHidden > 1) {
         var textToShow = numberOfCommentsHidden + " kommentarer skjult. [+]";
         var titleToShow = "Vis kommentarene";
      }
      if (numberOfCommentsHidden == 1) {
         var textToShow = "Én kommentar skjult. [+]";
         var titleToShow = "Vis kommentaren";
      } 
      $(this).text(textToShow);
      $(this).attr("title", titleToShow);
      $(this).attr("class", "show");
    }
    if ($(this).next().is(':visible')) {
      $(this).text("[-]");
      $(this).attr("title", "Skjul kommentaren");
      $(this).attr("class", "hide");
    }
   });
});
