	if (typeof Durian == 'undefined') {
		var Durian = {};
	}

	Durian.CHEditor = Class({
		init : function(option) {

			Class.extend(this, {
				//prefix : 'cheditor',
				item : null,
				//editorPath : '/common/js/cheditor/',
				//area : null, // used if item is 'ALL'
				//css : '/common/css/mall_editor.css',
				//action : '/',
				//act : 'common.upload',
				//uploadName : 'file',
				//postName : '__file',
				//width : '',
				//height : ''
				dummy : ''
			}, option || {});
			
			//var url = location.href.split('?')[0];
			//this.domain = url.match(/^([^:]+:\/\/[^\/]+)/)[0];
			//this.css = this.domain + this.css;

			option.editorPath = '/common/js/cheditor/';

			if (this.item) {
				if (this.item == 'ALL') {
					this.area = $(this.area) || document;
					this.item = $a(this.area.getElementsByTagName('textarea'));
				}
				this.applyEditor(this.item, option);
			}
		},
		applyEditor : function(item, option) {
			if (!(item instanceof Array)) {
				item = [item];
			}
			for (var i=0; i<item.length; i++) {
				var obj = $(item[i]);
				if (!obj || !obj.form) {
					// error : invalid item
					continue;
				}

				var editor = new cheditor('_editor_' + i);
				window['_editor_' + i] = editor; // global
				obj.editor = editor;

				if (typeof obj.id == 'undefined' || !obj.id) {
					obj.id = '_editor_' + i + '_textarea';
				}
				editor.inputForm = obj.id;

				var size = Element.getSize(obj);

				Class.extend(editor.config, {
					editorWidth     : size.width + 'px',
					editorHeight    : size.height + 'px',
					editorFontSize  : '9pt',
					editorFontFace  : '굴림',
					editorFontColor : '#000',
					editorBgColor   : '#fff',
					lineHeight      : 1.4,
					editAreaMargin  : '7px',
					tabIndex        : 0,
					//editorPath      : null,
					editorPath      : '/common/js/cheditor/',
					fullHTMLSource  : false,
					outputXhtml     : false,
					xhtmlLang       : 'ko',
					xhtmlEncoding   : 'euc-kr',
					hrefTarget      : '_blank',
					showTagPath     : false,
					toolBarSplit    : false,
					imgMaxWidth     : 640,
					imgBlockMargin  : '5px 0px',
					imgReSize       : true,
					includeHostname : false,
					ieEnterMode     : 'css', // [css, div, br, default]
					useSource       : true,
					usePreview      : false,
					usePrint        : false,
					useUndo         : false,
					useCopy         : false,
					useCut          : false,
					usePaste        : false,
					usePasteFromWord: false,
					useSelectAll    : false,
					useBold         : true,
					useUnderline    : true,
					useStrike       : true,
					useItalic       : true,
					useSuperscript  : false,
					useSubscript    : false,
					useJustifyLeft  : true,
					useJustifyCenter: true,
					useJustifyRight : true,
					useJustifyFull  : true,
					useOrderedList  : true,
					useUnOrderedList: true,
					useOutdent      : false,
					useIndent       : false,
					useFontType     : true,
					useParagraph    : false,
					useFontSize     : true,
					useBackColor    : true,
					useForeColor    : true,
					useBGColor      : false,
					useSChar        : false,
					useHyperLink    : true,
					useUnLink       : false,
					useFlash        : false,
					useMedia        : false,
					useUploadImage  : true,
					useImageLink    : true,
					useBGImage      : false,
					useEmotion      : false,
					useHR           : true,
					autoHeight      : false,
					useTable        : true,
					useBoxStyle     : false,
					useFullScreen   : false,
					usePageBreak    : false,
					useBodyAttribute: false
				}, option || {});
				editor.run();
			}
		}
	});


	///////////////////////////////////////////////////////////////////////////////////////////////////
	// override

	cheditor.prototype.runOrg = cheditor.prototype.run;
	cheditor.prototype.switchEditorModeOrg = cheditor.prototype.switchEditorMode;

	cheditor.prototype.run = function () {
		this.runOrg();

		// customizing
		this.evtEditBlur = this.onEditBlur.bindForEvent(this)
		setTimeout(this.setEditorCallback.bind(this), 500); // prevent IE6 crash
	}

	cheditor.prototype.switchEditorMode = function(selectedMode)
	{
		this.switchEditorModeOrg(selectedMode);

		this.setEditorCallback();
		this.$(this.inputForm).value = this.getValue();
	}

	cheditor.prototype.drawToolbar = function (wrapper) {
		if (this.config.toolBarSplit) {
			var toolbarRow1 = {
				btnPrint : { use : this.config.usePrint, icon : [1,0,22], title : '인쇄', exec : function() { this.doCmd('print', false); }},
				btnUndo : { use : this.config.useUndo, icon : [1,44,22], title : '실행취소', exec : function() { this.doCmd('Undo', false); }},
				btnRedo : { use : this.config.useUndo, title : '되돌리기', icon : [1,88,22], exec :function() { this.doCmd('Redo', false); }},
				btnCopy : { use : this.config.useCopy, icon : [1,132,22], title : '복사', exec : function() { this.doCmd('Copy', false); }},
				btnCut : { use : this.config.useCut, icon : [2,0,22], title : '잘라내기', exec : function() { this.doCmd('Cut', false); }},
				btnPaste : { use : this.config.usePaste, icon : [2,44,22], title : '붙이기', exec : function() { this.doCmd('Paste', false); }},
				btnPasteFromWord : { use : this.config.usePasteFromWord, icon : [10,88,22], title : 'MS워드 붙이기', exec : function() { this.doCmd('PasteFromWord', false); }},
				btnSelectAll : { use : this.config.useSelectAll, icon : [2,88,22], title : '전체 선택', exec : function() { this.doCmd('SelectAll', false); }},
				btnBold : { use : this.config.useBold, icon : [2,132,22], title : '진하게', exec : function() { this.doCmd('Bold', false); }},
				btnUnderline : { use : this.config.useUnderline, icon : [3,0,22], title : '밑줄', exec : function() { this.doCmd('Underline', false); }},
				btnStrike : { use : this.config.useStrike, icon : [3,44,22], title : '취소선', exec : function() { this.doCmd('Strikethrough', false); }},
				btnItalic : { use : this.config.useItalic, icon : [3,88,22], title : '기울임', exec : function() { this.doCmd('Italic', false); }},
				btnSuperscript : { use : this.config.useSuperscript, icon : [3,132,22], title : '위첨자', exec : function() { this.doCmd('Superscript', false); }},
				btnSubscript : { use : this.config.useSubscript, icon : [4,0,22], title : '아래첨자', exec : function() { this.doCmd('Subscript', false); }},
				btnJustifyLeft : { use : this.config.useJustifyLeft, icon : [4,44,22], title : '왼쪽 정렬', exec : function() { this.doCmd('JustifyLeft', false); }},
				btnJustifyCenter : { use : this.config.useJustifyCenter, icon : [4,88,22], title : '가운데 정렬', exec : function() { this.doCmd('JustifyCenter', false); }},
				btnJustifyRight : { use : this.config.useJustifyRight, icon : [4,132,22], title : '오른쪽 정렬', exec : function() { this.doCmd('JustifyRight', false); }},
				btnJustifyFull : { use : this.config.useJustifyFull, icon : [5,0,22], title : '양쪽 정렬', exec : function() { this.doCmd('JustifyFull', false); }},
				btnOrderedList : { use : this.config.useOrderedList, icon : [5,44,22], title : '문단 번호', exec : function() { this.doCmd('InsertOrderedList', false); }},
				btnUnOrderedList : { use : this.config.useUnOrderedList, icon : [5,88,22], title : '글 머리표', exec : function() { this.doCmd('InsertUnOrderedList', false); }},
				btnOutdent : { use : this.config.useOutdent, icon : [5,132,22], title : '왼쪽 여백 줄이기', exec : function() { this.doCmd('Outdent', false); }},
				btnIndent : { use : this.config.useIndent, icon : [6,0,22], title : '왼쪽 여백 늘이기', exec : function() { this.doCmd('Indent', false); }}
			};

			var toolbarRow2 = {
				btnFontType : { use : this.config.useFontType, icon : [8,0,30], title : '글꼴', exec : function(id) { this.showFontTypeMenu(id); }},
				btnParagraph : { use : this.config.useParagraph, icon : [8,44,30], title : '단락', exec : function(id) { this.showParagraphMenu(id); }},
				btnFontSize : { use : this.config.useFontSize, icon : [8,88,30], title : '글꼴 크기', exec : function(id) { this.showFontSizeMenu(id); }},
				btnBoxStyle : { use : this.config.useBoxStyle, icon : [11,0,22], title : '박스', exec : function(id) { this.showBoxStyleMenu(id); }},
				btnBackColor : { use : this.config.useBackColor, icon : [9,88,22], title : '형광펜', exec : function(id) { this.showColorMenu(id, 'backColor'); }},
				btnForeColor : { use : this.config.useForeColor, icon : [9,132,22], title : '글자색', exec : function(id) { this.showColorMenu(id, 'foreColor'); }},
				btnBGColor : { use : this.config.useBGColor, icon : [9,44,22], title : '배경색', exec : function(id) { this.showColorMenu(id, 'BgColor'); }},
				btnSChar : { use : this.config.useSChar, icon : [7,132,22], title : '특수문자', exec : function() { this.windowOpen('schar'); }},
				btnHyperLink : { use : this.config.useHyperLink, icon : [6,44,22], title : '하이퍼링크', exec : function() { this.windowOpen('hyperLink'); }},
				btnUnLink : { use : this.config.useUnLink, icon : [6,88,22], title : '하이퍼링크 취소', exec :function() { this.doCmd('UnLink', false); }},
				btnFlash : { use : this.config.useFlash, icon : [9,0,22], title : '플래쉬', exec : function() { this.windowOpen('flash'); }},
				btnMedia : { use : this.config.useMedia, icon : [6,132,22], title : '미디어', exec : function() { this.windowOpen('media'); }},
				btnUploadImage : { use : this.config.useUploadImage, icon : [7,0,22], title : '사진 넣기', exec : function() { this.windowOpen('imageUpload'); }},
				btnImageLink : { use : this.config.useImageLink, icon : [12,0,22], title : '외부 사진', exec : function() { this.windowOpen('imageUrl'); }},
				btnBGImage : { use : this.config.useBGImage, icon : [11,88,22], title : '배경 패턴', exec : function() { this.windowOpen('bgimage'); }},
				btnEmotion : { use : this.config.useEmotion, icon : [7,88,22], title : '이모티콘', exec : function() { this.windowOpen('emotion'); }},
				btnHR : { use : this.config.useHR, icon : [10,0,22], title : '가로선', exec : function() { this.doCmd('InsertHorizontalRule'); }},
				btnTable : { use : this.config.useTable, icon : [10,44,22], title : '테이블', exec : function() { this.windowOpen('table'); }},
				btnPageBreak : { use : this.config.usePageBreak, icon : [10,132,22], title : '인쇄 페이지 나눔', exec : function() { this.printPageBreak(); }},
				btnMap : { use : this.config.useMap, icon : [11,132,22], title : '지도', exec : function() { this.windowOpen('google_map'); }},
				btnHighLight : { use : this.config.useHighlight, icon : [11,44,22], title : '코드 하일라이트', exec : function() { this.windowOpen('highlight'); }},
				btnFullScreen : { use : this.config.useFullScreen, icon : [7,44,22], title : '전체화면', exec : function() { this.fullScreenMode(); }}
			};
		} else {
			var toolbarRow1 = {
				btnFontType : { use : this.config.useFontType, icon : [8,0,30], title : '글꼴', exec : function(id) { this.showFontTypeMenu(id); }},
				btnParagraph : { use : this.config.useParagraph, icon : [8,44,30], title : '단락', exec : function(id) { this.showParagraphMenu(id); }},
				btnFontSize : { use : this.config.useFontSize, icon : [8,88,30], title : '글꼴 크기', exec : function(id) { this.showFontSizeMenu(id); }},
				btnBoxStyle : { use : this.config.useBoxStyle, icon : [11,0,22], title : '박스', exec : function(id) { this.showBoxStyleMenu(id); }},
				
				btnBold : { use : this.config.useBold, icon : [2,132,22], title : '진하게', exec : function() { this.doCmd('Bold', false); }},
				btnUnderline : { use : this.config.useUnderline, icon : [3,0,22], title : '밑줄', exec : function() { this.doCmd('Underline', false); }},
				btnStrike : { use : this.config.useStrike, icon : [3,44,22], title : '취소선', exec : function() { this.doCmd('Strikethrough', false); }},
				btnItalic : { use : this.config.useItalic, icon : [3,88,22], title : '기울임', exec : function() { this.doCmd('Italic', false); }},
				btnSuperscript : { use : this.config.useSuperscript, icon : [3,132,22], title : '위첨자', exec : function() { this.doCmd('Superscript', false); }},
				btnSubscript : { use : this.config.useSubscript, icon : [4,0,22], title : '아래첨자', exec : function() { this.doCmd('Subscript', false); }},

				btnBackColor : { use : this.config.useBackColor, icon : [9,88,22], title : '형광펜', exec : function(id) { this.showColorMenu(id, 'backColor'); }},
				btnForeColor : { use : this.config.useForeColor, icon : [9,132,22], title : '글자색', exec : function(id) { this.showColorMenu(id, 'foreColor'); }},
				btnBGColor : { use : this.config.useBGColor, icon : [9,44,22], title : '배경색', exec : function(id) { this.showColorMenu(id, 'BgColor'); }},
				
				btnJustifyLeft : { use : this.config.useJustifyLeft, icon : [4,44,22], title : '왼쪽 정렬', exec : function() { this.doCmd('JustifyLeft', false); }},
				btnJustifyCenter : { use : this.config.useJustifyCenter, icon : [4,88,22], title : '가운데 정렬', exec : function() { this.doCmd('JustifyCenter', false); }},
				btnJustifyRight : { use : this.config.useJustifyRight, icon : [4,132,22], title : '오른쪽 정렬', exec : function() { this.doCmd('JustifyRight', false); }},
				btnJustifyFull : { use : this.config.useJustifyFull, icon : [5,0,22], title : '양쪽 정렬', exec : function() { this.doCmd('JustifyFull', false); }},
				btnOrderedList : { use : this.config.useOrderedList, icon : [5,44,22], title : '문단 번호', exec : function() { this.doCmd('InsertOrderedList', false); }},
				btnUnOrderedList : { use : this.config.useUnOrderedList, icon : [5,88,22], title : '글 머리표', exec : function() { this.doCmd('InsertUnOrderedList', false); }},
				btnOutdent : { use : this.config.useOutdent, icon : [5,132,22], title : '왼쪽 여백 줄이기', exec : function() { this.doCmd('Outdent', false); }},
				btnIndent : { use : this.config.useIndent, icon : [6,0,22], title : '왼쪽 여백 늘이기', exec : function() { this.doCmd('Indent', false); }},

				btnSChar : { use : this.config.useSChar, icon : [7,132,22], title : '특수문자', exec : function() { this.windowOpen('schar'); }},
				btnHyperLink : { use : this.config.useHyperLink, icon : [6,44,22], title : '하이퍼링크', exec : function() { this.windowOpen('hyperLink'); }},
				btnUnLink : { use : this.config.useUnLink, icon : [6,88,22], title : '하이퍼링크 취소', exec :function() { this.doCmd('UnLink', false); }},
				btnFlash : { use : this.config.useFlash, icon : [9,0,22], title : '플래쉬', exec : function() { this.windowOpen('flash'); }},
				btnMedia : { use : this.config.useMedia, icon : [6,132,22], title : '미디어', exec : function() { this.windowOpen('media'); }},
				btnUploadImage : { use : this.config.useUploadImage, icon : [7,0,22], title : '사진 넣기', exec : function() { this.windowOpen('imageUpload'); }},
				btnImageLink : { use : this.config.useImageLink, icon : [12,0,22], title : '외부 사진', exec : function() { this.windowOpen('imageUrl'); }},
				btnBGImage : { use : this.config.useBGImage, icon : [11,88,22], title : '배경 패턴', exec : function() { this.windowOpen('bgimage'); }},
				btnEmotion : { use : this.config.useEmotion, icon : [7,88,22], title : '이모티콘', exec : function() { this.windowOpen('emotion'); }},
				btnHR : { use : this.config.useHR, icon : [10,0,22], title : '가로선', exec : function() { this.doCmd('InsertHorizontalRule'); }},
				btnTable : { use : this.config.useTable, icon : [10,44,22], title : '테이블', exec : function() { this.windowOpen('table'); }},
				btnPageBreak : { use : this.config.usePageBreak, icon : [10,132,22], title : '인쇄 페이지 나눔', exec : function() { this.printPageBreak(); }},
				btnMap : { use : this.config.useMap, icon : [11,132,22], title : '지도', exec : function() { this.windowOpen('google_map'); }},
				btnHighLight : { use : this.config.useHighlight, icon : [11,44,22], title : '코드 하일라이트', exec : function() { this.windowOpen('highlight'); }},
				btnFullScreen : { use : this.config.useFullScreen, icon : [7,44,22], title : '전체화면', exec : function() { this.fullScreenMode(); }},

				btnPrint : { use : this.config.usePrint, icon : [1,0,22], title : '인쇄', exec : function() { this.doCmd('print', false); }},
				btnUndo : { use : this.config.useUndo, icon : [1,44,22], title : '실행취소', exec : function() { this.doCmd('Undo', false); }},
				btnRedo : { use : this.config.useUndo, title : '되돌리기', icon : [1,88,22], exec :function() { this.doCmd('Redo', false); }},
				btnCopy : { use : this.config.useCopy, icon : [1,132,22], title : '복사', exec : function() { this.doCmd('Copy', false); }},
				btnCut : { use : this.config.useCut, icon : [2,0,22], title : '잘라내기', exec : function() { this.doCmd('Cut', false); }},
				btnPaste : { use : this.config.usePaste, icon : [2,44,22], title : '붙이기', exec : function() { this.doCmd('Paste', false); }},
				btnPasteFromWord : { use : this.config.usePasteFromWord, icon : [10,88,22], title : 'MS워드 붙이기', exec : function() { this.doCmd('PasteFromWord', false); }},
				btnSelectAll : { use : this.config.useSelectAll, icon : [2,88,22], title : '전체 선택', exec : function() { this.doCmd('SelectAll', false); }}
			};
		}

		var table = document.createElement('table');
		table.border = table.cellPadding = table.cellSpacing = 0;
		var cell_1 = table.insertRow(0).insertCell(0);
		cell_1.align = 'left';
		this.showToolbar(toolbarRow1, cell_1);

		if (this.config.toolBarSplit) {
			var cell_2 = table.insertRow(1).insertCell(0);
			cell_2.align = 'left';
			this.showToolbar(toolbarRow2, cell_2);
		}

		wrapper.appendChild(table);
	}

	///////////////////////////////////////////////////////////////////////////////////////////////////
	// customizing

	cheditor.prototype.setEditorCallback = function()
	{
		if (Util.isIE) {
			this.addEvent(this.editArea, 'blur', this.evtEditBlur);
		} else {
			this.addEvent(this.doc, 'blur', this.evtEditBlur);
		}
	}
	cheditor.prototype.onEditBlur = function()
	{
		this.$(this.inputForm).value = this.getValue();
	}

	cheditor.prototype.getValue = function()
	{
		if (this.currentMode == 'code') {
			return this.makeHtmlContent();
		} else {
			var html = this.getContents();
			html = html.replace (/&amp;lt;/g, '&lt;').replace(/&amp;gt;/g,'&gt;');
			html = this.docSplit(html);

			if (this.config.useBodyAttribute) {
				var szCss = this.doc.body.style.cssText;

				if (typeof szCss !== 'string')
					szCss = this.doc.body.getAttribute('style');

				szCss = szCss.replace(/ margin:(.+?);/ig, "");
				html = '<div style="'+szCss+'">'+html+'</div>';
			}

			return html;
		}
	}
