/**
 * JavaScript for Comments-Form
 *
 * @author Marcel Eichner // Ephigenia <love@ephigenia.de>
 * @since 2010-04-19
 */
$(document).ready(function() {
	
	var md5Field = '<input type="hidden" name="data[md5]" value="ohthietoosaiZ4fe2Iyei4ciewechohf">';
	$('form.commentform fieldset').append(md5Field);
	

	$('form.commentform').live('submit.comment', function() {
		var options = {
			success: function(responseText, statusText, xhr, formElm) { 
				var isForm = $(responseText).find('input');
				if (isForm.length > 0) { // probably validation error, show form
					formElm.html($(responseText).html());
					
				} else { // show comments
					var commentsList = formElm.parent().find('ul.comments');
					if (commentsList.length > 0) {
						commentsList.html($(responseText).html());
					} else {
						formElm.before(responseText);
					}
					// clear form
					formElm.clearForm().removeClass('commentfocus');
					// update stream item if there?
					formElm.closest('.streamItem').removeClass('noComment').addClass('hasComment');
				}
				
				if (wesc._pluginLoaded('timeago')) {
					$('.datetime,.time').timeago();
				}
				
				wesc.formsglobal.setupcheckfill();
				
				
			}
		};
		$(this).ajaxSubmit(options); 
		return false;
	});
	
	
	
	// 
	$('.commentform textarea').live('focus.comment', function(){
		$(this).parents('form').addClass('commentfocus');
	}).live('blur.comment', function(){
		if(!$(this).val()) {
			$(this).parents('form').removeClass('commentfocus');
		}
	});
	
	
});

