	new function($) {
	  $.fn.setCursorPosition = function(pos) {
		if ($(this).get(0).setSelectionRange) {
		  $(this).get(0).setSelectionRange(pos, pos);
		} else if ($(this).get(0).createTextRange) {
		  var range = $(this).get(0).createTextRange();
		  range.collapse(true);
		  range.moveEnd('character', pos);
		  range.moveStart('character', pos);
		  range.select();
		}
	  }
	}(jQuery);
	
	$(function () {
		$('#submitForm').submit(function () {
			$('#submitButton').attr('disabled', 'disabled');
			//alert($('#submitForm').serialize());
			//return false;
		});
		$('.commentButton').click(function () {
			var editor = $('#editor');
			var editorContainer = $('#editorContainer');
			var textarea = editor.find('textarea');
			if (editor.parent().attr('id') !== 'editorContainer') {
				//textarea.val('');
				editorContainer.append(editor);
				editor.find('#parentid').val('0');
				editor.show();
			} else {
				if (editor.is(':hidden')) {
					editor.show();
				} else {
					editor.hide();
				}
			}
			textarea.focus();
			textarea.setCursorPosition(0);
			return false;
		});
		$('.answerButton').click(function () {
			var data = $(this).reldata();
			if (data) {
				var editor = $('#editor');
				var textarea = editor.find('textarea');
				editor.find('#parentid').val(data.id);
				var comment = $(this).closest('.comment');
				var commentInner = $(this).closest('.comment_inner');
				if (editor.closest('.comment').attr('id') !== comment.attr('id')) {
					editor.show();
					textarea.prepend(data.login + ', ');
					commentInner.append(editor);
				} else {
					if (editor.is(':hidden')) {
						editor.show();
					} else {
						editor.hide();
					}
				}
				textarea.focus();
				textarea.setCursorPosition(textarea.val().length);
			}
			return false;
		});
	});
