/* comments.js */
var MAX_COMMENT_LENGTH = 2000;

Comment.comments_count_template = function() {
	return "<span>Comments (#{count})</span>";
};

Comment.clone_form = function(comment_id) {
	var reply_form = $("#new_comment_form").clone();
	reply_form.removeAttr("id");
	reply_form.append('<input type="hidden" name="comment[parent_id]" value="'+comment_id+'" />');
	reply_form.find(".form_title").text("Reply");
	reply_form.find("div.errors").empty();
	reply_form.find(".charCount").text(MAX_COMMENT_LENGTH + " characters remaining");
	reply_form.find("textarea").bind("click change keydown keyup keypress blur focus", function(){
		var count = $(this).val().length;
		$(this).parent().find(".charCount").text((MAX_COMMENT_LENGTH - count) + " characters remaining");
	});
	return reply_form;
};

Comment.expand_all_or_collapse_all_link = function() {
	if (Url.get_params().expand_all == 'true') {
		return '<a class="collapse" href="'+Url.new_url({expand_all: 'false'})+'">Collapse all replies</a>';
	} else {
		return '<a class="expand" href="'+Url.new_url({expand_all: 'true'})+'">Expand all replies</a>';
	}
}

Comment.featured_comment_template = function() {
    return '<div class="inner"><h3 class="widgetTitle">What people are saying about...</h3><a href="#{board.url:getContentUrl}" class="link-to-article">#{board.name}</a> <a href="#{board.url}" class="link-to-comments comments">Comments (#{board.viewable_comments_count})</a> | <a href="#{board.url}#add-your-comment" class="link-to-comments">Add comment</a><div class="comment-body"><p class="fc"><img src="http://img4.allyou.com/static/i/icon_quoteL.gif" alt="" /> #{body} <img src="http://img4.allyou.com/static/i/icon_quoteR.gif" alt="" /> <span class="author">&mdash;#{user_name}</span></p></div></div>';
}

Comment.top_boards_template = function() {
	return '<div class="inner"><h3 class="widgetTitle">Most talked about articles &amp; galleries</h3>#{top_boards}</div>';
}
Comment.top_board_template = function() {
	return '<div class="top_board"><a class="board" href="#{url:getContentUrl}">#{name}</a> <a href="#{url}" class="comments">Comments (#{viewable_comments_count})</a></div>';
}
function getContentUrl(url) {return url.replace("comments-index.html", "index.html");}

Comment.comment_template = function() {
      return '<li class="comment" id="comment_#{id}"><!--img src="#{small_photo_url}" /--><span class="author">#{user_name}</span><span class="date">#{created_at:Format.iso_date}</span>#{body:Format.text}<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><!--a href="#{profile_url}" class="get view_profile">View profile</a><a href="#" class="get report_inappropriate_link" id="report_inappropriate_link#{id}">Report as inappropriate?</a--></div><div class="form"></div><ul class="replies"><li></li></ul></li>';
}

$(document).ready(function(){
	//character counter
	$("div.form textarea").bind("click change keydown keyup keypress blur focus", function(){
		var count = $(this).val().length;
		$(this).parent().find(".charCount").text((MAX_COMMENT_LENGTH - count) + " characters remaining");
	}).change();
});
