var commentsDiv;
var addCommentBox;
var FADESPEED = 65;

function doMagic() {
	if (document.getElementById("addcomment")) {
		if (document.getElementById("comments")) {
			commentsDiv = $("comments");
			commentsDiv = commentsDiv.getElementsByTagName("ul")[0];
		} else if (document.getElementById("viewcomments")) {
			commentsDiv = $("viewcomments");
		}

		if (commentsDiv) {
			addCommentBox = $("addcomment");
			addCommentBox.style.display = "none";
			addCommentLink = createAddCommentLink();

			commentsDiv.insertBefore(addCommentBox, commentsDiv.firstChild);
			commentsDiv.insertBefore(addCommentLink, commentsDiv.firstChild);
		}

		if (location.href.indexOf("process/comment/modify") > -1) {
			addComment();
		}
	}
}

function createAddCommentLink() {
	a = document.createElement("a");
	a.href = "javascript:void(0); addComment();";
	a.setAttribute("id","addCommentLink");
	a.appendChild(document.createTextNode("Post A Comment"));
	return a;
}

function addComment() {
	fadeIn(0);
	$("addcomment").style.display = "block";
	$("addCommentLink").style.display = "none";
	$("add-comment").childNodes[3].focus();
}

function setOpacity(opacity) {
	opacity = (opacity == 100) ? 99.999 : opacity;

	// IE/Win
	$("add-comment").style.filter = "alpha(opacity="+opacity+")";

	// Safari<1.2, Konqueror
	addCommentBox.style.KHTMLOpacity = opacity/100;

	// Older Mozilla and Firefox
	addCommentBox.style.MozOpacity = opacity/100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	addCommentBox.style.opacity = opacity/100;
}

function fadeIn(opacity) {
	if (opacity <= 100) {
		setOpacity(opacity);
		opacity += (FADESPEED/10);
		window.setTimeout("fadeIn("+opacity+")", FADESPEED/100);
	}
}

