/**
 * jeditor 1.0 fckeidtor loader Author: neil.mao Email: maoxiang@gmail.com
 * 2009-02-06 更新到fckeditor 2.6.4
 */
( function($) {

	var fckeditor_root = "/plus/fckeditor/";
	var fckeditor_js = fckeditor_root + "fckeditor.js";

	// 加载fckeditor.js
	document.write('<script type="text/javascript" src="' + fckeditor_js + '"></script>');

	$.fn.loadEditor = function(type) {
		return this.each( function() {
			try {
				// 如果未定义id，则不加载
				if (undefined == this.id || !this.id.length) return;
				var value = $(this).html();
				$(this).html("Please wait a moment for the initialization....");
				var oFCKeditor = new FCKeditor(this.id);
				oFCKeditor.BasePath = fckeditor_root;
				oFCKeditor.Width = $(this).width();
				oFCKeditor.Height = $(this).height();
				oFCKeditor.Value = value;
				switch (type) {
					case 0: // 标准配置
						oFCKeditor.Config['CustomConfigurationsPath'] = fckeditor_root + 'fckconfig.js';
						oFCKeditor.ToolbarSet = 'Default';
						break;
					case 1: // 最小配置
						oFCKeditor.Config['CustomConfigurationsPath'] = fckeditor_root + 'answer.fckconfig.js';
						oFCKeditor.ToolbarSet = 'answer';
						break;
				}
				$(this).html(oFCKeditor.CreateHtml());
			} catch (e) {
				alert("Error:" + e.message);
			}
		});
	};
	$.fn.getEditorHtml = function() {
		if (this.length > 0) {
			var o = this[0];
			if (undefined == o.id || !o.id.length)
				return;
			var oEditor = FCKeditorAPI.GetInstance(o.id);
			// Get the editor contents in XHTML.
			// "true" means you want it formatted.
			return (oEditor.GetXHTML(true));
		}
		;
		return "";
	};

	$.fn.setEditorHtml = function(html) {
		if (this.length > 0) {
			var o = this[0];
			if (undefined == o.id || !o.id.length)
				return;
			var oEditor = FCKeditorAPI.GetInstance(o.id);
			// Get the editor contents in XHTML.
			// "true" means you want it formatted.
			oEditor.InsertHtml(html);
		}
		;
	};
})(jQuery);
