Comment.comment_template = function() {
  var template =
  '<li class="comment" id="comment_#{id}"><span class="author">#{user_name}</span>\
    <span class="date">#{created_at:Format.iso_date}</span>\
    <blockquote class="comment-body">\
    #{body:Format.text}\
    </blockquote>\
    <div class="options">\
      <a href="#" class="get expand_replies_link #{viewable_children_count:Format.quantity_class_name}" id="toggle_replies_#{id}">Read replies (#{viewable_children_count})</a> <a href="#" class="get add_reply_link" id="toggle_add_reply_#{id}">Add reply</a>\
    </div>\
    <div class="form"></div>\
    <ul class="replies"></ul>\
  </li>';
  return template;
};
Comment.top_pagination_template = function() {
  template = 
  '<div class="header">\
  <h4>Comments</h4><span class="comments_count"></span></div>\
  <ul class="comment-app-tools">\
      <li>#{expand_all_or_collapse_all}</li>\
    <li><a class="add-comment-link" href="#add-your-comment">Add comment</a></li>\
    </ul>\
  <div class="top-pagination">\
    <div class="sort-comments">\
      <span class="label">Sort by:</span>\
      <ul class="inline-left">\
        <li>#{oldest_first}</li>\
        <li>#{newest_first}</li>\
      </ul>\
    </div>\
    <div class="comment-pagination">\
      <span class="label">Page:</span>\
      <div class="pagination">#{links}</div>\
    </div>';
  return template;
};
Comment.bottom_pagination_template = function() {
  template =
  '<div class="bottom-pagination">\
    <div class="comment-pagination">\
      <span class="label">Page:</span>\
      <div class="pagination">#{links}</div>\
    </div>\
  </div>';
  return template;
};
Comment.comments_count_template = function() {
  template = 'Comments <span class="box">#{count}<span class="btm"></span></span>';
  return template;
};
Comment.more_comments_template = function() {   
  template = '<li>There are <a href="#" class="get_comment_replies">#{remaining_comments}</a> more comments</li>';
  return template;
};

/* Update comment character counter when typing */
jQuery(function() {
	jQuery('#comment_body').keyup(function() { 
    		jQuery('.body-count').html(500 - jQuery('#comment_body').val().length);
	});
});

/* Need to set the default options without triggering a comments call */
Url.defaults["order"] = "ASC";

/* Amending function to only grab first 15 words from title for ruby board_name */
Comment.comments_url = function() {
	var page=parseInt(Url.get_param("page"),10);
	page=(page)?page:1;
	
	var trunc_board_name ='', board_name_array = [];
	board_name_array = Comment.board_name.split('%2B');
	if( board_name_array.length > 14 ){
		for(i=0;i<=14;i++){
			trunc_board_name += ( i===14 ) ? board_name_array[i] : board_name_array[i] +'%2B';
		}
	} else {
		trunc_board_name = Comment.board_name;				
	}			
	
	return Comment.build_url(
		[Comment.board_resource_id,"comments"],
		".json?page="+page+"&order="+Url.get_param("order")+"&expand_all="+Url.get_param("expand_all")+"&per_page="+Url.get_param("per_page")+"&board_name="+trunc_board_name+"&board_url="+Comment.board_url+"&callback=?"
	);
}
