function karma(cid, direction, buryable)
{
	if(direction == "N")
	{
		if(buryable)
		{
			bury(cid);
		}
		$("up-"+cid).src = "img/ArticlePage/Karma/up.gif";
		$("down-"+cid).src = "img/ArticlePage/Karma/down-disabled.gif";
	}
	else
	{
		unbury(cid);
		$("up-"+cid).src = "img/ArticlePage/Karma/up-disabled.gif";
		$("down-"+cid).src = "img/ArticlePage/Karma/down.gif";
	}

	$("karma-"+cid).className = "current-score";

	var requester = new Ajax.Updater(
				"karma-"+cid,
				"community.php?action=karma&cid="+cid+"&direction="+direction+"&return=false",
				{
					method: 'get'
				}
			);

	repositionNewFooter();
	return false;
}

function loginToComment(cid)
{
	$("buttons-"+cid).style.display = "none";
	$("karma-"+cid).style.display = "none";
	$("login-"+cid).style.display = "block";

	return false;
}

function adjustThreshold()
{
	var threshold = $("karma-threshold").options[$("karma-threshold").selectedIndex].value;

	var requester = new Ajax.Request("community.php?action=update-karma-threshold&threshold="+threshold+"&return=false");

	// iterate through all the comments
	var comments = document.getElementsByClassName("current-score");

	for(i = 0; i < comments.length; i++)
	{
		var splits = comments[i].id.split("-");
		cid = splits[1];

		// if the karma value of the comment is lower
		// than the threshold, hide it!
		var score = parseInt(comments[i].innerHTML);
		if(isNaN(score))
		{
			score = 0;
		}

		if(score < threshold)
		{
			bury(cid, true);
		}
		else
		{
			unbury(cid, true);
		}
	}

	repositionNewFooter();

	return false;
}

function bury(cid, adjustment)
{
	$("buried-"+cid).style.display = "none";
	$("poster-details-"+cid).style.display = "none";
	$("buried-message-"+cid).style.display = "block";
	$("poster-"+cid).className = "poster buried1";

	if(adjustment)
	{

	}
	else
	{
		$("buried-by-you-"+cid).style.display = "block";
		$("buried-by-others-"+cid).style.display = "none";
	}

	repositionNewFooter();
}

function unbury(cid)
{
	$("buried-"+cid).style.display = "block";
	$("poster-details-"+cid).style.display = "block";
	$("buried-message-"+cid).style.display = "none";
	$("poster-"+cid).className = "poster buried";

	repositionNewFooter();

	return false;
}

function loadScorers(id)
{
	if($("scorers-"+id))
	{
		$("scorers-"+id).style.display = "block";
		var updater = new Ajax.Updater(
			"scorers-"+id,
			"community.php?action=view-scorers&cid="+id,
			{
				method: 'get'
			}
		);
	}
}

function AjaxComment(submission, aid)
{
	new Ajax.Request(
		'community.php',
		{
			method: 'post',
			encoding: 'UTF-8',
			parameters: Form.serialize(submission)
		}
	);
	new Ajax.Updater
	(
		'comments',
		'community.php',
		{
			evalScripts: true,
			asynchronous: true,
			parameters: '&action=redraw-comments&article_id='+aid
		}
	);
	return false;
}