$(document).ready(function(){	
	//Reply					   
	$("a.c_reply").click(function() { 
		//Find author name in link						  
		var author = $(this).parents("li").find("span a").html();
		//Find comment id
		var authlink = $(this).parents("li").attr("id");
		//Get textarea value
		var text = $("textarea#commentbox").attr("value");
		//Add textarea value to include username and comment link
		$('textarea#commentbox').attr("value",text+"<a href='#"+authlink+"'>@"+author+"</a>").focus();
	});
	//Quote
	$("a.c_quote").click(function() {
		//Find author name in link							  
	 	var author = $(this).parents("li").find("span a").html();
		//Find comment id
	 	var authlink = $(this).parents("li").attr("id");
		//Get textarea value
	 	var text = $("textarea#commentbox").attr("value");
		//Get content of comment
		var quote = $(this).parents("li").find('p').text();
		//Get any highlighted text
		if (window.getSelection)
			var selection = window.getSelection();
		else if (document.getSelection)
			var selection = document.getSelection();
		else if (document.selection) {
			var selection = document.selection.createRange().text; }   
		//Use highlighted text if anything is highlighted instead of full comment
		if(selection!="") quote = selection;
		//Add quoted text, author, and comment link to textarea
	 	$('textarea#commentbox').attr("value",text+"<a href='#"+authlink+"'>@"+author+"</a><cite>"+quote+"</cite>").focus();
	});
});