// Cosmetic fixup on frontpage block items
window.cosmeticsBlockItems = new Cosmetics.FrontPageBlockItems();
window.articleDataGetter = new ArticleData.DataGetter();
window.commentCountSetter = new ArticleData.CommentCountSetter({
  defaultInsertSelector: '.ingress p a:last',
  defaultInsertFunction: function(targetEl, data) {
    targetEl.insert({'after': '<span class="comment-count"><a title="Denne artikkelen har ' + data.count + ' kommentar(er)" href="/php/art.php?id=' + data.id + '#debatt"><img src="/pub/resources/img/icons/comments.png" alt="snakkeboble" title="Kommentarer" />' + data.count + '</a></span>'});
  }
});
/* Add layoutclasses for commentCountSetter so it knows what
 * to look for when iserting the commentcount-tags ('standard-layout' is added by default): */
window.commentCountSetter.addLayoutClass('title-only-layout', {
  insertSelector: '.text h2'
});

Event.observe(document, 'dom:loaded', function() {
  (function() {
    /* Load comentcounts for the articles on the frontpage.
     * -The commentCountSetter is listening */
    window.articleDataGetter.get({
      doneEventName: 'article-data:comment-counts-loaded',
      handler: 'commentcounts',
      params: {categoryid: window.serverData.webCategoryId},
      caller: window.articleDataGetter,
      callback: window.articleDataGetter._responseParser
    });

  })();
});

Event.observe(document, 'article-data:comment-counts-inserted', function() {
  (function() {
    /* Adjust height of items in the last, small games block */
    window.cosmeticsBlockItems.setBlockItemHeights({blockSelector: '.sub-block.games .sub-block.small'});
  })();
});

