/* comments.js */

Comment.comments_count_template = function() {
	template = "<span>Read All Comments (#{count})</span>";
	return template;
};

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("500 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((500 - 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() {
    template = '<div class="inner"><h3 class="widgetTitle">What people are saying about...</h3><a href="#{board_url}" 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.southernaccents.com/static/i/icon_quoteL.gif" alt="" /> #{body} <img src="http://img4.southernaccents.com/static/i/icon_quoteR.gif" alt="" /> <span class="author">&mdash;#{user_name}</span></p></div></div>';
	return template;
}

Comment.top_boards_template = function() {
	template = '<div class="inner"><h3 class="widgetTitle">Most talked about articles &amp; galleries</h3>#{top_boards}</div>';
	return template;
}
Comment.top_board_template = function() {
	template = '<div class="top_board"><a class="board" href="#{url:getContentUrl}">#{name}</a> <a href="#{url}" class="comments">Comments (#{viewable_comments_count})</a></div>';
	return template;
}
function getContentUrl(url) {return url.replace("comments-index.html", "index.html");}

$(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((500 - count) + " characters remaining");
	});
});