/**
*@ ClassName : AshHtmlEditor(extends AshEventDispatcher)
 Author : 			An.sehan (www.happyfri.com / plandas@naver.com)
 Creation Date : 	2009.01.05
 Last Modified : 	2009.01.22
 Version : 		0.7
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var AshHtmlEditor=Ash.createClass('AshHtmlEditor',AshEventDispatcher);
AshHtmlEditor.LOADED='loaded';
AshHtmlEditor.SELECTION='selection';
AshHtmlEditor.configToolButtons=function(toolbar,disableClassName){var toolButtons=[],lowEvnts=['onmouseover','onmouseout','onclick'],reconstructLowLevelEvent,setEnable;
	reconstructLowLevelEvent=function(btn){for(var l=lowEvnts.length,p,h,i=0; i<l; i++){p=lowEvnts[i],h=btn[p],btn.__enabled=true,btn.__className=btn.className,btn.__tooltip=btn.title;
			if(h!=null){btn[p]=function(){if(this.__enabled)arguments.callee.original.call(this);
				}
				btn[p].original=h;
			}
		}
	}
	setEnable=function(value){try{var imgs=this.getElementsByTagName('IMG');
			for(var i in imgs)AshUtil.filter.opacity(imgs[i],value?1:0.4);
			this.__enabled=value?true:false;
			this.className=value?this.__className:disableClassName;
			this.title=value?this.__tooltip:'';
		} catch(error){};
	}
	for(var l=toolbar.childNodes.length,c,n,i=0; i<l; i++){c=toolbar.childNodes[i],n=c.nodeName.toUpperCase();
		if(n=='DIV' ||n=='SPAN' ||n=='A' )toolButtons.push(c);
	}
	for(var l=toolButtons.length,btn,i=0; i<l; i++){btn=toolButtons[i];
		btn.setEnable=setEnable;
		reconstructLowLevelEvent(btn);
	}
	return toolButtons;
}
Ash.addPrototype(AshHtmlEditor,{textArea:null,container:null,iframe:null,borderOutLiner:null,doc:null,docAgent:null,
	loaded:false,isWysi:true,range:null,
	rangeText:'',rangeHtmlText:'',rangeStyle:'',
	onLoaded:null,onSelection:null,_onLoaded:function(e){if(this.onLoaded!=null)this.onLoaded(e);
	},_onSelection:function(e){if(this.onSelection!=null)this.onSelection(e);
	},_createIframe:function(doc){var i=doc.createElement("IFRAME");
		i.setAttribute("allowTransparency",true);
		i.setAttribute("frameBorder",0);
		i.setAttribute("scrolling","yes");
		i.setAttribute("wrap","virtual");
		i.style.position='absolute';
		i.style.display='none';
		try{return i;
		}finally{
		}
	},_createBorderOutLiner:function(doc){var d=doc.createElement('DIV');
		d.style.border='solid 1px #aaaaaa';
		d.style.position='absolute';
		try{return d;
		}finally{
		}
	},_draw:function(updateList){if( !this.available())return;
		if( !updateList)updateList={position:true,size:true,display:true,content:true};
		if(updateList.position){this.textArea.style.display='block';  
			var x=this.textArea.offsetLeft,y=this.textArea.offsetTop;
			AshUtil.move(this.iframe,x,y);
			AshUtil.move(this.borderOutLiner,x-1,y-1); 
			if(this.isWysi)this.textArea.style.display='none';
		}
		if(updateList.size){this.textArea.style.display='block';
			var w=this.textArea.offsetWidth,h=this.textArea.offsetHeight;
			AshUtil.resize(this.iframe,w,h);
			AshUtil.resize(this.borderOutLiner,w+1,h+1);
			if(this.isWysi)this.textArea.style.display='none';
		}
		if(updateList.display){this.textArea.style.display=this.isWysi?'none':'block';
			this.iframe.style.display=this.isWysi?'block':'none';
		}
		if(updateList.content){if(this.isWysi)this.doc.body.innerHTML=this.textArea.value;
			else this.textArea.value=this.doc.body.innerHTML;
		}
	},_syncCurrentStatus:function(caller){var updateList={position:true,size:true,display:true,content:true};
		if(this.isWysi==false)updateList.position=updateList.size=false;
		if(caller==this.initialize)updateList.content=false;
		this._draw(updateList);
	},initialize:function(){var own=this,iframesrc,textArea,container,iframe,borderOutLiner,doc,onSelection,onInitializeEvent,checkLoadStatus;
		if(!arguments[0]||arguments[0].nodeName.toLowerCase()!='textarea' )throw new Error("No more can't use this class(AshHtmlEditor)");
		iframesrc=arguments[1];
		textArea=this.textArea=arguments[0];
		container=this.container=this.owner=textArea.parentNode;
		
		borderOutLiner=this.borderOutLiner=this._createBorderOutLiner(document);
		iframe=this.iframe=this._createIframe(document);
		container.insertBefore(borderOutLiner,textArea);
		container.appendChild(iframe);
		textArea.style.border='0px';
		textArea.style.position='absolute';
		onSelection=function(e){own.updateRange();
			own.dispatchEvent(new AshEvent(AshHtmlEditor.SELECTION),{range:own.range,rangeText:own.rangeText,rangeHtmlText:own.rangeHtmlText});
		}
		onInitializeEvent=function(caller){try{if(caller==own.initialize){if(own.loaded)return; 
					own.docAgent=new AshEventDispatcher(own.doc);
					own.docAgent.addEventListener('keydown',onInitializeEvent);
					own.docAgent.addEventListener('keyup',function(e){if(e.ctrlKey&&e.keyCode==65)onSelection(); 
					});
					own.docAgent.addEventListener('mouseup',onSelection);
					if(own.iframe.contentWindow.getSelection)own.rangeStyle='DOM';
					else if(own.doc.selection.createRange)own.rangeStyle='IE';
					own.loaded=true;
					own.dispatchEvent(new AshEvent(AshHtmlEditor.LOADED),{} );
				} 
				else{if(AshUtil.browser.ie){
						var evt=caller,obj=evt.target||evt.srcElement;
						if(evt.keyCode==13){var r=document.selection.createRange(); 
							r.pasteHTML(evt.shiftKey?"<p>":"<br>"); 
							r.select();
							return false;
						}
					}
				}
			} catch(error){};
		}
		
		iframe.contentWindow.document.designMode='on'; 
		if(iframesrc){
			var _ev=new AshEventDispatcher(iframe);
			_ev.addEventListener('load',function(e){doc=own.doc=iframe.contentWindow.document;
				if(doc){doc.designMode='on';
					if(AshUtil.browser.ie)doc.body.contentEditable=true;
					textArea.value=doc.body.innerHTML;
					own._syncCurrentStatus(own.initialize);
					onInitializeEvent(own.initialize);
				}
			});
			iframe.setAttribute("src",iframesrc);
			
		}
		else{doc=this.doc=iframe.contentWindow.document;
			doc.open();
			doc.write('\
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\
			<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">\
			<head>\
				<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\
				<style type="text/css">\
					body { margin:0; padding:0; background-color:#ffffff; color:#666666; font-family:Arial, 돋움, sans-serif; font-size:12px;  line-height:1.6; }\
					input { font-family:Arial, 돋움, sans-serif; font-size:12px;}\
					a:link { text-decoration:none; color:#333333; }\
					a:visited { text-decoration:none; color:#333333; }\
					a:active { text-decoration:none; color:#333333; }\
					a:hover { text-decoration:underline; position:relative; left:1px; top:1px; color:#000000; }\
				</style>\
			</head>\
			<body>\
			</body>\
			</html>');
			doc.close();
			if(AshUtil.browser.ie)doc.body.contentEditable=true;
			
			setTimeout(function(){own._syncCurrentStatus();
				onInitializeEvent(own.initialize);
			},31);
		}
		this.addEventListener(AshHtmlEditor.LOADED,this._onLoaded);
		this.addEventListener(AshHtmlEditor.SELECTION,this._onSelection);
	}
});
AshHtmlEditor.prototype.available=function(){if( !this.textArea||!this.iframe||!this.doc)return false;
	return true;
}
AshHtmlEditor.prototype.redraw=function(){this._draw();
}
AshHtmlEditor.prototype.resize=function(w,h){AshUtil.resize(this.textArea,w,h);
	this._draw({position:true,size:true});
}
AshHtmlEditor.prototype.resizeContainer=function(w,h,autoFix){AshUtil.resize(this.container,w,h);
	if(autoFix){var margin={x:6,y:6};
		if(AshUtil.browser.ff)margin.x=4,margin.y=5;
		if(AshUtil.browser.opera)margin.x=6,margin.y=6;
		if(AshUtil.browser.safari)margin.x=6,margin.y=6;
		this.resize(w-margin.x,h-margin.y);
	}
}
AshHtmlEditor.prototype.reboundContainer=function(x,y,w,h,autoFix){AshUtil.move(this.container,x,y);
	this.resizeContainer(w,h,autoFix);
}
AshHtmlEditor.prototype.visible=function(value){if( !this.loaded)return;
	if(value)this._draw({display:true});
	else{this.iframe.style.display='none';
		this.textArea.style.display='none';
	}
}
AshHtmlEditor.prototype.show=function(){this.visible(true);
}
AshHtmlEditor.prototype.hide=function(){this.visible(false);
}
AshHtmlEditor.prototype.setStyle=function(prop,value){try{if(prop&&value)this.doc.body.style[prop]=value;
	} catch(error){};
}
AshHtmlEditor.prototype.setCSSText=function(value){try{this.doc.body.style.cssText+=';' +value;
	} catch(error){};
}
AshHtmlEditor.prototype.setHtmlValue=function(value){if(value!=null)this.textArea.value=this.doc.body.innerHTML=value;
}
AshHtmlEditor.prototype.getHtmlValue=function(){if(this.isWysi)return this.doc.body.innerHTML;
	return this.textArea.value;
}
AshHtmlEditor.prototype.setBorderOutLinerColor=function(color){this.borderOutLiner.style.border='solid 1px '+color;
}
AshHtmlEditor.prototype.wysiwygMode=function(value){this.isWysi=value?true:false;
	this._syncCurrentStatus();
}
AshHtmlEditor.prototype.command=function(command,userInterface,value){if(this.doc)this.doc.execCommand(command,userInterface,value);
}
AshHtmlEditor.prototype.customCommand=function(insertNode){if(!this.range)return;
	this.clearSelection();
	try{var range=this.range||this.getRange();
		if(this.rangeStyle=='DOM'){var container=range.startContainer;
			var start=range.startOffset;
			range.deleteContents();
			range=this.doc.createRange(); 
			if(container.nodeType==1){container.insertBefore(insertNode,container.childNodes[start]);
			}
			else if(container.nodeType==3)
			{if(insertNode.nodeType==1){var parent=container.parentNode;
					var text=container.nodeValue;
					var beforeNode=this.doc.createTextNode( text.substr(0,start));
					var afterNode=this.doc.createTextNode( text.substr(start));
					parent.insertBefore(afterNode,container);
					parent.insertBefore(insertNode,afterNode);
					parent.insertBefore(beforeNode,insertNode);
					parent.removeChild(container);
				}
				else if(insertNode.nodeType==3)
				{container.insertData(start,insertNode.nodeValue);
				}
			}
			range.selectNode(insertNode);
		}
		else if(this.rangeStyle=='IE'){var l=range.text.length,htmlText;
			htmlText=insertNode.outerHTML;
			if(insertNode.nodeType==3)htmlText=insertNode.nodeValue;
			range.pasteHTML(htmlText);
			range.moveStart('character',-l);
			range.moveEnd('character',0);
		}
		if(this.rangeText.length!=0)this.setSelection(range);
	}
	catch(error){};
}
AshHtmlEditor.prototype.setSelection=function(range,clearMode){try{if(!range)return;
		if(this.rangeStyle=='DOM'){var sel=this.iframe.contentWindow.getSelection();
			sel.removeAllRanges();
			sel.addRange(range);
		}
		else if(this.rangeStyle=='IE'){range.select();
		}
		 
		if(!clearMode)this.updateRange();
	} catch(error){};
}
AshHtmlEditor.prototype.clearSelection=function(){try{this.setSelection( (this.rangeStyle=='DOM'?this.doc.createRange():this.doc.selection.createRange()),true);
	} catch(error){};
}
AshHtmlEditor.prototype.updateRange=function(){this.range=this.getRange();
	this.rangeText=this.getRangeText(this.range)||'';
	this.rangeHtmlText=this.getRangeHtmlText(this.range)||'';
}
AshHtmlEditor.prototype.getRange=function(){try{if(this.rangeStyle=='DOM'){var sel=this.iframe.contentWindow.getSelection();
			return sel.getRangeAt(0);
		}
		else if(this.rangeStyle=='IE'){return this.doc.selection.createRange();
		}
	} catch(error){};
	return null;
}
AshHtmlEditor.prototype.getRangeParentNode=function(){var node=null;
	try{var range=this.range||this.getRange();
		if(this.rangeStyle=='DOM'){node=range.commonAncestorContainer;
			if(node.nodeType==3)node=node.parentNode;
		}
		else if(this.rangeStyle=='IE')node=range.parentElement();
		if(node==document.body)node=null;
	} catch(error){};
	return node;
}
AshHtmlEditor.prototype.getRangeHtmlText=function(){try{var range=this.range||this.getRange();
		if(this.rangeStyle=='DOM'){var span=this.doc.createElement('SPAN');
			span.appendChild(range.cloneContents());
			return span.innerHTML;
		}
		else if(this.rangeStyle=='IE')return range.htmlText;
	} catch(error){};
	return'';
}
AshHtmlEditor.prototype.getRangeText=function(){try{var range=this.range||this.getRange();
		if(this.rangeStyle=='DOM')return range.toString();
		else if(this.rangeStyle=='IE')return range.text;
	} catch(error){};
	return'';
}
AshHtmlEditor.prototype.makeRichStyle=function(styleType,value){var make=function(obj,value){if(obj.nodeType==1&&obj.tagName.toUpperCase()!='BR' )obj.style[styleType]=value;
		if(obj.hasChildNodes())for(var l=obj.childNodes.length,i=0; i<l; i++)make(obj.childNodes[i],value);
		return obj;
	}
	var span=this.doc.createElement('SPAN');
	span.innerHTML=this.rangeHtmlText;
	make(span,value);
	return span;
}
AshHtmlEditor.prototype.font=function(value){this.command('FontName',false,value?value:'Arial');
}
AshHtmlEditor.prototype.fontSize=function(value){var ele=this.makeRichStyle('fontSize',value+'px');
	this.customCommand(ele);
}
AshHtmlEditor.prototype.bold=function(){this.command('Bold',false,null);
}
AshHtmlEditor.prototype.italic=function(){this.command('Italic',false,null);
}
AshHtmlEditor.prototype.underline=function(){this.command('Underline',false,null);
}
AshHtmlEditor.prototype.strikeThrough=function(){this.command('StrikeThrough',false,null);
}
AshHtmlEditor.prototype.foreColor=function(value){this.setSelection(this.range);
	this.command('ForeColor',false,value);
}
AshHtmlEditor.prototype.backColor=function(value){this.setSelection(this.range);
	try{this.command('hiliteColor',false,value);
	}catch(error){this.command('BackColor',false,value);
	}
}
AshHtmlEditor.prototype.justifyLeft=function(){this.command('JustifyLeft',false,null);
}
AshHtmlEditor.prototype.justifyCenter=function(){this.command('JustifyCenter',false,null);
}
AshHtmlEditor.prototype.justifyRight=function(){this.command('JustifyRight',false,null);
}
AshHtmlEditor.prototype.justifyFull=function(){this.command('JustifyFull',false,null);
}
AshHtmlEditor.prototype.letterSpacing=function(value){var ele=this.makeRichStyle('letterSpacing',value+'px');
	this.customCommand(ele);
}
AshHtmlEditor.prototype.lineHeight=function(value){var ele=this.getRangeParentNode();
	if(ele)ele.style.lineHeight=value+'px';
}
AshHtmlEditor.prototype.outdent=function(){this.command('Outdent',false,null);
}
AshHtmlEditor.prototype.indent=function(){this.command('Indent',false,null);
}
AshHtmlEditor.prototype.createLink=function(value,target){if(target){this.setSelection(this.range);
		var a=this.doc.createElement('A');
		if(value.search(/http:\/\//i)==-1)value='http://'+value;
		a.href=value;
		a.target=target;
		a.appendChild(this.doc.createTextNode(this.rangeText));
		this.customCommand(a);
	}
	else this.command('CreateLink',false,value);
}
AshHtmlEditor.prototype.insertOrderedList=function(){
	this.command('InsertOrderedList',false,null);
}
AshHtmlEditor.prototype.insertUnorderedList=function(){
	this.command('InsertUnorderedList',false,null);
}
AshHtmlEditor.prototype.insertHorizontalRule=function(){this.command('InsertHorizontalRule',false,null);
}
AshHtmlEditor.prototype.undo=function(){this.command('Undo',false,null);
}
AshHtmlEditor.prototype.redo=function(){this.command('Redo',false,null);
}
AshHtmlEditor.prototype.selectAll=function(){this.command('SelectAll',false,null);
}
AshHtmlEditor.prototype.cut=function(){this.command('Cut',false,null);
}
AshHtmlEditor.prototype.copy=function(){this.command('Copy',false,null);
}
AshHtmlEditor.prototype.paste=function(){this.command('Paste',false,null);
}
AshHtmlEditor.prototype.insertCharater=function(value){var scroll=window.top.document.documentElement.scrollTop;
	var t=this.doc.createTextNode(value);
	this.customCommand(t);
	window.top.document.documentElement.scrollTop=scroll; 
}
AshHtmlEditor.prototype.insertImage=function(src){var scroll=window.top.document.documentElement.scrollTop;
	try{var img=this.doc.createElement('IMG');
		img.src=src;
		this.customCommand(img);
	}catch(error){};
	window.top.document.documentElement.scrollTop=scroll; 
}
AshHtmlEditor.prototype.setCustomClass=function(tagName,className){try{var ele=this.doc.createElement(tagName||'span');
		ele.className=className;
		ele.innerHTML=this.rangeHtmlText;
		this.customCommand(ele);
	}catch(error){};
}
var AshEditorPanel=Ash.createClass('AshEditorPanel',AshMotionAgent);
AshEditorPanel.MINIMUM='minimum';
AshEditorPanel.NORMAL='normal';
AshEditorPanel.MAXIMUM='maximum';
AshEditorPanel.OK='ok';
AshEditorPanel.CANCEL='cancel';
AshEditorPanel.SHOW='show';
AshEditorPanel.HIDE='hide';
Ash.addPrototype(AshEditorPanel,{
	container:null,editor:null,body:null,dragbar:null,toolbar:null,submitbar:null,resizer:null,resizeGap:10,dragbarHeight:30,submitbarHeight:25,toolbarSize:80,
	minWidth:20,minHeight:20,defaultWidth:0,defaultHeight:0,currentWidth:0,currentHeight:0,isMaximum:false,client:null,
	toolbarDirection:'n',
	onMinimum:null,onNormal:null,onMaximum:null,onOk:null,onCancel:null,onShow:null,onHide:null,_onMinimum:function(e){if(this.onMinimum)this.onMinimum(e);},_onNormal:function(e){if(this.onNormal)this.onNormal(e);},_onMaximum:function(e){if(this.onMaximum)this.onMaximum(e);},_onOk:function(e){if(this.onOk)this.onOk(e);},_onCancel:function(e){if(this.onCancel)this.onCancel(e);},_onShow:function(e){if(this.onShow)this.onShow(e);},_onHide:function(e){if(this.onHide)this.onHide(e);},_castEvent:function(eventType,params){if(this.client){if( eventType==AshEditorPanel.OK)this.client.innerHTML=this.editor.getHtmlValue();
			if(this.client.onEditorPanelCallback!=null)this.client.onEditorPanelCallback(eventType);
		}
		this.dispatchEvent(new AshEvent(eventType),params);
	},_draw:function(updateList){var rg=this.resizeGap,dh=this.dragbarHeight,sh=this.submitbarHeight,ts=this.toolbarSize;
		if(!updateList)updateList={size:true,toolbarDirection:true};
		if(updateList.size||updateList.toolbarDirection){this.currentWidth=parseInt(AshUtil.getStyle(this.container,'width'))||this.container.offsetWidth;
			this.currentHeight=parseInt(AshUtil.getStyle(this.container,'height'))||this.container.offsetHeight;
			AshUtil.rebound(this.dragbar,rg,rg,this.currentWidth-(rg*2),dh);
			
			switch(this.toolbarDirection){case'n':default:AshUtil.rebound(this.toolbar,rg,rg+dh,this.currentWidth-(rg*2),ts);
					this.editor.reboundContainer( rg+1,rg+dh+ts+1,this.currentWidth-(rg*2),this.currentHeight-(rg*2+dh+ts+sh-1),true); 
					break;
				case'e':ts*=1.7;
					AshUtil.rebound(this.toolbar,this.currentWidth-rg-ts,rg+dh,ts,this.currentHeight-(rg*2+dh+sh));
					this.editor.reboundContainer( rg+1,rg+dh+1,this.currentWidth-(rg*2+ts),this.currentHeight-(rg*2+dh+sh-1),true); 
					break;
				case's':AshUtil.rebound(this.toolbar,rg,this.currentHeight-(rg+ts+sh),this.currentWidth-(rg*2),ts);
					this.editor.reboundContainer( rg+1,rg+dh+1,this.currentWidth-(rg*2),this.currentHeight-(rg*2+dh+ts+sh-1),true); 
					break;
				case'w':ts*=1.7;
					AshUtil.rebound(this.toolbar,rg,rg+dh,ts,this.currentHeight-(rg*2+dh+sh));
					this.editor.reboundContainer( rg+ts+1,rg+dh+1,this.currentWidth-(rg*2+ts),this.currentHeight-(rg*2+dh+sh-1),true); 
					break;
			}
			AshUtil.rebound(this.submitbar,rg,this.currentHeight-(rg+sh),this.currentWidth-(rg*2),sh);
		}
	},initialize:function()
	{var own=this,container,editor,body,dragbar,toolbar,submitbar,resizer;
		var onEditorLoaded,onResizeStart,onResizeStart,onResizeStop,initMotionEventHadler;
		if(!arguments[0])throw Error('Can not generate the class-EditorPanel');
		container=this.container=this.owner=arguments[0];
		editor=this.editor=new AshHtmlEditor( (AshUtil.getChildByName(container,'body').getElementsByTagName('textarea'))[0],arguments[1]);
		body=this.body=editor.container;
		dragbar=this.dragbar=AshUtil.getChildByName(container,'dragbar');
		toolbar=this.toolbar=AshUtil.getChildByName(container,'toolbar');
		submitbar=this.submitbar=AshUtil.getChildByName(container,'submitbar');
		resizer=this.resizer=new AshResize(container);
		if(!container||!editor||!body||!dragbar||!toolbar||!submitbar)return;
		dragbar.setAttribute('ashdragtarget',container.getAttribute('id'));
		dragbar.setAttribute('ashdrag','true');
		dragbar.style.cursor='move';
		dragbar.style.position='absolute';
		toolbar.style.position='absolute';
		body.style.position='absolute';
		submitbar.style.position='absolute';
		toolbar.style.overflow='hidden';
		toolbar.style.zIndex=1;
		body.style.zIndex=2;
		submitbar.style.zIndex=3;
		dragbar.style.zIndex=4;
		this.defaultWidth=parseInt(AshUtil.getStyle(container,'width'))||container.offsetWidth;
		this.defaultHeight=parseInt(AshUtil.getStyle(container,'height'))||container.offsetHeight;
		onEditorLoaded=function(e){this.docAgent.addEventListener('mousedown',function(e2){AshPopup.manager.clear();
			});
			this.docAgent.addEventListener('mouseup',function(e2){resizer.abort();
			});
		}
		onResizeStart=function(e){dragbar.style.display=toolbar.style.display=body.style.display=submitbar.style.display='none';
		}
		onResizing=function(e){}
		onResizeStop=function(e){dragbar.style.display=toolbar.style.display=body.style.display=submitbar.style.display='block';
			own.redraw();
		}
		initMotionEventHadler=function(){var width=own.getMotioner('width'),height=own.getMotioner('height'),all=own.getMotioner('all');
			var onStart=function(e){onResizeStart();};
			var onStop=function(e){onResizeStop();};
			width.addEventListener(AshMotioner.START,onStart); width.addEventListener(AshMotioner.FINISHED,onStop);
			height.addEventListener(AshMotioner.START,onStart); height.addEventListener(AshMotioner.FINISHED,onStop);
			all.addEventListener(AshMotioner.START,onStart); all.addEventListener(AshMotioner.FINISHED,onStop);
		}
		dragbar.ondblclick=function(e){own.setToggle();
		}
		editor.addEventListener(AshHtmlEditor.LOADED,onEditorLoaded);
		resizer.addEventListener(AshResize.RESIZE_START,onResizeStart);
		resizer.addEventListener(AshResize.RESIZING,onResizing);
		resizer.addEventListener(AshResize.RESIZE_STOP,onResizeStop);
		resizer.start();
		this.addEventListener(AshEditorPanel.MINIMUM,this._onMinimum);
		this.addEventListener(AshEditorPanel.NORMAL,this._onNormal);
		this.addEventListener(AshEditorPanel.MAXIMUM,this._onMaximum);
		this.addEventListener(AshEditorPanel.OK,this._onOk);
		this.addEventListener(AshEditorPanel.CANCEL,this._onCancel);
		this.addEventListener(AshEditorPanel.SHOW,this._onShow);
		this.addEventListener(AshEditorPanel.HIDE,this._onHide);
		this.setMinSize(200,250);
		this.setResizeGap(5,true);
		this.redraw();
		initMotionEventHadler();
	}
});
AshEditorPanel.prototype.setClient=function(client){if(!client)return;
	this.client=client;
	try{var list=['color','fontStyle','fontSize','fontFamily','fontWeight','lineHeight','padding','margin','letterSpacing','wordSpacing'],list2=['color','font-style','font-size','font-family','font-weight','line-height','padding','margin','letter-spacing','word-spacing'];
		for(var l=list.length,cssText='',i=0; i<l; i++)cssText+=';'+(list2[i]+':'+AshUtil.getStyle(this.client,list[i]));
		this.editor.setCSSText(cssText);
		this.editor.setHtmlValue(client.innerHTML);
	}
	catch(error){};
}
AshEditorPanel.prototype.show=function(client,defaultWidth,defaultHeight){this.container.style.display='block';
	this.setClient(client);
	if(defaultWidth){this.defaultWidth=defaultWidth;
		this.container.style.width=defaultWidth+'px';
	}
	if(defaultHeight){this.defaultHeight=defaultHeight;
		this.container.style.height=defaultHeight+'px';
	}
	if(defaultWidth||defaultHeight)this.setNormal();
	else this.editor.redraw();
	AshDepthManager.manager.front(this.container);
	this._castEvent(AshEditorPanel.SHOW);
}
AshEditorPanel.prototype.hide=function(){this.hide31();
	this._castEvent(AshEditorPanel.HIDE);
}; AshEditorPanel.prototype.hide31=function(){this.container.style.display='none';};
AshEditorPanel.prototype.redraw=function(){this._draw();
}
AshEditorPanel.prototype.ok=function(){this.hide31();
	this._castEvent(AshEditorPanel.OK);
}
AshEditorPanel.prototype.cancel=function(){this.hide31();
	this._castEvent(AshEditorPanel.CANCEL);
}
AshEditorPanel.prototype.setResizeGap=function(value,skipDraw){this.resizeGap=this.resizer.sensitivity=value||10;
	if(!skipDraw)this._draw({size:true});
}
AshEditorPanel.prototype.setDragbarHeight=function(value,skipDraw){this.dragbarHeight=value||30;
	if(!skipDraw)this._draw({size:true});
}
AshEditorPanel.prototype.setSubmitbarHeight=function(value,skipDraw){this.submitbarHeight=value||30;
	if(!skipDraw)this._draw({size:true});
}
AshEditorPanel.prototype.setToolbarSize=function(value,skipDraw){this.toolbarSize=value||100;
	if(!skipDraw)this._draw({size:true});
}
AshEditorPanel.prototype.setToolbarDirection=function(direction,skipDraw){if(direction==this.toolbarDirection)return;
	this.toolbarDirection=direction;
	if(!skipDraw)this._draw({toolbarDirection:true});
}
AshEditorPanel.prototype.setMinSize=function(width,height){this.resizer.minWidth=this.minWidth=width||20;
	this.resizer.minHeight=this.minHeight=height||20;
}
AshEditorPanel.prototype.setMinimum=function(duration,engin)
{var w=this.minWidth,h=this.minHeight;
	var x=document.documentElement.clientWidth/2-w/2,y=document.documentElement.clientHeight/2-h/2;
	var sinfo=AshUtil.document.scrollInfo();
	if(w!=this.currentWidth||h!=this.currentHeight){var props={x:sinfo.left+x,y:sinfo.top+y,width:w,height:h};
		this.tween(props,duration||30,engin||'back.inout');
		this.isMaximum=false;
		this._castEvent(AshEditorPanel.MINIMUM,props);
	}
}
AshEditorPanel.prototype.setNormal=function(duration,engin)
{var w=this.defaultWidth,h=this.defaultHeight;
	var x=document.documentElement.clientWidth/2-w/2,y=document.documentElement.clientHeight/2-h/2;
	var sinfo=AshUtil.document.scrollInfo();
	var props={x:sinfo.left+x,y:sinfo.top+y,width:w,height:h};
	this.tween(props,duration||30,engin||'back.inout');
	if(w!=this.currentWidth||h!=this.currentHeight){this.isMaximum=false;
		this._castEvent(AshEditorPanel.NORMAL,props);
	}
}
AshEditorPanel.prototype.setMaximum=function(duration,engin)
{var x=1,y=1,w=document.documentElement.clientWidth-10,h=document.documentElement.clientHeight-20;
	var sinfo=AshUtil.document.scrollInfo();
	if(w!=this.currentWidth||h!=this.currentHeight){var props={x:sinfo.left+x,y:sinfo.top+y,width:w,height:h};
		this.tween(props,duration||20,engin||'back.in');
		this.isMaximum=true;
		this._castEvent(AshEditorPanel.MAXIMUM,props);
	}
}
AshEditorPanel.prototype.setToggle=function(){this.isMaximum?this.setNormal():this.setMaximum();
}