/**
 * adds hide/show behaviour to form
 * activated by clicking on the title
 */
function commentControls(){
    //target the comment form
    var commentDiv = $('div#respond');

    //target form contents except h3
    var formContent = commentDiv.children().not('h3')
    //target the title
    var formTitle = commentDiv.children('h3');

    formContent.hide();

    formTitle.click(function(){
	var self = $(this);

	//instead of using toggleClass to add and remove the active state
	//we need to wait for the form animation to complete before
	//altering the title class
	if(!self.hasClass('active')){
	    self.addClass('active');
	}
	
	//stop and clear any animation, then perform slidetoggle
	formContent.stop(true,true).slideToggle('slow',function(){
	    $(this).toggleClass('active');
	    if(!$(this).hasClass('active')){
		self.removeClass('active');
	    }
	});
    });

}


$('document').ready(function(){
    commentControls();
});


