document.observe("dom:loaded", function() {
	
	var cookies = document.cookie.match('24-7blogcommenter=(.*?)(;|$)');
	
	if ($('comment-form') && cookies) {
		$H(unescape(cookies[1]).evalJSON()).each(function(pair){
			$('comment-form').getInputs('text',pair.key).invoke('setValue',pair.value);
		});
		$('commentform-name').setValue($('commentform-name').getValue().gsub('+',' '));
		$('commentform-remember').checked = true;
	}

	$$('#commentform-preview').each(function(elt){
		elt.observe('click',function(event){
			Event.stop(event);
			Event.element(event).addClassName('disabled');
			$('comment-form').select('input.missing,textarea.missing').each(function(elt){ elt.removeClassName('missing'); });
			$('comment-form').select('.alert_negative').each(function(elt){ elt.remove(); });
			new Ajax.Updater('comment-preview', location.pathname, {
				method: 'post',
				parameters: $H($('comment-form').serialize({hash:true})).merge({action:'preview'}),
				evalScripts: true
			});
		});
	});
	
	$$('.link-post-comment').each(function(elt){
		elt.observe('click',function(event){
			Event.stop(event);
			Effect.ScrollTo('comment-form',{offset:-17,duration:0.6});
		});
	});
	
	$$('#commentform-comment').each(function(elt){
		elt.observe('focus',function(event){
			Effect.Appear('comments-help',{duration:0.6});
		}).observe('blur',function(event){
			Effect.Fade('comments-help',{duration:0.6});
		});
	});
	
});