// ================================================================================================
var comment_controller = {
  // init vars
  
  // ==========================================================================
  init: function() {
    this.setNumComments();
    this.setReadMore();
    this.setAddComment();
    
    // set up the report abuse buttons
    reportAbuse.init();
  },
  
  // ==========================================================================
  setNumComments: function() {
    $('.news_comment_links').text(num_comments + ' Comment' + (num_comments != 1 ? 's' : ''));
  },
  
  // ==========================================================================
  setReadMore: function() {
    var ele = $('#comments_read_more');
    if (ele)
    {
      var tag = ele.children('a');
      ele.attr('rel', tag.attr('href'));
      tag.attr('href', '#');
      ele.show();
      ele.click(function() {
        $('#comments').load($(this).attr('rel'), '', function() {comment_controller.init();});
        return false;
      });
    }
  },
  
  // ==========================================================================
  setAddComment: function() {
    // override the main form
    $('#ArticleCommentsMainLeft form').submit(function() {return false;});
  }, 
  
  // ==========================================================================
  catchErrors: function() {
    if ($('#ArticleCommentsMainLeft').get(0).innerHTML == 'fail_login')
    {
      $('#ArticleCommentsMainLeft').get(0).innerHTML = $('#comments_must_login').get(0).innerHTML;
      $("#comments_show_login").colorbox({width: '415px'});
    }
  }
};

// sets up and controls the comments
// ================================================================================================
$(function() {
  // check for a jump to comments
  var jump = window.location.href.match(/\#comment\_\d+/i);
  if (jump)
    comment_url = comment_url.replace(/(&short=short)|(\/short)/gi, '');
  
  // load in the comments
  $('#comments').load(comment_url, '', function() {comment_controller.init(); if (jump) {window.location.href = window.location.href;}});
});