/**************************************************
 *
 *	commentFormDisplay, hide dotclear's comment form and add button to display it.
 *
 *	@author    Neck - http://www.eikylon.net
 *	@version   1.2.0
 *	@licence   available under the Creative Commons Attribution 3.0 Unported - http://creativecommons.org/licenses/by/3.0/
 *	           WITHOUT ANY WARRANTY, use it "at your own risks"
 *	@created   november 2007
 *	@updated   december 2007
 *
 **************************************************/
commentFormDisplay = {
	/**
	 * The comment-form node
	 *
	 * @var DOMNode
	 */
	commentForm : null,
	/**
	 * The button to display the form
	 *
	 * @var DOMNode
	 */
	commentFormButton : null,

	/**
	 * Init the class, hide comment-form.
	 *
	 */
	init: function () {
		if (!document.getElementById) return;

		// seek comment-form
		this.commentForm = document.getElementById('comment-form');
		if(!this.commentForm) return;

		// do not hide in preview
		if(document.getElementById('pr')) {
			this.commentForm.style.display = 'block';
			return;
		}

		// hide the comment form
		// this is done by stylesheet and .hasJS class which looks better
		// this.commentForm.style.display = 'none';

		// create a button to show comment-form
		this.commentFormButton = document.createElement('input');
		this.commentFormButton.setAttribute('type', 'button');
		this.commentFormButton.setAttribute('id', 'comment-button');

		// copy label from first <h3> in comment-form
		var buttonLabel = this.commentForm.getElementsByTagName('h3').item(0).firstChild.nodeValue;
		this.commentFormButton.setAttribute('value', buttonLabel.toLowerCase());
		this.commentFormButton.onclick = function() {commentFormDisplay.show()};

		this.commentForm.parentNode.insertBefore(this.commentFormButton, this.commentForm);
	},

	/**
	 * Hide button and display form.
	 *
	 */
	show: function () {
		if(!this.commentForm) return;

		this.commentFormButton.style.display = 'none';
		this.commentForm.style.display = 'block';
	}
}

// autoload
window.onload = function () {
	commentFormDisplay.init();
}
NK_framework.addJSClass();