$.fn.textarea2fck = function(o) {
	var defaults = {
		height: 200,
		width: 425,
		toolBarSet: "Basic",
		basePath: "/fckeditor/",
		log: true
	};
	o = $.extend(defaults, o);	
	if(typeof FCKeditor == "undefined") {
		var s = document.createElement("script");
		s.type="text/javascript";
		s.src="/fckeditor/fckeditor.js";
		$("head").append(s);
	};	
	$(this).each(function() {
		var name = $(this).attr("name");
		var wrapper = "<div id='"+name+"-fck' class='fckeditor_div'></div>";
		$(this).wrap($(wrapper));		
		var oFCKeditor = new FCKeditor(name);
		oFCKeditor.BasePath = o.basePath;
		oFCKeditor.ToolbarSet = o.toolBarSet;
		oFCKeditor.Height = o.height;
		oFCKeditor.Width = o.width;
		oFCKeditor.ReplaceTextarea();
	});
	$(this).parents("form").find("[name='submit']").mouseup(function(e) {
		FCKContentTotextArea();
	});
	$(this).parents("form").find("input").keypress(function(e) {
		if(e.keyCode == 13) {
			e.preventDefault();
			FCKContentTotextArea();
		}
	});
	FCKContentTotextArea = function() {
		$(".fckeditor_div").each(function() {
		    var ta = $("[name="+$(this).attr("id").split("-fck")[0]+"]");
		    var content = FCKeditorAPI.GetInstance($(this).attr("id").split("-fck")[0]).GetHTML();
		    $(ta).val(content);
		});
	};
	qlog = function(m) {
		if(o.log) {
			if(window.console && console.log) {
				console.log(m);
			}else {
				alert(m);
			}
		}
	};
	return $(this);	
};
