/* comments.js */

Comment.comments_count_template = function() {
	template = "&raquo; Read all comments (#{count})";
	return template;
};

Comment.top_pagination_template = function() {
	template = '<div class="top-pagination"><div class="pagination-row1"><div class="pagination_info"><b>COMMENTS</b> (#{info})</div><ul class="expand-collapse"><li>#{expand_all_or_collapse_all}</li><li><a href="#new_comment_form">&raquo; add comment</a></li></ul></div><div class="pagination-row2"><div class="sort-comments"><span class="label">Sort by:</span> #{newest_first} | #{oldest_first}</div><div class="comment-pagination"><span class="label">Page:</span><div class="pagination">#{links}</div></div></div></div>';
	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.comment_template = function() {
	template =
	'<li class="comment" id="comment_#{id}"><span class="author">#{user_name}</span><span class="date">#{created_at:Format.iso_date}</span>#{body:Format.text}<ul class="comment-tools"><li><a href="#" class="get expand_replies_link #{viewable_children_count:Format.quantity_class_name}" id="toggle_replies_#{id}">Read replies (#{viewable_children_count})</a></li><li><a href="#" class="get add_reply_link" id="toggle_add_reply_#{id}">Add reply</a></li></ul><div class="form"></div><ul class="replies"><li/></ul></li>';
	return template;
};

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>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">&raquo; Read All Comments (#{board_viewable_comments_count})</a> <a href="#{board_url}#add-your-comment" class="link-to-comments">&raquo; Add Comment</a><div class="comment-body"><p class="fc"><img src="http://img4.myhomeideas.com/static/i/icon_quoteL.gif" alt="" /> #{body} <img src="http://img4.myhomeideas.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>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">&raquo; Read All Comments (#{viewable_comments_count})</a></div>';
	return template;
}
function getContentUrl(url) {return url.replace("comments.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");
	});
});