jQuery.noConflict();
jQuery(document).ready(function(){
	/* The following code is executed once the DOM is loaded */

	/* This flag will prevent multiple comment submits: */
	var working = false;

        jQuery('#clicke').click(function(e){

            jQuery('#addCommentContainer').slideDown();
            jQuery('#clicke').hide();
        });
        jQuery('#news').click(function(e){

            jQuery('#newsletter').slideDown();
            
        });        

	/* Listening for the submit event of the form: */
	jQuery('#addCommentForm').submit(function(e){

 		e.preventDefault();
		if(working) return false;

		working = true;
		jQuery('#submit').val('Working..');
		jQuery('span.error').remove();

		/* Sending the form fileds to submit.php: */
		jQuery.post('/submit.php',jQuery(this).serialize(),function(msg){
                        
			working = false;
			jQuery('#submit').val('Submit');

			if(msg.status){

				/*
				/	If the insert was successful, add the comment
				/	below the last one on the page with a slideDown effect
				/*/

				//jQuery(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
                                jQuery(msg.html).hide().insertAfter('#addCommentContainer').slideDown();
                                jQuery('#addCommentContainer').slideUp();
                                jQuery('#clicke').show();
				jQuery('#body').val('');
			}
			else {

				/*
				/	If there were errors, loop through the
				/	msg.errors object and display them on the page
				/*/

				jQuery.each(msg.errors,function(k,v){
					jQuery('label[for='+k+']').append('<span class="error">'+v+'</span>');
				});
			}
		},'json');

	});

});
