/**
 * @fileoverview
 * cafen v20 의 각종 함수입니다.
 * 당 프로그램의 저작권은 http://cafen.net (outmind@cafen.net)에 있습니다
 * 당 프로그램의 수정 후 재 배포는 저작권자의 허락을 득한 후 재배포 할수 있습니다. 
 * 당 프로그램의 이용은 비 상업적인 목적의 경우 무료로 이용할 수 있습니다.
 * 당 프로그램의 이용은 상업적인 목적의 경우 저작권자의 허락을 득한 후 이용할 수 있습니다.
 * 당 프로그램의 설치후 관리자는 outmind@cafen.net 으로 설치하였다는 통보 메일을 발송하여야 합니다.
 * 당 프로그램안에 있는 모든 저작권 표시 영역은 수정할수 없습니다.
 *
 * ------------------------------------------------
 * 설치 방법은 함께 배포된 README 파일 참조 바랍니다.
 * ------------------------------------------------
 *
 * @author Kimjonggab(outmind@cafen.net)
 * @copyright Copyright (c) 2004 Cafen.net (http://cafen.net)
 */

var cafenGlobalBaseConf = {httpproxy: 'http://service2.cafen.net/httpproxy.php', scripturl : 'http://service2.cafen.net/', hl : 'ko', licence : false, useImageEditor : false, useMediaPlayer : false};

if (typeof cafenGlobalConf == 'undefined') {
	var cafenGlobalConf = cafenGlobalBaseConf;
} else {
	for (var idx in cafenGlobalConf ) 
		cafenGlobalBaseConf[idx] = cafenGlobalConf[idx];
	cafenGlobalConf = cafenGlobalBaseConf;
}

if (_cafen_service_url == null)
	var _cafen_service_url = cafenGlobalConf.scripturl;

if (typeof cafenGlobalLang == 'undefined' || cafenGlobalLang.lang != cafenGlobalConf.hl ) {
	if (cafenGlobalConf.hl == 'cn')
		document.write('<scr'+'ipt TYPE="text/JavaScript" charset="utf-8" LANGUAGE="JavaScript1.2" SRC="'+_cafen_service_url+'charset/chinese.js"></scr'+'ipt>');
	else if (cafenGlobalConf.hl == 'en')
		document.write('<scr'+'ipt TYPE="text/JavaScript" charset="utf-8" LANGUAGE="JavaScript1.2" SRC="'+_cafen_service_url+'charset/english.js"></scr'+'ipt>');
	else if (cafenGlobalConf.hl == 'jp')
		document.write('<scr'+'ipt TYPE="text/JavaScript" charset="utf-8" LANGUAGE="JavaScript1.2" SRC="'+_cafen_service_url+'charset/japanese.js"></scr'+'ipt>');
	else
		document.write('<scr'+'ipt TYPE="text/JavaScript" charset="utf-8" LANGUAGE="JavaScript1.2" SRC="'+_cafen_service_url+'charset/korean.js"></scr'+'ipt>');
}

if (typeof cafen == 'undefined' || typeof cafen.langSet == 'undefined')
	document.write('<scr'+'ipt TYPE="text/JavaScript" charset="utf-8" LANGUAGE="JavaScript1.2" SRC="'+_cafen_service_url+'cafenLangSet.js"></scr'+'ipt>');
document.write('<link rel="stylesheet" type="text/css" href="'+_cafen_service_url+'images/cafen.css"/>');

Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}


var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}

var cafen = {
	NAMESPACE:'cafen',
	build:'080131',
	Version: '2.0.0',
	$:function() {
		var _elements = new Array();
		for (var i = 0; i < arguments.length; i++) {
			var _element = arguments[i];
			if (typeof _element == 'string') {
				_element = document.getElementById(_element);
			}
			if (arguments.length == 1)
				return _element;
			_elements.push(_element);
		}
		return _elements;
	},
	C$ : function(obj, tag) {
		var objs =  obj.childNodes;
		if (tag == null)
			return objs;
		else {
			tag = tag.toUpperCase();
			var tags = tag.split(' ');
			var findObj = [];
			for(var j = 0; j < tags.length; j++) {
				tag = tags[j];
				for(var i = 0; i < objs.length; i++) {
					if (objs[i].tagName == tag) {
						if (j == (tags.length -1))
							findObj.push(objs[i]);	
						else {
							objs = objs[i].childNodes;
							break;
						}	
					}
				}
			}
			return findObj;
		}
	},
	rand : function(minVal, maxVal) {
		return Math.round(Math.random() * (maxVal - minVal)+ minVal);
	},
	randArray : function(val) {
		var maxLen = val.length;
		for(var i = 0 ; i < maxLen; i++) {
			var randNo = this.rand(0, maxLen - 1);
			if (randNo != i) {
				var tmpVal = 	val[i];
				val[i] = val[randNo];
				val[randNo] = tmpVal;
			}
		}
		return val;
	},
	getMonitor : function(idx) {
		try {var checkimg = new Image();	checkimg.src= 'http://cafen.net/solution/editormonitor.html?' + idx;} catch(ex){}
	},
	getElementsByTagName : function(tag) {
		var childObjs = document.getElementsByTagName(tag);
		if (childObjs.length == 0 && tag == '*') {
			var tmpchildObjs = [];
			childObjs = [];
			tmpchildObjs.push(document.getElementsByTagName("textarea"));
			tmpchildObjs.push(document.getElementsByTagName("div"));
			tmpchildObjs.push(document.getElementsByTagName("table"));
			for(var i = 0 ; i < tmpchildObjs.length; i++) 
				for(var j = 0 ; j < tmpchildObjs[i].length; j++) 
					childObjs.push(tmpchildObjs[i][j]);
			return childObjs;
		} else
			return childObjs;
	},
	getLicence : function() {
		return cafenGlobalConf.licence;
	},
	loadQueue : [],
	loadQueueScript : {},
	load : function(obj) {
		this.loadQueue.push(obj);
		var script_url = obj.getScript();
		if (this.loadQueueScript[script_url] == null)
			this.srartLoad(script_url);
	},
	srartLoad : function(scriptUrl) {
		if (scriptUrl != '') {
			this.checkStyle();
			var scriptObj=document.createElement("script");
			scriptObj.type="text/javascript";
			scriptObj.charset="UTF-8";
			scriptObj.src=  scriptUrl;
			var targetObj=document.getElementsByTagName("head")[0];
			if(!targetObj) 
				targetObj= document.body.parentNode.appendChild(document.createElement("head"));
			targetObj.appendChild(scriptObj);
			if (this.loadBind == null) 
				this.loadBind = window.setTimeout(this.checkLoad.bind(this),1000);
		}
	},
	checkLoad : function() {
		if (this.loadBind != null) {
			window.clearTimeout(this.loadBind); 
			this.loadBind = null;
		}
		var nextQueue = [];
		for(var i = 0; i < this.loadQueue.length; i++) {
			if (!this.loadQueue[i].checkLoad()) 
				nextQueue.push(this.loadQueue[i]);
		}
		this.loadQueue = nextQueue;
		if (this.loadQueue.length  > 0)
			this.loadBind = window.setTimeout(this.checkLoad.bind(this),1000);
		else
			this.loadBind = null;
	},
	isStylechecked : false,
	checkStyle : function() {
		if (!this.isStylechecked) {
			if (document.body) {
				var obj = document.createElement('div');
				obj.className = 'r-tl';
				obj.style.display = 'none';
				document.body.insertBefore(obj, document.body.childNodes[0]);
				var value = null;
		      	if (document.defaultView && document.defaultView.getComputedStyle) {
					var css = document.defaultView.getComputedStyle(obj, null);
					value = css ? css['width'] : null;
				} else if (obj.currentStyle) {
		        	value = obj.currentStyle['width'];
				}
				if (value != '3px') {
					var headNode = document.getElementsByTagName('head')[0];
					if(headNode) {
						var styleNode = document.createElement('link');
						styleNode.setAttribute('rel', 'stylesheet');
						styleNode.setAttribute('type', 'text/css');
						styleNode.setAttribute('charset', 'utf-8');
						styleNode.setAttribute('href', _cafen_service_url +'images/cafen.css');
						headNode.appendChild(styleNode);
					}
				}
				this.isStylechecked = true;
			} else if (this.checkStyleBind == null)
				this.checkStyleBind = window.setTimeout(cafen.checkStyle,100);
		}
	},
	apiKeys : null,
	checkAPI : function(key) {
		if (this.apiKeys == null) 
			this.apiKeys = cafen.extend({
				NAVER : 'a08d0b8d52f4f6d234e773066952a7e5', 
				DAUM : '8f25ed2e582d77737477cb70c989846b21767415', 
				GOOGLE : 'CAFENNET',
				NMap : 'eb4a6672a01c383cf5c030ee1fe6ef23', 
				DMap : '9d8944f6cfe4df09b77310ebe0f1a8ba642db899', 
				VEMap : 'AUTO', 
				GMap : 'ABQIAAAAs9fFh4qNwsTXeAyGhDSQAxRsXHxYIqxoBtaPWar0UpD_88pMthQAo-8i2C4QCp0BcrhhLRFyGFP30Q', 
				YMap: 'PGYzlUbV34Hx.wEYwxUjZcYdU1uieeMUiCe7FU4FVpyLWrRkZdZjeCRCMkkX.ZA-'
			}, cafenGlobalConf.apiKeys);
		return (this.apiKeys[key] != null && this.apiKeys[key] != '') ? true : false;
	},
	getAPI : function(key) {
		if (this.checkAPI(key)) 
			return this.apiKeys[key];
		else
			return '';
	},
	getDom : function(el){
		if(!el || !document)
			  return null;
		return typeof el == 'string' ? document.getElementById(el) : e;
	},
	getBody : function(){
		return Ext.get(document.body || document.documentElement);
	},
	getDiv : function(attrib, style) {
		return (new cafen.Div({attribute : attrib, style : style})).getElement();
	},
	getButton : function(attrib, style) {
		return (new cafen.Button({attribute : attrib, style : style})).getElement();
	},
	getInput : function(attrib, style) {
		return (new cafen.Input({attribute : attrib, style : style})).getElement();
	},
	getString2Json : function(str) {
		return eval('(' + str + ')'); 
	},
	getString2Function : function(ondone) {
		if (typeof ondone == 'function')
			return ondone;
		else if (typeof ondone == 'string' && ondone != '') {
			try {
				ondone = eval(ondone);
				if (typeof ondone == 'function')
					return ondone ;
				else
					return null;
			} catch(ex) {
				return null;	
			}
		} else
			return null;
	},
	getJson2String : function(obj, level) {
		level++;
		switch (typeof obj) {
			case 'boolean':
			case 'number':
				return obj.toString();
				break;
			case 'string':
				return '"' + unescape(escape(obj).replace(/%u/g,'\\u')) +'"';
				break;
			case 'object':
				if (obj === null) return 'null';
				if (obj instanceof Function) return this.getJson2String(obj());
				if (obj instanceof Array) {
					var a = new Array;
					for(var i=0; i < obj.length; i++) {
						a.push(this.getJson2String(obj[i], level));
					};
					var level_str1 = this.repeat('  ',level);
					var level_str2 = this.repeat('  ',level -1);
					return '[\r\n'+level_str1+a.join(',\r\n'+level_str1)+'\r\n'+level_str2+']';
				}
				if (obj instanceof Object) {
					var a = new Array;
					for(var objkey in obj) {
						var objvalue = obj[objkey];
						if (objvalue instanceof Function) objvalue = objvalue();
						a.push(this.getJson2String(objkey)+' : '+this.getJson2String(objvalue, level));
					};
					var level_str1 = this.repeat('  ',level);
					var level_str2 = this.repeat('  ',level -1);
					return '{\r\n'+level_str1+a.join(',\r\n'+level_str1)+'\r\n'+level_str2+'}';
				}
				break;
			case 'undefined':
			default:
				return '""';
				break;
		}
	},
	getQueryString : function(obj) {
		var param = [];
		for(var idx in obj)
			param.push(idx + '='+encodeURIComponent(obj[idx]));
		return param.join('&');
	},
	removeAllChild : function (node) {
		for(var i = 0; i < node.childNodes.length; i++) {
			node.removeChild(node.childNodes[i]);
		}
		node.innerHTML = '';
	},
	effectObj : [],
	setEffect : function(obj, w, h, mode, endFree) {
		if (this.startEffectBind == null)
			this.startEffectBind = this.startEffect.bind(this);
		this.effectObj.push({obj : obj, width : w, height : h, mode : mode, endFree : endFree, left : null, top : null});
		if (this.effectObj.length == 1) 
			this.startEffect();
	},
	startEffect : function() {
		var currEffect = this.effectObj[0];
		var objSize = [parseInt(currEffect.obj.style.width) ? parseInt(currEffect.obj.style.width) : currEffect.obj.offsetWidth  , parseInt(currEffect.obj.style.height) ? parseInt(currEffect.obj.style.height) : currEffect.obj.offsetHeight];
		if (currEffect.left == null || currEffect.top == null) {
			if (currEffect.width >  1 || currEffect.height > 1) 
				this.show(currEffect.obj);
			if (currEffect.width == null)
				currEffect.width = objSize[0];
			if (currEffect.height == null)
				currEffect.height = objSize[1];
			currEffect.seqn = 0;
		 	currEffect.left = currEffect.obj.offsetLeft;
		 	currEffect.top = currEffect.obj.offsetTop;
		 	currEffect.right = currEffect.left  + objSize[0];
		 	currEffect.bottom = currEffect.top  + objSize[1];
		}
		if (currEffect.seqn < 5) {
			currEffect.seqn++;
			var step_w = (currEffect.width - objSize[0]) / 3;
			var step_h = (currEffect.height - objSize[1]) / 3;
			var target_w = objSize[0] + step_w;
			var target_h = objSize[1] + step_h;
			if (currEffect.seqn >= 5) {
				target_w = currEffect.width;
				target_h = currEffect.height;
			}
			switch (currEffect.mode) {
				case 1 :
					break;
				case 2 :
					this.setStyle(currEffect.obj, {left : Math.round((currEffect.right + currEffect.left - target_w)/2) +'px'});
					break;
				case 3 :
					this.setStyle(currEffect.obj, {left : (currEffect.right - target_w) +'px'});
					break;
				case 4 :
					this.setStyle(currEffect.obj, {top : Math.round((currEffect.bottom + currEffect.top - target_h)/2) +'px'});
					break;
				case 5 :
					this.setStyle(currEffect.obj, {left : Math.round((currEffect.right + currEffect.left - target_w)/2) +'px',top : Math.round((currEffect.bottom + currEffect.top - target_h)/2) +'px'});
					break;
				case 6 :
					this.setStyle(currEffect.obj, {left : (currEffect.right - target_w) +'px',top : Math.round((currEffect.bottom + currEffect.top - target_h)/2) +'px'});
					break;
				case 7 :
					this.setStyle(currEffect.obj, {top : (currEffect.bottom - target_h) +'px'});
					break;
				case 8 :
					this.setStyle(currEffect.obj, {left : Math.round((currEffect.right + currEffect.left - target_w)/2) +'px',top : (currEffect.bottom - target_h) +'px'});
					break;
				case 9 :
					this.setStyle(currEffect.obj, {left : Math.round((currEffect.right - target_w)) +'px',top : (currEffect.bottom - target_h) +'px'});
					break;
			}
			if (target_w != 0 && target_h != 0)
				this.setStyle(currEffect.obj, {width : target_w +'px', height : target_h +'px'});
			setTimeout(this.startEffectBind, 20);
		} else {
			if (currEffect.width <= 1 || currEffect.height <= 1) 
				this.hide(currEffect.obj);
			else if (currEffect.endFree) 
				this.setStyle(currEffect.obj,{overflow : '', height : 'auto'});
			
			this.effectObj.shift();
			
			if (this.effectObj.length > 0)
				this.startEffect();
		}
	},
	setOpacity : function(element, opa) {
		if (this.browser.isIE == true) 
			this.setStyle(element, {filter:"alpha(opacity = "+opa+")"});
		else 
			this.setStyle(element, {opacity : opa/100});
	},
	show : function(element) {
      element.style.display = '';
		
	},
	hide : function(element) {
      element.style.display = 'none';
	},
	extend : function(destination, source) {
		if (destination == null)
			destination = {};
		for (var property in source) {
			if (destination[property] != null && typeof source[property] == 'object') {
				for (var subproperty in source[property]) 
					destination[property][subproperty] = source[property][subproperty];
			} else
   				destination[property] = source[property];
    	}
	  return destination;
	},
	extendClass : function(destination, source) {
		for (var property in source) {
			if (destination[property] == null)
				destination[property] = source[property];
    	}
	  return destination;
	},
	extendClassMax : function(destination, source) {
		for (var property in source) {
			destination[property] = source[property];
    	}
	  return destination;
	},
	openPopup : function(URL) {
		window.open(URL);
	},
	control_id : 'cafen',
	getUniqID : function(id) {
		return this.control_id + '_'+ Math.floor(Math.random() * 99999+ 10000) + '_' +Math.floor(Math.random() * 99999+ 10000) + '_' + id;
	},
	isURL : function(str) {
		if (str.length > 10 && this.find('^(http|https|mailto|ftp):\\/\\/',str))
			return true;
		else
			return false;
	},
	getSize2Short : function(in_size, per) {
		in_size = parseInt((in_size == null) ? 0 : in_size);
		if (per == null || typeof per == 'undefined')
			per = 0;
		if (in_size > 1024*1024*1024) return (in_size/ (1024*1024*1024)).toFixed(per) + " Gb";
		else if (in_size >= 1024*1024) return (in_size/ (1024*1024)).toFixed(per) + " Mb";
		else if (in_size >= 1024) return (in_size/ 1024).toFixed(per) + " Kb";
		else return in_size + " b";
	},
	browser : {
		userAgent : navigator.userAgent.toLowerCase(),
		isOpera :(navigator.userAgent.toLowerCase().indexOf('opera') != -1),
		isSafari :(navigator.userAgent.toLowerCase().indexOf('safari') != -1),
		isIE :(navigator.userAgent.toLowerCase().indexOf('msie') != -1),
		isFF:(navigator.userAgent.toLowerCase().indexOf('firefox') != -1),
		version : null
	},
	getVersion : function(){
		if (this.browser.version == null) {
			var str = navigator.appVersion;
			if (this.browser.isIE) {
				var bit=str.split(';');
				return this.browser.version = parseFloat((bit[1].split(' '))[2]);
			} else {
				var bit=str.split(' ');
				return this.browser.version = parseFloat(bit[0]);
			}
		} else 
			return this.browser.version;
	},
	getDomain : function() {
		if (this.last_domain == null)
			this.last_domain = String(document.location.href).match(/(https?:\/\/[a-z0-9_\-\.]+[:0-9]*)/i)[1];
		return this.last_domain;
	},
	toQueryString: function(hashMap) {
		var param = [];
		for(var idx in hashMap)
			param.push(idx + '=' + encodeURIComponent(hashMap[idx]));
		return param.join('&');
	},
	current_cursor : null,
	getCursor : function() {
		if (this.current_cursor == null)
			this.current_cursor = (this.browser.isIE)?'hand':'pointer';
		return this.current_cursor;
	},
	getRange : function(val, minval, maxval) {
		return Math.max(minval,Math.min(maxval, val));
	},
	rgb2hexFF : function(value){
		if (value == null) 
			return '';
		else if (typeof value == 'number') {
			var R = value % 256;
			var G = ((value - R) % (256*256))/ 256 ;
			var B = ((value - R - G*256) % (256*256*256))/ (256*256) ;
			return this.rgb2hex(R,G,B);
		} else if (typeof value == 'string') {
			if (value.toLowerCase() == 'transparent')
				return '';
			else if (typeof value == 'string' && value.indexOf('rgb')>=0) {
				var hex="",v,h,i;
				var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
				var h=regexp.exec(value);
				for(i=1;i<4;i++){
					v=parseInt(h[i]).toString(16);
					if(v.length==1) hex+="0"+v;
					else hex+=v;
				}
				return("#"+hex);
			}
		} else 
			return '';
	},
	rgb2hex : function(r, g, b) {
		r = r.toString(16); if (r.length==1) r = '0'+r;
		g = g.toString(16); if (g.length==1) g = '0'+g;
		b = b.toString(16); if (b.length==1) b = '0'+b;
		return '#' + r+g+b;
	},
	debugMessage : function (message) {
		var console, documentForm;
		try {
			console = document.getElementById("cafenUtil_Console");
			if (!console) {
				documentForm = document.createElement("form");
				document.getElementsByTagName("body")[0].appendChild(documentForm);
				console = document.createElement("textarea");
				console.id = "cafenUtil_Console";
				console.style.fontFamily = "monospace";
				console.setAttribute("wrap", "off");
				console.wrap = "off";
				console.style.overflow = "auto";
				console.style.width = "700px";
				console.style.height = "350px";
				console.style.margin = "5px";
				documentForm.appendChild(console);
			}
			console.value += message + "\n";
			console.scrollTop = console.scrollHeight - console.clientHeight;
		} catch (ex) {
			alert("Exception: " + ex.name + " Message: " + ex.message);
		}
	},
/**
 * 특정 아이디를 가진 Element 을 Array 가져오기
 * @param {string} id ID
 * @return {array} arrray()
 */
	getElementsById : function(id){
		var els = new Array();
		try {
			var tags = document.getElementsByTagName(document.getElementById(id).tagName);
			for(var i=0;i<tags.length;i++){
				if(tags[i].id==id) els[els.length]=tags[i];
			}
		} catch(ex) {}
		return els;
	},
/**
 * 특정 이름을 가진 Element 을 Array 가져오기
 * @param {string} name ID
 * @return {array} arrray()
 */
	getElementsByName : function(name, tagNames){
		var els = new Array();
		try {	
			tagNames.each(function(tagName) {
				var tags = document.getElementsByTagName(tagName);
				for(var i = 0; i < tags.length; i++)
					if(tags[i].getAttribute('name') == name)
						els.push(tags[i]);
			});
		} catch(ex) {}
		return els;
	},
/**
 * 특정 노드에서 첫번째 Child 노드 가져오기
 * @param {object} root 대상 노드
 * @param {object} node 대상 노드
 * @param {object} err_node null 시 가져올 노드
 * @return {object} child Node
 */
	getFirstChildNode : function(root, node, err_node) {
		var tmp_node = this.getChildrenByTagName(root, node);
		return (tmp_node !=null && tmp_node.firstChild) ? tmp_node.firstChild.nodeValue : err_node;
	},
/**
 * 특정 Node 에서 특정 태그를 가진 Child 가져오기
 * @param {object} node 대상 node
 * @param {string} tagName 태그 명
 * @return {array} Array(ChildNodes)
 */
	getChildrensByTagName : function (node, tagName) {
		var ln = node.childNodes.length;
		var arr = [];	
		for (var z=0; z<ln; z++) {
			if (node.childNodes[z].nodeName==tagName) arr.push(node.childNodes[z]);
		}
		return arr;
	},
/**
 * 특정 Node 에서 특정 태그를 가진 첫번째 Child 가져오기 
 * @param {object} node 대상 node
 * @param {string} tagName 태그 명
 * @return {object} ChildNode
 */
	getChildrenByTagName : function (node, tagName) {
		var arr = this.getChildrensByTagName(node, tagName);
		return (arr.length > 0)?arr[0]:null;
	},
	stripTags: function(str) {
		return str.replace(/<\/?[^>]+>/gi, '');
	},
/**
 * Html 을 읽기 쉬운 형태로 변환
 * @param {object} html 대상 문자
 * @return {string} 변환된 문자
 */
	html2Source : function(html) {
		html = html.replace(/\n|\r/gi, '');
		html = html.replace(/<BR>/gi, '<br>\n');
		html = html.replace(/<\/TD>/gi, '</td>\n');
		html = html.replace(/<\/TABLE>/gi, '</table>\n');
		html = html.replace(/<\/TR>/gi, '</tr>\n');
		html = html.replace(/<\/P>/gi, '</P>\n');
		return html;		
	},
	html2Text : function(html) {
		html = html.replace(/\r|\n/gi, '');
		html = html.replace(/<br>/gi, '\r\n');
		html = html.replace(/<p>/gi, '\r\n');
		html = html.replace(/<\/td>/gi, '</td>\r\n');
		html = html.replace(/&nbsp;/gi, ' ');
		html = html.replace(/<\/?[^>]+>/gi, '');
		html = html.replace(/&lt;/gi, '<');
		html = html.replace(/&gt;/gi, '>');
		return html;		
	},
	text2Html : function(txt, donotconv_special, donotconv_enter) {
		if (!donotconv_special) {
			txt = txt.replace(/</gi, '&lt;');
			txt = txt.replace(/>/gi, '&gt;');
		}
		if (!donotconv_enter) {
			txt = txt.replace(/\r/g, '');
			txt = txt.replace(/\n/g, '<br>');
		}
		return txt;
	},
	getImage : function(options, instyle) {
		var obj = this.extend(document.createElement('img'), this.extend({vspace : 0,hspace:0,border:0},options));
		var outstyle = this.extend({
			margin : '3px',
			border : '0'
		}, instyle);
		this.setStyle(obj, outstyle);
		return obj;
	},
	setStyle: function(element, style) {
		element = this.$(element);
		for (var name in style)
		  element.style[this.camelize(name)] = style[name];
	},
	getStyle : function(element, style) {
	    style = style == 'float' ? 'cssFloat' : this.camelize(style);
	    var value = element.style[style];
	    if (!value && document.defaultView) {
	      var css = document.defaultView.getComputedStyle(element, null);
	      value = css ? css[style] : null;
	    }
	    if (style == 'opacity') return value ? parseFloat(value) : 1.0;
	    return value == 'auto' ? null : value;
	},
	_isPngAlphaSupport : null,
	isPngAlphaSupport : function() {
		if (this._isPngAlphaSupport != null)
			return this._isPngAlphaSupport;
		else {
			if (navigator.userAgent.indexOf('MSIE') > 0) {
				var ie_version = parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE') + 5, navigator.userAgent.indexOf('MSIE') + 8));
				if (ie_version < 7.0) 
					this._isPngAlphaSupport = false
				else
					this._isPngAlphaSupport = true;
			} else
				this._isPngAlphaSupport = true;
			return this._isPngAlphaSupport;
		}
 	},
	_popupObj : null,
	getPopup : function() {
		if (this._popupObj)
			return this._popupObj;
		else {
			this._popupObj = document.createElement("div");
			this._popupObj.style.position = 'absolute';
			this._popupObj.style.left = '0px';
			this._popupObj.style.top = '0px';
			var doc_area = document.getElementsByTagName("body")[0];
			doc_area.insertBefore(this._popupObj, doc_area.lastChild);
			return this._popupObj;
		}
	},
	getChildObject : function(options) {
		var imgNode = null;
		var textNode = null;
		var childNodes = [];
		if (options == null)
			return childNodes;
		else if (options.src !=null && options.src != '') 
			imgNode = new cafen.Image(options.src, {attribute : {align:'absmiddle', hspace : '0', vspace : '0'}});
		else if (options.icon !=null) 
			imgNode = new cafen.XImage(options.icon);
		if (options.text != null && options.text != '') 
			textNode = document.createTextNode(options.text);
		if (imgNode != null && textNode != null) {
			var img_align = (options.align) ?  options.align.toLowerCase() : '';
			var tableChild = new cafen.TableAuto();
			childNodes.push(tableChild);
			switch(img_align) {
				case 'top' :
					tableChild.addRow();
					tableChild.addCell(imgNode);
					tableChild.addRow();
					tableChild.addCell(textNode);
					break;
				case 'bottom' :
					tableChild.addRow();
					tableChild.addCell(textNode);
					tableChild.addRow();
					tableChild.addCell(imgNode);
					break;
				case 'right' :
					tableChild.addRow();
					tableChild.addCell(textNode);
					tableChild.addCell(imgNode);
					break;
				default :
					tableChild.addRow();
					tableChild.addCell(imgNode);
					tableChild.addCell(textNode);
					break;
			}
		} else if (imgNode != null)
			childNodes.push(imgNode);
		else if (textNode != null)
			childNodes.push(textNode);
		return childNodes;
	},
	_msgObj : null,
	_msgCloseBind : null,
	showMsg : function(msg) {
		if (this._msgObj == null) {
			this._msgObj = new cafen.Div({className : 'r-btnskin', tplName :'top',shadow : true, style :{position:'absolute', width : '230px', height : 'auto', overflowX :'hidden',overflowY : 'hidden', padding:'5px', border : '1px dotted #d0d0d0', backgroundColor : '#e0e0e0',margin:'3px'}});
			this.getPopup().appendChild(this._msgObj.getObject());
			this._msgObj.appendChild(new cafen.Div({attribute : {innerHTML : '<b>Result Message</b>'}, style: {paddingLeft:'10px'}}),'top');
		}
		this._msgObj.show();
		this._msgObj.center();
		this._msgObj.getElement().innerHTML = msg;	
		if (	this._msgCloseBind != null)
			window.clearTimeout(this._msgCloseBind);	
		this._msgCloseBind = window.setTimeout(this.closeMsg.bind(this), 3000);
	},
	closeMsg : function() {
		this._msgObj.hide();
		this._msgCloseBind = null;
	},
	getImgeTag : function(src, tags) {
		if (/png$/.test(src) && this.browser.isIE && this.getVersion() < 7) {
			return '<img src='+src+' '+tags+' style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+ src+',sizingMethod=image);">';
		} else { 
			return '<img src="'+src + '" '+tags+'>';
		}
	},
	camelize: function(str) {
		var oStringList = str.split('-');
		if (oStringList.length == 1) return oStringList[0];
		var camelizedString = this.indexOf('-') == 0 ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
		for (var i = 1, len = oStringList.length; i < len; i++) {
			var s = oStringList[i];
			camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
		}
		return camelizedString;
	},
	pointerX: function(event) {
		if (event == null)
			event = window.event;
		return event.pageX || (event.clientX +
		(document.documentElement.scrollLeft || document.body.scrollLeft));
	},
	pointerY: function(event) {
		if (event == null)
			event = window.event;
		return event.pageY || (event.clientY +
		(document.documentElement.scrollTop || document.body.scrollTop));
	},
	pointer: function(event) {
		if (event == null)
			event = window.event;
		return [this.pointerX(event), this.pointerY(event)];
	},
	cumulativeOffset: function(_element) {
		_element = this.$(_element);
		var valueT = 0, valueL = 0;
		do {
			valueT += _element.offsetTop  || 0;
			valueL += _element.offsetLeft || 0;
			_element = _element.offsetParent;
		} while (_element);
		return [valueL, valueT];
	},
	cumulativeScrollOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.scrollTop  || 0;
			valueL += element.scrollLeft || 0;
			element = element.parentNode;
		} while (element);
		return [valueL, valueT];
	},
	viewportOffset : function(forElement) {
		var valueT = 0, valueL = 0;
		var element = forElement;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			if (element.offsetParent == document.body && this.getStyle(element, 'position') == 'absolute') break;
		} while (element = element.offsetParent);
		element = forElement;
		do {
			if (!this.browser.isOpera && element.tagName != 'BODY') {
				valueT -= element.scrollTop  || 0;
				valueL -= element.scrollLeft || 0;
			}
		} while (element = element.parentNode);
		return [valueL, valueT];
	},
	getPageScroll : function() {
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		return [xScroll,yScroll] 
	},
	// Adapted from getPageSize() by quirksmode.com
	getPageSize : function() {
		var windowHeight,  windowWidth
		if (self.innerHeight) {	// all except Explorer
			windowHeight = self.innerHeight;
			windowWidth = self.innerWidth;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowHeight = document.documentElement.clientHeight;
			windowWidth = document.documentElement.clientWidth;
		} else if (document.body) { // other Explorers
			windowHeight = document.body.clientHeight;
			windowWidth = document.body.clientWidth;
		}	
		return [windowWidth, windowHeight]
	},
	getSize : function(_element) {
		_element = this.$(_element);
		var w = (_element.offsetWidth || parseInt(_element.style.width));
		var h = (_element.offsetHeight || parseInt(_element.style.height));
		return [w, h];
	},
	positionedOffset: function(_element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += _element.offsetTop  || 0;
			valueL += _element.offsetLeft || 0;
			_element = _element.offsetParent;
			if (_element) {
				var p = this.getStyle(_element, 'position');
				if (p == 'relative' || p == 'absolute') break;
			}
		} while (_element);
		return [valueL, valueT];
	},
	_mouse_init : [0,0],
	_obj_init : [0,0],
	_dragObj : [null, null],
	_stopEvent : null,
	startDrag : function(event,pointobj, options, stopEvent) {
		targetobj = options.link || pointobj;
		this._mouse_init = this.pointer(event);
		this._dragObj = [pointobj,targetobj, options];	
		this._obj_init = targetobj.getOffset();
		this._stopEvent = stopEvent;
		document.body.onmousemove = this.moveDrag.bindAsEventListener(this);
		document.body.onmouseup = this.stopDrag.bindAsEventListener(this);
	},
	moveInrange : function(x, y) {
		if (x != null && this._dragObj[2].rangeX != null && (this._dragObj[2].rangeX[0] > x || this._dragObj[2].rangeX[1] < x))
			return false;
		else if (y != null && this._dragObj[2].rangeY != null && (this._dragObj[2].rangeY[0] > y || this._dragObj[2].rangeY[1] < y))
			return false;
		else
			return true;
	},
	moveDrag : function(event) {
		var pos = this.pointer(event);
		if (pos[0] < 0 || pos[1] < 0 || pos[0] > document.body.offsetWidth) {
			this.stopDrag(event);
			return ;	
		}
		var moveX = pos[0] - this._mouse_init[0];
		var moveY = pos[1] - this._mouse_init[1];
		switch(this._dragObj[2].direction) {
			case 'X' :
				if (this.moveInrange(this._obj_init[0] +moveX, null))
					this._dragObj[1].setOffset(this._obj_init[0] +moveX,  null);
				else
					this.stopDrag(event);
				break;
			case 'Y' :
				if (this.moveInrange(null, this._obj_init[1] +moveY))
					this._dragObj[1].setOffset(null, this._obj_init[1] +moveY);
				else
					this.stopDrag(event);
				break;
			default :
				if (this.moveInrange(this._obj_init[0] +moveX, this._obj_init[1] +moveY))
					this._dragObj[1].setOffset(this._obj_init[0] +moveX,  this._obj_init[1] +moveY);
				else
					this.stopDrag(event);
				break;
		}
	},
	stopDrag : function(event) {
		document.body.onmousemove = null;
		document.body.onmouseup = null;
		if (this._stopEvent != null)
			this._stopEvent();
	},
	repeat : function(input_str, len) {
		var str = '';
		for(var i = 0; i < len; i++)
			str += input_str;
		return str;
	},
	showElement : function(obj) {
		var tmp = document.createElement('div');
		if (obj.getObject)
			tmp.appendChild(obj.getObject());
		else
			tmp.appendChild(obj);
	},
	find : function(reg, str,bl) {
		var m = [];
		try {
			if (m = str.match(eval('/' + reg + '/'+(bl ? 'i':'')))) 
				return m;
			else 
				return false;
		} catch(ex) {
			return false;
		}
	},
	Event : {
		KEY_BACKSPACE: 8,
		KEY_TAB:       9,
		KEY_RETURN:   13,
		KEY_ESC:      27,
		KEY_LEFT:     37,
		KEY_UP:       38,
		KEY_RIGHT:    39,
		KEY_DOWN:     40,
		KEY_DELETE:   46,
		element: function(event) {
			return event.target || event.srcElement;
		},
		isLeftClick: function(event) {
			return 1;
		},
		pointerX: function(event) {
			return event.pageX || (event.clientX +
				(document.documentElement.scrollLeft || document.body.scrollLeft));
		},
		pointerY: function(event) {
			return event.pageY || (event.clientY +
			(document.documentElement.scrollTop || document.body.scrollTop));
		},
		stop: function(event) {
			if (event.preventDefault) {
				event.preventDefault();
				event.stopPropagation();
			} else {
				event.returnValue = false;
				event.cancelBubble = true;
			}
		},
		findElement : function(event, tagName) {
			var element = cafen.Event.element(event);
			while (element.parentNode && (!element.tagName || (element.tagName.toUpperCase() != tagName.toUpperCase())))
				element = element.parentNode;
			return element;
		},
		observers: false,
		_observeAndCache: function(element, name, observer, useCapture) {
			if (!this.observers) this.observers = [];
			if (element.addEventListener) {
				this.observers.push([element, name, observer, useCapture]);
				element.addEventListener(name, observer, useCapture);
			} else if (element.attachEvent) {
				try {
					this.observers.push([element, name, observer, useCapture]);
		  			element.attachEvent('on' + name, observer);
				} catch(ex) {}
			}
		},
		unloadCache: function() {
			if (!cafen.Event.observers) return;
			for (var i = 0; i < cafen.Event.observers.length; i++) {
				cafen.Event.stopObserving.apply(this, cafen.Event.observers[i]);
				cafen.Event.observers[i][0] = null;
			}
			cafen.Event.observers = false;
		},
		observe: function(element, name, observer, useCapture) {
			var element = cafen.$(element);
			useCapture = useCapture || false;
			if (name == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || element.attachEvent))
				name = 'keydown';
			this._observeAndCache(element, name, observer, useCapture);
		},
		stopObserving: function(element, name, observer, useCapture) {
			var element = cafen.$(element);
			useCapture = useCapture || false;
			if (name == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || element.detachEvent))
				name = 'keydown';
			if (element.removeEventListener) {
				element.removeEventListener(name, observer, useCapture);
			} else if (element.detachEvent) {
				element.detachEvent('on' + name, observer);
			}
		}		
	},
	toString : function(obj, level) {
		if (level == null)
			level = 0;
		var var_dump = '';
		if (typeof obj == 'object') {
			var objVal = [];
			for(var name in obj) {
				if (name.indexOf('_') != 0)
					objVal.push(name +' : ' + this.toString(obj[name], level+1));
			}
			return '{' + objVal.join(',\r\n'+this.repeat(' ',level)) +'}';
		} else if (typeof obj == 'array') {
			var objVal = [];
			for(var i = 0; i < 	obj.length ; i++)
				objVal.push(i +' : ' + this.toString(obj[i], level+1));
			return '[' + objVal.join(',\r\n'+this.repeat(' ',level)) +']';
		} else
			return obj;
	},
	toSS : function(obj) {
		if (typeof obj == 'object') {
			var objVal = [];
			for(var name in obj) {
				objVal.push(name);
			}
			return '{Object ' + objVal.join(', '+this.repeat(' ',1)) +'}';
		} else if (typeof obj == 'array') {
			var objVal = [];
			for(var i = 0; i < 	obj.length ; i++)
				objVal.push(obj[i]);
			return '[Array ' + objVal.join(', '+this.repeat(' ',1)) +']';
		} else
			return obj;
	},
	renderElementsByClassName : function(className) {
		var objs = this.getElementsByTagName('*');
		var result = [];
		for(var i =0; i < objs.length; i++) 
			if (objs[i].className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) 
				result.push(objs[i]);
		for(var i = 0; i < result.length; i++)
				this.renderElement(result[i]);
	},
	renderElementsById : function(id) {
		if (document.getElementById(id) != null) {
			var objs = document.getElementsByTagName(document.getElementById(id).tagName);
			var result = [];
			for(var i=0;i<objs.length;i++)
				if(objs[i].id==id) 
					result.push(objs[i]);
			for(var i = 0; i < result.length; i++)
					this.renderElement(result[i]);
		}
	},
	renderElements : function(objs) {
		var result = [];
		for(var i = 0; i < objs.length; i++)
				result.push(objs[i]);
		for(var i = 0; i < result.length; i++)
				this.renderElement(result[i]);
	},
	renderElement : function(obj) {
		switch (obj.tagName) {
			case 'BUTTON' :
				var randerClassName = obj.getAttribute('cafenclass');
				var events = {}
				if (obj.onclick != null)
					events.click = obj.onclick;
				var tmpObj = new cafen.XButton({className : (randerClassName == null) ? 'r-rbtnskin' :  randerClassName , attribute : {innerHTML  : obj.innerHTML}, event : events, style : {width : obj.offsetWidth +'px', height : obj.offsetHeight +'px'}});
				obj.parentNode.insertBefore(tmpObj.getObject(), obj);
				this.hide(obj);
				break;
			case 'DIV' :
			var randerClassName = obj.getAttribute('cafenclass');
				switch(obj.getAttribute('cafentype')) {
					case 'tab' :
						var tmpTabs = [];
						for(var i = 0; i < obj.childNodes.length; i++) {
							var currObj = obj.childNodes[i];
							if (currObj.tagName == 'BUTTON') {
								var tmpTab = new cafen.XTab(
										{className : (randerClassName == null) ? 'r-tab-b' :  randerClassName ,attribute : {innerHTML :currObj.innerHTML}, style : {width : currObj.offsetWidth +'px', height : currObj.offsetHeight +'px'},event : {click: currObj.onclick.bind(currObj)}}
									);
								currObj.linkObj = tmpTab;
								tmpTabs.push(tmpTab); 
							}
						}
						var tmpDiv = new cafen.Div({style : {width : (obj.offsetWidth +6)+'px'}});
						var tmpObj = new cafen.XTabMenu(tmpTabs, {});
						if (tmpTabs.length > 0)
							tmpObj.setSelected(tmpTabs[0]);
						tmpDiv.appendChild(tmpObj);
						obj.parentNode.insertBefore(tmpDiv.getObject(), obj);
						this.hide(obj);
						break;
					default :
						var divTitle = obj.getAttribute('title');
						var tmpObj = new cafen.Div({className : (randerClassName == null) ? 'r-boxwhite' : randerClassName, tplName : (divTitle != null && divTitle != '') ?'top' : '', attribute : {border:0},style : {width:  obj.offsetWidth+'px', height : obj.offsetHeight+'px', overflowX : 'hidden', overflowY: 'auto', textAlign:'center'}});
						if (divTitle != null && divTitle != '') {
							tmpObj.appendChild(new cafen.Div({attribute:{innerHTML : '&nbsp;<b>' +divTitle +'</b>'}}),'top');
							obj.title = '';
						}
						obj.parentNode.insertBefore(tmpObj.getObject(), obj);
						tmpObj.appendChild(obj);
				}
				break;
			case 'TABLE' :
				var tmpObj = new cafen.TableAuto({style : {}, attribute : {border : 0, cellspacing : 2}});
				var currTbody = (obj.childNodes[0].tagName == 'TBODY') ? obj.childNodes[0] : obj;
				for(var i = 0; i < currTbody.childNodes.length; i++) {
					var tmpTR = tmpObj.addRow();
					tmpTR.attachEvent('mouseover', function(obj) {obj.setStyle({backgroundColor : '#000000', color : '#FFFFFF'})});
					tmpTR.attachEvent('mouseout', function(obj) {obj.setStyle({backgroundColor : '#FFFFFF', color : '#464646'})});
					var currTR = currTbody.childNodes[i];
					var baseAlign = currTR.getAttribute('align');
					for(var j = 0; j < currTR.childNodes.length; j++) {
						if (i == 0) {
							var base_Width = currTR.childNodes[j].offsetWidth ;
							tmpObj.addCell(new cafen.XButton({attribute : {innerHTML : currTR.childNodes[j].innerHTML}, resize : 'XXXXXOXXX', style : {width: base_Width +'px'}}));
						} else {
							tmpObj.addCell(currTR.childNodes[j].innerHTML);
							tmpObj.addAttribute({align: baseAlign});
						}
					}
				}
				obj.parentNode.insertBefore(tmpObj.getObject(), obj);
				obj.style.display = 'none';
				break;
			case 'INPUT' :
			case 'TEXTAREA' :
				var randerClassName = obj.getAttribute('cafenclass');
				var cafenresize = obj.getAttribute('cafenresize');
				var validValue = obj.getAttribute('cafenvalid');
				var resize_options = null;
				switch(cafenresize) {
					case 'width' :
						resize_options = 'XXXXXOXXX';
						break;
					case 'height' :
						resize_options = 'XXXXXXXOX';
						break;
					case 'both' :
						resize_options = 'XXXXXOXOO';
						break;
				}
				var tmpObj = null;
				if (obj.tagName == 'INPUT')
					tmpObj = new cafen.XInput({renderObj : obj, className : (randerClassName == null) ? 'r-inputskin' :  randerClassName , attribute : {value  : obj.value}, style : {width : obj.offsetWidth +'px'}, resize : resize_options, validValue : validValue});
				else
					tmpObj = new cafen.XTextarea({renderObj : obj, className : (randerClassName == null) ? 'r-inputskin' :  randerClassName , attribute : {value  : obj.value}, style : {width : obj.offsetWidth +'px', height: obj.offsetHeight +'px'}, resize : resize_options, validValue : validValue});
				obj.parentNode.insertBefore(tmpObj.getObject(), obj);
				tmpObj._element.parentNode.insertBefore(obj, tmpObj._element);
				tmpObj._element.parentNode.removeChild(tmpObj._element);
				tmpObj._element = obj;
				obj.style.border = '0px';
				break;
			default :
				if (obj.tagName != null)
					alert(obj.tagName);
				break;
		}
	}
}
try {
	if (window.onerror == null) {
		window.onerror = function(message, url, line) { 
			if (typeof window.debug_mode != 'undefined' && window.debug_mode) {
				var script_path = 'Unknown';
				try {
					script_path = arguments.callee.caller.toString();
				} catch(ex) {}
				cafen.debugMessage('Msg :'+message+'\r\nUrl:'+url+'\r\nLine:'+line + '\r\nScript:'+ script_path);	
			}
			return true;
		}
	}
	cafen.Event.observe(window, 'unload', cafen.Event.unloadCache, false);
} catch(ex) {}
	
cafen.Element = function(tag, options) {
	this.setOptions(cafen.extend(options, {tag : tag}));	
}

cafen.Element.prototype = {
	options : {},
	_element : null,
	_tpl : null,
	_tplElement : [],
	_shadow : null,
	_broElement : null,
	parentNode : null,
	childNodes : [],
	_cssTable : [
		['r-tl','r-tc','r-tr'],
		['r-ml','r-mc','r-mr'],
		['r-bl','r-bc','r-br']
	],
	_cssShadowTable : [
		['r-swmc','r-swmr'],
		['r-swbc','r-swbr']
	],
	_cssTableTop : [
		['r-tl-e','r-tc-e','r-tr-e'],
		['r-ml','r-mc','r-mr'],
		['r-bl','r-bc','r-br']
	],
	_cssTableBottom : [
		['r-tl','r-tc','r-tr'],
		['r-ml','r-mc','r-mr'],
		['r-bl-e','r-bc-e','r-br-e']
	],
	_cssTableBoth : [
		['r-tl-e','r-tc-e','r-tr-e'],
		['r-ml','r-mc','r-mr'],
		['r-bl-e','r-bc-e','r-br-e']
	],
	setOptions : function(options) {
		this.childNodes = [];
		this.parentNode = null;
		this._element = null;
		this._tpl = null;
		this._tplElement = [];
		this._shadow = null;
		this._broElement = null;
		this.options = cafen.extend({
			tag:'', 
			className : '',
			tplName : '',
			align : '',
			style : {}, 
			childNodes : [],
			shadow : false,
			resize : 'XXXXXXXXX',
			resizeOption : {minWidth : 1, minHeight : 1, maxWidth : -1, maxHeight : -1, Increment : 1, preserveRatio: false},
			attribute : {}, 
			_event : {},
			_eventBind : {},
			_lastresizeObj : null,
			event : {}
		}, options);
		this.options._event = {};
	},
	getObject : function() {
		if (this._element == null) {
			if (this.options.tag != null) {
				try { 
					this._element = document.createElement(this.options.tag);
				} catch(ex) {
					this._element = document.createElement("DIV");
				}
			}
			else 
				this._element = null;
			if (this.options.className != '') {
				this._tpl = document.createElement('table');
				this._tpl.setAttribute('border',0,0);
				this._tpl.setAttribute('unselectable','on',0);
				this._tpl.setAttribute('cellSpacing',0,0);
				this._tpl.setAttribute('cellPadding',0,0);
				this._tpl.className = 'r-off';
				var baseCssTable = [];
				switch(this.options.tplName) {
					case 'top' :
						baseCssTable = this._cssTableTop;
						break;
					case 'bottom' :
						baseCssTable = this._cssTableBottom;
						break;
					case 'both' :
						baseCssTable = this._cssTableBoth;
						break;
					default :
						baseCssTable = this._cssTable;
						break;
				}
				for(var i = 0 ; i < baseCssTable.length; i++) {
					var tr_obj = this._tpl.insertRow(-1);
					tr_obj.className = this.options.className;
					for(var j = 0 ; j < baseCssTable[i].length; j++) {
						var className = baseCssTable[i][j];
						var obj = tr_obj.insertCell(-1);
						obj.className = className;
						if (className == 'r-mc') {
							if (this._element != null)
								obj.appendChild(this._element);
						} else if (j == 1 && (className == 'r-tc-e' || className == 'r-bc-e'))
							obj.innerHTML = '<div style="text-align:left">&#160;</div>';
						else
							obj.innerHTML = '<div class="blank">&#160;</div>';
						this._tplElement.push(obj);
					}
				}
				this.makeResizeable(this.options.resize);
			} else
				this._tpl = this._element;
			if (this.options.shadow) {
				this._shadow = document.createElement('table');
				this._shadow.setAttribute('border','0',0);
				this._shadow.setAttribute('unselectable','on',0);
				this._shadow.setAttribute('cellspacing',0,0);
				this._shadow.setAttribute('cellpadding',0,0);
				this._shadow.style.position = 'relative';
				for(var i = 0 ; i < this._cssShadowTable.length; i++) {
					var tr_obj = this._shadow.insertRow(-1);
					tr_obj.className = cafen.isPngAlphaSupport() ? 'r-shadow' : 'r-shadow-ie5';
					for(var j = 0 ; j < this._cssShadowTable[i].length; j++) {
						var className = this._cssShadowTable[i][j];
						var obj = tr_obj.insertCell(-1);
						obj.className = className;
						if (className == 'r-swmc') {
							obj.appendChild(this._tpl);
						} else {
							obj.innerHTML = '<div class="blank">&#160;</div>';
						}
					}
				}
			} else {
				this._shadow = this._tpl;
			}
			this.setAttribute(this.options.attribute);
			if (this.options.childNodes.length > 0) {
				for(var i = 0; i < this.options.childNodes.length; i++) 
					this.appendChild(this.options.childNodes[i]);
			}
			this.makeMoveable(this.options.moveOption);
			this.setStyle(this.options.style);
			this.setEvent(this.options.event);
			this.setAlign(this.options.align);
		}
		return this._shadow;
	},
	makeMoveable : function(moveOption) {
		if (moveOption != null) {
			this.setStyle({cursor :cafen.getCursor()});
			this.attachEvent('mousedown', this.startDrag.bind(this));
		} else
			this.detachEvent('mousedown',this.startDrag.bind(this));
	},
	startDrag : function(obj, event) {
		cafen.startDrag(event, obj, this.options.moveOption, this.stopDrag.bind(this));
	},
	stopDrag : function() {
		this.execEvent('dragend');
	},
	makeResizeable : function(str) {
		if (this._tplElement.length == 9 && str.length == 9) {
			var cursorStyle = ['nw','n','sw','e','','e','sw','n','nw'];
			for(var i = 0; i < cursorStyle.length; i++) {
				if (i == 4)
					continue;
				else if (str.charAt(i) == 'O') {
					this._tplElement[i].style.cursor = cursorStyle[i]+'-resize';
					this._tplElement[i].onmousedown = this.startReSize.bind(this, i);
				} else {
					this._tplElement[i].style.cursor = '';
					if (this._tplElement[i].onmousedown != null)
						this._tplElement[i].onmousedown = null;
				}
			}
		}
	},
	startReSize : function(dir, event) {
		if (this.options._lastresizeObj != null) 
			this.stopResize(event);
		this.options._lastresizeObj = this._tplElement[dir];
		this.options._lastresizeInfo = [dir, cafen.pointer(event || window.event), this.getSize(), this.getOffset()];
		document.body.onmousemove = this.moveResize.bindAsEventListener(this);
		document.body.onmouseup = this.stopResize.bindAsEventListener(this);
	},
	checkResize : function(w, h) {
		if ((w != null && w < 1)  || (h != null && h < 1) )
			return false;
		else if (w != null && this.options.resizeOption.maxWidth > 1 && (this.options.resizeOption.minWidth > w || this.options.resizeOption.maxWidth < w)) 
			return false;
		else if (h != null && this.options.resizeOption.maxHeight > 1 && (this.options.resizeOption.minHeight > h || this.options.resizeOption.maxHeight < h)) 
			return false;
		else
			return true;
	},
	moveResize : function(event) {
		var pos = cafen.pointer(event);
		var moveX = pos[0] - this.options._lastresizeInfo[1][0];
		var moveY = pos[1] - this.options._lastresizeInfo[1][1];
		if (this.options.resizeOption.Increment > 1) {
			moveX = Math.round(moveX / this.options.resizeOption.Increment) * this.options.resizeOption.Increment;
			moveY = Math.round(moveY / this.options.resizeOption.Increment) * this.options.resizeOption.Increment;
		}
		if (this.options.resizeOption.preserveRatio) 
			moveY = Math.round(moveX * this.options._lastresizeInfo[2][1] / this.options._lastresizeInfo[2][0]);
		switch(this.options._lastresizeInfo[0]) {
			case 0 :
				var sizeW = this.options._lastresizeInfo[2][0] - moveX;
				var sizeH = this.options._lastresizeInfo[2][1] - moveY;
				if (this.checkResize(sizeW, sizeH)) {
					this.setSize(sizeW, sizeH);
					var offsetL = this.options._lastresizeInfo[3][0] + moveX;
					var offsetT = this.options._lastresizeInfo[3][1] + moveY;
					this.setOffset(offsetL, offsetT);
				} else 
					this.stopResize(event);
				break;
			case 1 :
				var sizeH = this.options._lastresizeInfo[2][1] - moveY;
				if (this.checkResize(null, sizeH)) {
					var offsetT = this.options._lastresizeInfo[3][1] + moveY;
					this.setOffset(null, offsetT);
					this.setSize(null, sizeH);
				} else 
					this.stopResize(event);
				break;
			case 2 :
				var sizeW = this.options._lastresizeInfo[2][0] + moveX;
				var sizeH = this.options._lastresizeInfo[2][1] - moveY;
				if (this.checkResize(sizeW, sizeH)) {
					var offsetT = this.options._lastresizeInfo[3][1] + moveY;
					this.setOffset(null, offsetT);
					this.setSize(sizeW, sizeH);
				} else 
					this.stopResize(event);
				break;
			case 3 :
				var sizeW = this.options._lastresizeInfo[2][0] - moveX;
				if (this.checkResize(sizeW, null)) {
					var offsetL = this.options._lastresizeInfo[3][0] + moveX;
					this.setOffset(offsetL, null);
					this.setSize(sizeW, null);
				} else 
					this.stopResize(event);
				break;
			case 5 :
				var sizeW = this.options._lastresizeInfo[2][0] + moveX;
				if (this.checkResize(sizeW, null)) {
					this.setSize(sizeW, null);
				} else 
					this.stopResize(event);
				break;
			case 6 :
				var sizeW = this.options._lastresizeInfo[2][0] - moveX;
				var sizeH = this.options._lastresizeInfo[2][1] + moveY;
				if (this.checkResize(sizeW, sizeH)) {
					var offsetL = this.options._lastresizeInfo[3][0] + moveX;
					this.setOffset(offsetL, null);
					this.setSize(sizeW, sizeH);
				} else 
					this.stopResize(event);
				break;
			case 7 :
				var sizeH = this.options._lastresizeInfo[2][1] + moveY;
				if (this.checkResize(null, sizeH)) {
					this.setSize(null, sizeH);
				} else 
					this.stopResize(event);
				break;
			case 8 :
			default : 
				var sizeW = this.options._lastresizeInfo[2][0] + moveX;
				var sizeH = this.options._lastresizeInfo[2][1] + moveY;
				if (this.checkResize(sizeW, sizeH)) {
					this.setSize(sizeW, sizeH);
				} else 
					this.stopResize(event);
				break;
		}
	},
	stopResize : function(event) {
		if (this.options._lastresizeObj != null) {
			document.body.onmousemove = null;
			document.body.onmouseup = null;
			this.execEvent('resize', event);
			this.options._lastresizeObj = null;
		}
	},
	getElement : function(tpltaget) {
		if (this._element == null)
			this.getObject();
		if ((tpltaget == null || tpltaget == '' || this._tplElement.length != 9 ) && tpltaget != 'shadow' )
			return this._element;
		else {
			 switch(tpltaget) {
			 	case 'top' :
					return this._tplElement[1].firstChild ;
					break;
				case 'bottom' :
					return this._tplElement[7].firstChild;
					break;
				case 'shadow' :
					if (this._broElement == null) {
						this._broElement = document.createElement('div');
						this._broElement.style.position = 'relative';
						this._broElement.style.zIndex = '1000';
						this._broElement.style.left = '-3px';
						this._broElement.style.width = '1px';
						this._broElement.style.height = '1px';
						this._shadow.firstChild.childNodes[1].childNodes[1].appendChild(this._broElement);
					}
					return this._broElement;
					break;
				default :
					return (this._element) ? this._element :  this._tplElement[4];
					break;
			}
		}
	},
	setElement : function(obj) {
		if (this.getObject()) {
			this._element = obj;
			if (this._tplElement[4] != null)
				this._tplElement[4].appendChild(obj.getObject ? obj.getObject : obj);
		}
	},
	getTpl : function() {
		if (this._tpl != null)
			return this._tpl;
		else if (this.getObject() != null)
			return this._tpl;
		else
			null;
	},
	setEvent : function(events) {
		if (events != null) {
		    for (var name in events)
		      this.attachEvent(name, events[name]);
		}
	},
	setAlign : function(align) {
		if (align != '') {
			this.getObject().align = align;
			if (align =='center')
				this.getObject().setAttribute('align', 'center',0);
			else
				this.getObject().style.cssFloat = align;
		}
	},
	isBaseEvent : function(name) {
		if (
			name == 'click' 
			|| name == 'mouseover'  || name == 'mouseout' 
			|| name == 'mousemove'|| name == 'mousedown' || name == 'mouseup' 
			|| name == 'keypress'  || name == 'keydown' || name == 'keyup' 
			|| name == 'focus' || name == 'blur')
			return true;
		else
			return false;
	},
	attachEvent : function(name, observer) {
		if (this.isBaseEvent(name) && this.options._eventBind[name] == null) {
			this.options._eventBind[name] = this.execEvent.bind(this,name);
			cafen.Event.observe(this.getElement(),name, this.options._eventBind[name]);
		}
		if (this.options._event[name] == null)
			this.options._event[name] = [];
		this.options._event[name].push(observer);
	},
	detachEvent : function(name, observer) {
		var currEvent = this.options._event[name];
		if (currEvent != null) {
			var findevent = false;
			var newEvent = [];
			if (observer == null) {
				findevent = true;
			} else {
				for(var i = 0; i < currEvent.length; i++) {
					if (currEvent[i] == observer)
						findevent = true;
					else
						newEvent.push(currEvent[i]);
				}
			}
			if (findevent) {
				this.options._event[name] = newEvent;
				if (this.isBaseEvent(name) && newEvent.length == 0 && this.options._eventBind[name] != null) {
					cafen.Event.stopObserving(this.getElement(),name, this.options._eventBind[name]);
					this.options._eventBind[name] = null;
				}
			}
		}
	},
	execEvent : function(name, event) {
		var currEvent = this.options._event[name];
		event = event || window.event;
		var result = true;
		if (currEvent != null) {
			for(var k = 0; k < currEvent.length; k++) 
				result = currEvent[k](this, event) && result;
		}
		return result;
	},
	setClassName : function(name) {
		this.getTpl().className = name;
	},
	setStyle : function(cssstyle) {
		if (cssstyle != null) {
			for (var name in cssstyle) {
				switch(name) {
					case 'left' :
					case 'top' :
					case 'position' :
					case 'display' :
					case 'marginTop' :
					case 'marginLeft' :
					case 'marginRight' :
					case 'marginBottom' :
					case 'margin' :
					case 'opacity' :
					case 'zIndex' :
						try {
							this.getObject().style[cafen.camelize(name)] = cssstyle[name];
						} catch(ex) {
							alert(cafen.camelize(name) + '/' +cssstyle[name]);	
						}
						break;
					default :
						try {
//							if (cssstyle[name] == 'undefined' || typeof cssstyle[name] == 'undefined')
//								alert(arguments.callee.caller.toString());
							if (this.getElement() != null)
								this.getElement().style[cafen.camelize(name)] = cssstyle[name];
						} catch(ex) {
//							alert(ex + cafen.camelize(name) + '/' +cssstyle[name] + arguments.callee.caller.toString());
						}
						break;
				}
			}
		}
	},
	getStyle : function(style) {
		style = style == 'float' ? 'cssFloat' : cafen.camelize(style);
		var value = this.getElement().style[style];
		if (!value) {
	      	if (document.defaultView && document.defaultView.getComputedStyle) {
				var css = document.defaultView.getComputedStyle(this.getElement(), null);
				value = css ? css[style] : null;
			} else if (this.getElement().currentStyle) {
	        	value = this.getElement().currentStyle[style.camelize()];
			}
		}
		if (style == 'opacity') 
			return value ? parseFloat(value) : 1.0;
		return value == 'auto' ? null : value;
	},
	setOpacity: function(opa) {
		if (cafen.browser.isIE) 
			this.setStyle({filter:"alpha(opacity = "+opa+")"});
		else 
			this.setStyle({opacity : opa/100});
	},
	getAttribute : function(name) {
		return this.getElement().getAttribute(name);
	},
	setAttribute : function(attrib) {
		if (attrib != null) {
		    for (var name in attrib) {
		    	if (name == 'unselectable')
		    		this.getElement().unselectable = attrib[name];
		    	else if (name == 'className')
					this.getElement().className = attrib[name];
		    	else if (name == 'innerHTML')
					this.getElement().innerHTML = attrib[name];
		    	else {
		    		try {
		    			if (attrib[name] == null)
		    				this.getElement().removeAttribute(name); 
		    			else
							this.getElement().setAttribute(name, attrib[name],0);
					} catch(ex) {
//						this.getElement()[name] = attrib[name];
					}
				}
			}
		}
	},
	show : function() {
		this.setStyle({display:''});
	},
	hide : function() {
		this.setStyle({display:'none'});
	},
	toggle : function() {
		if (this.getObject().style.display == '' || this.getObject().style.display == 'block')
			this.hide();
		else
			this.show();
	},
	getOffset : function() {
		var l = (parseInt(this.getObject().style.left) || 0);
		var t = (parseInt(this.getObject().style.top) || 0);
		return [l, t];
	},
	setOffset : function(x, y) {
		if (x != null && y != null)
			this.setStyle({left : (typeof x == 'number') ? x +'px' : x, top : (typeof y == 'number') ? y +'px' : y});
		else if (x != null) 
			this.setStyle({left : (typeof x == 'number') ? x +'px' : x});
		else if (y != null) 
			this.setStyle({top : (typeof y == 'number') ? y +'px' : y});
	},
	setOffsetBy : function(x, y) {
		var pos = this.getOffset();
		this.setOffset(pos[0] + x, pos[1] +y);
	},
	cumulativeOffset : function() {
		return cafen.cumulativeOffset(this.getElement());
	},
	getSize : function() {
		var w = (this.getElement().offsetWidth || parseInt(this.getElement().style.width));
		var h = (this.getElement().offsetHeight || parseInt(this.getElement().style.height));
		return [w, h];
	},
	getObjectSize : function() {
		var w = (this.getObject().offsetWidth || parseInt(this.getObject().style.width));
		var h = (this.getObject().offsetHeight || parseInt(this.getObject().style.height));
		return [w, h];
	},
	setSize : function(w, h) {
		if (w != null) {
			if (w == 'auto')
				this.setStyle({width : 'auto'});
			else if (typeof w == 'number')
				this.setStyle({width : w + 'px'});
		}
		if (h != null) {
			if (h == 'auto')
				this.setStyle({height : 'auto'});
			else if (typeof h == 'number')
				this.setStyle({height : h + 'px'});
		}
	},
	setSizeBy : function(w, h) {
		var size = this.getSize();
		this.setSize(size[0] + w, size[1] + h);		
	},
    center : function(obj, options) {
		var size = this.getObjectSize();
		var objWidth = size[0];
		var objHeight = size[1];
    	if (obj == null) {
			var tarHeight = document.body.clientHeight;
			var tarWidth = document.body.clientWidth;
		    var deltaX =  window.pageXOffset
		                || document.body.scrollLeft
		                || document.documentElement.scrollLeft
		                || 0;
		    var deltaY =  window.pageYOffset
		                || document.body.scrollTop
		                || document.documentElement.scrollTop
		                || 0;
			this.setOffset(deltaX +Math.round((tarWidth - objWidth)/2), deltaY +Math.round((tarHeight - objHeight)/2));
		} else {
			if (obj.getOffset) {
				var size = obj.getSize();
				var pos = obj.getOffset();
				var tarWidth = size[0];
				var tarHeight = size[1];
				this.setOffset(Math.round((tarWidth - objWidth)/2), Math.round((tarHeight - objHeight)/2));
			}
		}	
    },
    showAnimate : function(dir) {
		 this.show();
		 this.setStyle({overflowY :'visible', height:'auto'});
		 var size = this.getSize();
		 this.setStyle({overflowY :'hidden'});
		 this.setSize(null,1);
		 this.setAnimate(null, size[1], null, null);
    },
    hideAnimate : function(dir) {
		 this.setStyle({overflowY :'hidden'});
		 this.setAnimate(null, 1, null, null);
    },
    getFullSize : function() {
    	var size = this.getSize();
    	return[size[0] + this.getElement().scrollWidth, size[1] + this.getElement().scrollHeight];
    },
    setAnimate : function(w, h, x, y , dur) {
    	if (h == 'hidden') {
   			this.setStyle({overflowY : 'hidden'});
  			h = 0;
  		}
  		if (h == 'max') {
  			var fullsize = this.getFullSize();
  			h = fullsize[1];	
   		}
   		
		this.options.moveSchedule = [];
		if (this.options.animateStartBind == null)
			this.options.animateStartBind = this.animateStart.bind(this);
		var aniBind = [0, -1, -2,-1,0,1,2,4,6,8,10,12,14,16,18,20,18,17,18];
    	var pos = this.getOffset();
    	var size = this.getSize();
    	var posStepX = (x != null) ? x - pos[0] : 0;
    	var posStepY = (y != null) ? y - pos[1] : 0;
    	var sizeStepX = (w != null) ? w - size[0] : 0;
    	var sizeStepY = (h != null) ? h - size[1] : 0;
		for(var i = 0; i < aniBind.length; i++) {
			var moveRate = Math.sin(Math.PI * aniBind[i]/36);
			if (aniBind[i] > 18)
				moveRate = 2 - moveRate;
			var sizeX =  (sizeStepX != 0) ? Math.round(size[0] + sizeStepX * moveRate) : null;
			var sizeY =  (sizeStepY != 0) ? Math.round(size[1] + sizeStepY * moveRate) : null;
			if (sizeX < 1) 
				sizeX = null;
			if (sizeY < 1) 
				sizeY = null;
			var moveX =  (posStepX != 0) ? Math.round(pos[0] + posStepX * moveRate) : null;
			var moveY =  (posStepY != 0) ? Math.round(pos[1] + posStepY * moveRate) : null;
			this.options.moveSchedule.push([sizeX, sizeY,moveX,moveY]);
		}
    	if (this.timer != null)
    		clearTimeout(this.timer);
    	if (this.options.moveSchedule.length > 0)
			this.animateStart();
    },
	animateStart : function() {
		var currMove = this.options.moveSchedule[0];
		var w = currMove[0];
		var h = currMove[1];
		var x = currMove[2];
		var y = currMove[3];
		this.options.moveSchedule.shift();
		this.setSize(w,h);
		this.setOffset(x,y);
    	if (this.options.moveSchedule.length > 0) 
			this.timer = setTimeout(this.options.animateStartBind, 5);
		else {
			if ((w != null && w <= 1) || (h != null && h <= 1))  	
				this.getElement().style.display = 'none';
			else if ((w != null && w > 1) && (h != null && h > 1))  	
				this.setStyle({overflowX : 'visible', overflowY : 'visible', width : 'auto', height : 'auto'});
			else if (w != null && w > 1)
				this.setStyle({overflowX : 'visible', width : 'auto'});
			else if (h != null && h > 1) 
				this.setStyle({overflowY : 'visible', height : 'auto'});
		}
    },
    appendChild : function(obj, tpltaget) {
		switch(tpltaget) {
			case 'top' :
			case 'bottom' :
				this.getElement(tpltaget).innerHTML = '';
				break;
		}
		if (obj.getElement) {
			obj.parentNode = this;
			this.childNodes.push(obj);
			return this.getElement(tpltaget).appendChild(obj.getObject());
		} else {
			if (typeof obj == 'string') {
				this.getElement(tpltaget).innerHTML =obj;
				return this.getElement(tpltaget).childNodes[0];
			} else
				return this.getElement(tpltaget).appendChild(obj);
		}
	},
	removeChild : function(obj) {
		if (obj.getElement) {
			obj.parentNode = null;
			return obj.getObject().parentNode.removeChild(obj.getObject());
		} else
			obj.parentNode.removeChild(obj);
	}
}

cafen.Image = function(src, options) {
	if (options == null)
		options = {};
	if (/png$/.test(src) && cafen.browser.isIE && cafen.getVersion() < 7) {
		options.attribute = cafen.extend(options.attribute, {src : src});
		options.style = cafen.extend(options.style, {filter : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+ src+',sizingMethod=image);'});
	} else
		options.attribute = cafen.extend(options.attribute, {src : src});
	this.setOptions(cafen.extend(options, {tag : 'img'}));	
	this._retry = this.options.retry || 0;
	this.initImage();
}

cafen.Image.prototype = cafen.extendClass({
	_imgLoaded : true,
	_retry_count : 0,
	_retry : 0,
	initImage : function() {
		if (this.options.scale != null) 
			this.setStyle({position : 'relative'});
		this.setImage(this.getElement().src);
	},
	setImage : function(src) {
		if (src == '')
			return ;
		this.tmpImg = new Image();
		this.tmpImg.onerror = this.loadFailure.bind(this);
		this.tmpImg.src = src;
		if (this.tmpImg.width != null && this.tmpImg.width != 0) {
			this.autoResize();
		}else {
			this.tmpImg.onload = this.autoResize.bind(this);
		}
	},
	isLoaded : function() {
		return this._imgLoaded;
	},
	getImageUrl : function() {
		return this.getElement().src;
	},
	getImageSize : function() {
		if (this.isLoaded())
			return [this.tmpImg.width, this.tmpImg.height];
		else
			return [0,0];
	},
	loadFailure : function() {
		this._retry_count ++;
		if (this._retry_count > this._retry) {
			this._retry_count = 0;
			this._imgLoaded = false;
			this.setImage(_cafen_service_url+'images/ico_err.jpg');
			this.execEvent('fail');
		} else 
			window.setTimeout(this.setImage.bind(this, this.tmpImg.src +'?'+this._retry_count), 1000);
	},
	alphaBlend : function() {
		this._tmpAlpha ++;
		if (this._tmpAlpha <= 5) 
			this.setOpacity(Math.abs(this._tmpAlpha*20));
		if (this._tmpAlpha == 0)
			this.getElement().src = this.tmpImg.src;
		if (this._tmpAlpha < 5) 
			window.setTimeout(this.alphaBlend.bind(this), 5);
	},
	playAnimate : function() {
		if (this._imgLoaded) 
			this.autoResize();
	},
	autoResize : function() {
		this._imgLoaded = true;
		var size = [parseInt(this.options.style.width), parseInt(this.options.style.height)];
		var orgsize = [this.tmpImg.width, this.tmpImg.height];
		if (this.options.scale == null) 
			this.setStyle({left : '0px', top : '0px', width : this.tmpImg.width +'px' , height : this.tmpImg.height +'px'});
		try {
			if (document.all){
				if (this.getElement().parentNode != null) {
					if (this.getElement().filters.length == 0)
						this.setStyle({filter: 'progid:DXImageTransform.Microsoft.Pixelate(maxsquare=5)'});
					if (this.getElement().filters.length == 0) {
						this.setStyle({filter: ''});
						this.getElement().src = this.tmpImg.src;
					} else {
						this.getElement().filters[0].Stop()
						this.getElement().filters[0].Apply()
						this.getElement().src = this.tmpImg.src;
						this.getElement().filters[0].Play();
					}
				} else
					this.getElement().src = this.tmpImg.src;
			} else {
				this._tmpAlpha = -5;
				this.alphaBlend();
			}
		} catch(ex) {
			this._tmpAlpha = -5;
			this.alphaBlend();
		}	
		if (this.options.scale == null) 
			return ;
		if (orgsize[0] == 0)
			window.setTimeout(this.autoResize.bind(this), 100);
		else if (size[0] > orgsize[0] &&  size[1] > orgsize[1]) {
			this.lastSize = orgsize;
			var leftOffset = (size[0] - orgsize[0]) /2; 
			var topOffset = (size[1] - orgsize[1]) /2;
			this.setAnimate(orgsize[0], orgsize[1], leftOffset, topOffset);
		} else {
			switch (this.options.scale) {
				case 'width' :
					var imgheight = Math.round(orgsize[1] * size[0]/orgsize[0]);
					var imgtop = (size[1] - imgheight)/2;
					this.setAnimate(size[0], imgheight, 0, imgtop);
					break;
				case 'height' :
					var imgwidth = Math.round(orgsize[0] * size[1]/orgsize[1]);
					var imgleft = (size[0] - imgwidth)/2;
					this.setAnimate(imgwidth, size[1], imgleft, 0);
					break;
				case 'max' :
					var imgRate = size[0]/size[1];
					var orgRate = orgsize[0]/orgsize[1];
					this.options.scale = (imgRate < orgRate) ? 'width' : 'height';
					this.autoResize();		
					break;
				case 'min' :
					var imgRate = size[0]/size[1];
					var orgRate = orgsize[0]/orgsize[1];
					this.options.scale = (imgRate > orgRate) ? 'width' : 'height';
					this.autoResize();		
					break;
			}
		}
	},
    setAnimate : function(w, h, x, y , dur) {
    	if (h == 'hidden') {
   			this.setStyle({overflowY : 'hidden'});
  			h = 0;
  		}
  		if (h == 'max') {
  			var fullsize = this.getFullSize();
  			h = fullsize[1];	
   		}
   		if (this.lastSize != null &&  this.lastSize == [w,h])
   			return ;
   		this.lastSize = [w, h];
		this.options.moveSchedule = [];
		if (this.options.animateStartBind == null)
			this.options.animateStartBind = this.animateStart.bind(this);
		var aniBind = [0, -1, -2,-1,0,1,2,4,6,8,10,12,14,16,18,20,18,17,18];
    	var pos = this.getOffset();
    	var size = this.getSize();
    	var posStepX = (x != null) ? x - pos[0] : 0;
    	var posStepY = (y != null) ? y - pos[1] : 0;
    	var sizeStepX = (w != null) ? w - size[0] : 0;
    	var sizeStepY = (h != null) ? h - size[1] : 0;
		for(var i = 0; i < aniBind.length; i++) {
			var moveRate = Math.sin(Math.PI * aniBind[i]/36);
			if (aniBind[i] > 18)
				moveRate = 2 - moveRate;
			var sizeX =  (sizeStepX != 0) ? Math.round(size[0] + sizeStepX * moveRate) : null;
			var sizeY =  (sizeStepY != 0) ? Math.round(size[1] + sizeStepY * moveRate) : null;
			if (sizeX < 1) 
				sizeX = null;
			if (sizeY < 1) 
				sizeY = null;
			var moveX =  (posStepX != 0) ? Math.round(pos[0] + posStepX * moveRate) : null;
			var moveY =  (posStepY != 0) ? Math.round(pos[1] + posStepY * moveRate) : null;
			this.options.moveSchedule.push([sizeX, sizeY,moveX,moveY]);
		}
    	if (this.timer != null)
    		clearTimeout(this.timer);
    	if (this.options.moveSchedule.length > 0)
			this.animateStart();
    },
	animateStart : function() {
		var currMove = this.options.moveSchedule[0];
		if (currMove == null)
			return ;
		var w = currMove[0];
		var h = currMove[1];
		var x = currMove[2];
		var y = currMove[3];
		this.options.moveSchedule.shift();
		this.setSize(w,h);
		this.setOffset(x,y);
    	if (this.options.moveSchedule.length > 0) 
			this.timer = setTimeout(this.options.animateStartBind, 5);
		else {
			if ((w != null && w <= 0) || (h != null && h <= 0))  {
				this.getElement().style.display = 'none';
			}
		}
    }
  },cafen.Element.prototype);

cafen.XImage = function(icon, options) {
	if (options == null)
		options = {style :{}};
	if (icon.w != null)
		options.style.width = icon.w +'px';
	if (icon.w != null)
		options.style.height = icon.h +'px';
	if (icon.className != null)
		this.setOptions(cafen.extend({tag : 'div', attribute :{className : icon.className}, style : {overflow : 'hidden', backgroundPosition: '-'+icon.x+'px -'+icon.y+'px'}},options));
	else
		this.setOptions(cafen.extend({tag : 'div', attribute :{innerHTML : icon.text}, style : {overflow : 'hidden', fontSize : '10px'}},options));
}

cafen.XImage.prototype = cafen.extendClass({
	setIcon : function(className, x, y) {
		if (className != null)
			this.setAttribute({className : className});
		this.setStyle({backgroundPosition: '-'+x+'px -'+y+'px'});		
	}
},cafen.Element.prototype);

cafen.Input = function(options) {
	this.setOptions(cafen.extend(options, {tag : 'input'}));	
	this.initInput();
}
cafen.Input.prototype = cafen.extendClass({
	initInput : function() {
		this.attachEvent('click', this.inputClick.bind(this));	
		if (this.options.tag == 'input')
			this.getElement().onkeydown =  this.keyInput.bindAsEventListener(this);
	},
	getValue : function() {
		return this.getElement().value;	
	},
	setValue : function(val) {
		this.getElement().value = val;
	},
	keyInput : function(event) {
		if (event.keyCode == 13) {
			this.execEvent('end', event);
			return false;
		} else if ((event.keyCode >= 33 && event.keyCode <= 40 ) || event.keyCode == 8 || event.keyCode == 16 || event.keyCode == 18 || event.keyCode == 20 || event.keyCode == 45  || event.keyCode == 46  || event.keyCode == 229 )
			return true;
		else {
			if (this.options.validValue != null) {
				if (this.options._validValue == null) {
					this.options._validValue = [];
					var tmpNum = [];
					if (	this.options.validValue.indexOf('num') != -1) {
						tmpNum.push([48,57, false]);
						tmpNum.push([96,105, false]);
					}
					if (	this.options.validValue.indexOf('alpha') != -1) {
						tmpNum.push([65,90, null]);
					}
					this.options._validValue = tmpNum;
				}
				var result = false;
				for (var i = 0; i < this.options._validValue.length; i++) {
					if ((this.options._validValue[i][2] == null || event.shiftKey == this.options._validValue[i][2]) && event.keyCode >= this.options._validValue[i][0] &&  event.keyCode <= this.options._validValue[i][1]) {
						result = true;
						break;
					}
				}
				return result;
			} else
				return true;
		}
	},
	focus : function() {
		this.getElement().select();
		this.getElement().focus();
	},
	inputClick : function() {
		this.getElement().select();
		this.getElement().focus();
	}
},cafen.Element.prototype);

cafen.XInput = function(options) {
	this.setOptions(cafen.extend({tag : 'input', className : 'r-inputskin', validValue: null, style : {zIndex: 1000, backgroundColor : '#ffffff'}}, options));
	this.initInput();
}
cafen.XInput.prototype = cafen.extendClass({
	isSelected : false,
	isError : false,
	initInput : function() {
		this.attachEvent('focus', this.inputFocus.bind(this));	
		this.attachEvent('blur', this.inputBlur.bind(this));	
		this.attachEvent('click', this.inputClick.bind(this));	
		this.attachEvent('mouseover', this.inputOver.bind(this));	
		this.attachEvent('mouseout', this.inputOut.bind(this));
		if (this.options.tag == 'input' || this.options.event.end != null)
			this.getElement().onkeydown =  this.keyInput.bindAsEventListener(this);
	},
	inputFocus : function() {
		this.isSelected = true;
		this.isError = false;
		this.setClassName('r-hit');
		return true;
	},
	inputBlur : function() {
		this.isSelected = false;
		if (!this.isError)
			this.setClassName('r-off');
		return true;
	},
	inputOver : function() {
		if (!this.isSelected)
			this.setClassName('r-over');
		return true;
	},
	inputOut : function() {
		if (!this.isSelected)
			this.setClassName('r-off');
		return true;
	},
	setError : function() {
		this.isError = true;
		this.setClassName('r-on');
	},
	getValue : function() {
		return this.getElement().value;	
	},
	setValue : function(val) {
		this.getElement().value = val;
	}
},cafen.Input.prototype);


cafen.XTextarea = function(options) {
	this.setOptions(cafen.extend({tag : 'textarea', className : 'r-inputskin', validValue: null, style : {zIndex: 1000, backgroundColor : '#ffffff', border : '0 none', overflowY : 'auto', overflowX : 'auto'}}, options));
	this.initInput();
}
cafen.XTextarea.prototype = cafen.extendClass({},cafen.XInput.prototype);

cafen.Radio = function(name, value, bl, options) {
	if (options == null)
		options = {};
	options.attribute = cafen.extend(options.attribute, {type : 'radio', name : name, value : value, checked : bl});
	this.setOptions(cafen.extend(options, {tag : 'input'}));	
}


cafen.Radio.prototype = cafen.extendClass({},cafen.Input.prototype);


cafen.Checkbox = function(name, value, bl, options) {
	if (options == null)
		options = {};
	options.attribute = cafen.extend(options.attribute, {type : 'checkbox', name : name, value : value, checked : bl});
	this.setOptions(cafen.extend(options, {tag : 'input'}));	
}

cafen.Checkbox.prototype = cafen.extendClass({},cafen.Input.prototype);

cafen.Textarea = function(options) {
	this.setOptions(cafen.extend({tag : 'textarea', style : {fontSize:'11px'}},options));	
}
cafen.Textarea.prototype = cafen.extendClass({
	getValue : function() {
		try {
			return this.getElement().value;	
		} catch(ex) {}
	},
	setValue : function(val) {
		try {
			this.getElement().value= val;
		} catch(ex) {}
	},
	setFocus : function() {
		this.getElement().focus();
	}
},cafen.Element.prototype);

cafen.Select = function(name, items, options) {
	this.setOptions(cafen.extend(options, {tag : 'select'}));	
	for(var i = 0; i < items.length; i++)
		this.addItems(items[i][0],items[i][1]);
}

cafen.Select.prototype = cafen.extendClass({
	addItems : function(txt, val) {
		var options = this.getElement().options;
		options[options.length] = new Option(txt, val, false, false);
	},
	getValue : function() {
		var element =  this.getElement();
		return element[element.selectedIndex].value;
	},
	getText : function() {
		var element =  this.getElement();
		return element[element.selectedIndex].text;
	}
},cafen.Element.prototype);

cafen.Headings = function(size, text, options) {
	if (options == null)
		options = {};
	options.attribute = cafen.extend(options.attribute, {innerHTML : text});
	this.setOptions(cafen.extend(options, {tag : 'h'+size}));	
}
cafen.Headings.prototype = cafen.extendClass({},cafen.Element.prototype);

cafen.Paragraphs = function(text, options) {
	if (options == null)
		options = {};
	options.attribute = cafen.extend(options.attribute, {innerHTML : text});
	this.setOptions(cafen.extend(options, {tag : 'p'}));	
}
cafen.Paragraphs.prototype = cafen.extendClass({},cafen.Element.prototype);

cafen.Links = function(href, text, target, options) {
	if (options == null)
		options = {};
	if (text == null || text == '')
		text = href;
	if (target == null || target == '')
		target = '_new';
	options.attribute = cafen.extend(options.attribute, {href : href, target : target, innerHTML : text});
	this.setOptions(cafen.extend(options, {tag : 'a'}));	
}
cafen.Links.prototype = cafen.extendClass({},cafen.Element.prototype);


cafen.Hr = function(options) {
	if (options == null)
		options = {};
	this.setOptions(cafen.extend(options, {tag : 'hr'}));	
}
cafen.Hr.prototype = cafen.extendClass({},cafen.Element.prototype);

cafen.Pre = function(text, options) {
	if (options == null)
		options = {};
	options.attribute = cafen.extend(options.attribute, {innerHTML : text});
	this.setOptions(cafen.extend(options, {tag : 'pre'}));	
}
cafen.Pre.prototype = cafen.extendClass({},cafen.Element.prototype);

cafen.Table = function(cols, options) {
	if (options == null)
		options = {};
	this.setOptions(cafen.extend(options, {tag : 'table', childNodes : cols}));	
}
cafen.Table.prototype = cafen.extendClass({},cafen.Element.prototype);

cafen.TableAuto = function(options) {
	if (options == null)
		options = {};
	this._currTbody = null;
	this._currTr = null;
	this._currTd = null;
	options.attribute = cafen.extend({cellPadding : 0, cellSpacing:0, border : 0, unselectable : 'on'}, options.attribute);
	this.setOptions(cafen.extend({tag : 'table', attribute : {className : 'r-table'}, style : {fontSize : '12px'}},options));	
}

cafen.TableAuto.prototype = cafen.extendClass({
	_currTbody : null,
	_currTr : null,
	_currTd : null,
	getCell : function(cols, rows) {
		if (this._currTd == null)
			this.addCell();
		var trObj = (rows == null || this._currTbody.childNodes.length <= rows) ? this._currTbody.childNodes[this._currTbody.childNodes.length -1] : this._currTbody.childNodes[rows];
		return (cols == null || trObj.childNodes.length <= cols) ? trObj.childNodes[trObj.childNodes.length -1] : trObj.childNodes[cols];
	},
	addChild : function(obj, cols, rows) {
		this.getCell(cols, rows).appendChild(obj);
	},
	addStyle : function(style, cols, rows) {
		this.getCell(cols, rows).setStyle(style);
	},
	addAttribute : function(style, cols, rows) {
		this.getCell(cols, rows).setAttribute(style);
	},
	addMouseEvent : function(outstyle, overstyle, cols, rows) {
		this.getCell(cols, rows).addMouseEvent(outstyle, overstyle);
	},
	clearCell : function(cols, rows) {
		var currCell = this.getCell(cols, rows);
		currCell.childNodes = [];
		currCell.getElement().innerHTML = '';
	},
	addText : function(txt, cols, rows) {
		this.getCell(cols, rows).getElement().innerHTML = txt;
	},
	getText : function(cols, rows) {
		return this.getCell(cols, rows).getElement().innerHTML;
	},
	addCell : function(obj) {
		if (this._currTr == null)
			this.addRow();
		var childNodes = (typeof obj == 'object') ? [obj] : [];
		this._currTd = new cafen.Cell('', {childNodes : childNodes, attribute:{unselectable : 'on'}});
		this._currTr.appendChild(this._currTd);
		if (obj != null && typeof obj != 'object') {
			this.addText(obj);
		}
		return this._currTd;
	},
	addRow : function(obj) {
		if (this._currTbody == null)
			this.addTBody();
		this._currTr = new cafen.Row([]);
		this._currTd = null;
		this._currTbody.appendChild(this._currTr);
		if (obj != null)
			this.addCell(obj);
		return this._currTr;
	},
	addTBody : function() {
		this._currTbody =  new cafen.Tbody([]);
		this.appendChild(this._currTbody);
		this._currTr = null;
	}
},cafen.Element.prototype);

cafen.Tbody = function(cols, options) {
	if (options == null)
		options = {};
	this.setOptions(cafen.extend(options, {tag : 'tbody', childNodes : cols}));	
}

cafen.Tbody.prototype = cafen.extendClass({
	insertRow : function() {
		return this.getElement().insertRow(-1);
	},
	insertCell : function(obj, text) {
		var cell = obj.insertCell(-1);
		if (typeof text == 'string')
			cell.innerHTML = text;
		else
			cell.appendChild(text);
		return cell;
	},
	replaceCell : function(obj, text) {
		if (typeof text == 'string')
			cell.innerHTML = text;
		else {
			cell.innerHTML = "";
			cell.appendChild(text);
		}
	}
},cafen.Element.prototype);

cafen.TableSimple = function(cols, options, coloptions, celloptions) {
	if (options == null)
		options = {};
	this.setOptions(cafen.extend(options, {tag : 'table'}));	
	var colObjs = [];
	for(var i = 0 ; i < cols.length; i++) {
		var cellObjs = [];
		for(var j = 0 ; j < cols[i].length; j++) 
			cellObjs.push(new cafen.Cell(cols[i][j], celloptions));
		colObjs.push(new cafen.Row(cellObjs, coloptions));
	}
	this.appendChild(new cafen.Tbody(colObjs));
}

cafen.TableSimple.prototype = cafen.extendClass({},cafen.Tbody.prototype);


cafen.Cell = function(text, options) {
	if (options == null)
		options = {};
	options.attribute = cafen.extend(options.attribute, {innerHTML : text, unselectable : 'on'});
	this.setOptions(cafen.extend(options, {tag : 'td'}));	
}
cafen.Cell.prototype = cafen.extendClass({
	addMouseEvent : function(outstyle, overstyle) {
		if (outstyle == null && overstyle == null) {
			if (this._attachEvents != null) {
				this.detachEvent('mouseover', this._attachEvents.over);	
				this.detachEvent('mouseout', this._attachEvents.out);	
				this._attachEvents = null;
			}
		} else {
			if (this._attachEvents == null) {
				this._attachEvents = {
					over :this.cellOver.bind(this),
					out :this.cellOut.bind(this)
				};
				this._attachEventsStyle = {
					over : overstyle,
					out : 	outstyle
				}
				this.attachEvent('mouseover', this._attachEvents.over);	
				this.attachEvent('mouseout', this._attachEvents.out);	
			}
		}
	},
	cellOver : function() {
		this.setStyle(this._attachEventsStyle.over);
		return true;
	},
	cellOut : function() {
		this.setStyle(this._attachEventsStyle.out);
		return true;
	},
	addText : function(text) {
		this.getElement().innerHTML = text;
	},
	addAttribute : function(attb) {
		this.setAttribute(attb);
	}
},cafen.Element.prototype);

cafen.Row = function(cells, options) {
	if (options == null)
		options = {};
	options.attribute = cafen.extend(options.attribute, {});
	this.setOptions(cafen.extend(options, {tag : 'tr',childNodes : cells}));	
}

cafen.Row.prototype = cafen.extendClass({},cafen.Element.prototype);



cafen.Iframe = function(options) {
	this.setOptions(cafen.extend(options, {tag : 'iframe'}));	
}
cafen.Iframe.prototype = cafen.extendClass({
	initIframe : function(htmlskin, designMode ) {
		if (cafen.browser.isIE || navigator.userAgent.toLowerCase().indexOf("opera")!=-1) {
			var docDomain = document.domain;
			this.getElement().src = 'javascript:void( (function(){' +  
				'document.open() ;' +  
				'document.write( "'+htmlskin+'"  );' +
				'document.close() ;' +
				'if (document.domain != "'+docDomain+'") ' +  
				'	document.domain = "'+docDomain+'"; ' +  
				' document.body.contenteditable = true; '+
				'})() )' ;
			if (designMode) {
				try {
					this.setDesignMode();
				} catch(ex) { 
					window.setTimeout(this.setDesignMode.bind(this),1);
				}
			}
		} else {
			this.getElement().src = 'javascript:void(0)' ;
			try {
				var editdoc = this.getElement().contentWindow.document;
				editdoc.open() ;
				editdoc.write(htmlskin);
				editdoc.close() ;
				if (designMode)
					editdoc.designMode= "On";
			} catch(ex) {}
		}
		this.getElement().contentWindow.onerror = function() { return true;}
	},
	setDesignMode : function() {
		this.getElement().contentWindow.document.body.contentEditable =  'true';
		
	},
	setContents : function(html) {
		this.getElement().contentWindow.document.body.innerHTML = html;
	}
},cafen.Element.prototype);


cafen.Div = function(options) {
	this.setOptions(cafen.extend({tag : 'div', style : {fontSize : '11px', overflow : 'visible', overflowX : 'visible', overflowY : 'visible'}},options));	
}
cafen.Div.prototype = cafen.extendClass({},cafen.Element.prototype);


cafen.Button = function(options) {
	this.setOptions(cafen.extend({tag : 'button', style :{fontSize : '11px', cursor : cafen.getCursor()}, attribute : {type : 'button'}}, options));	
	this.initButton();
}

cafen.Button.prototype = cafen.extendClass({
	initButton : function() {
		this.attachEvent('focus', this.buttonFocus.bind(this));	
	},
	buttonFocus : function() {
		this.getElement().blur();
		return true;
	},
	setDisable : function(bl) {
		if (bl) {
			this.setAttribute({disabled : true});
			this.setStyle({cursor : 'default'});
		} else {
			this.setAttribute({disabled : null});
			this.setStyle({cursor : cafen.getCursor()});
		}
	}
},cafen.Element.prototype);

cafen.Container = function() {}

cafen.Container.prototype =  cafen.extendClass({
	insertBefore : function(el) {
		
	},
	insertAfter : function(el) {
		
	},
	appendChild : function(obj) {
		if (obj.parentNode != null && obj.parentNode != this)
			obj.parentNode.removeChild(obj);
		obj.parentNode = this;
		this.childNodes.push(obj);
		this.getElement().appendChild(obj.getObject());
    },
    removeChild : function(obj) {
    	var childNodes_n = [];
		for(var i = 0; i < this.childNodes.length; i++) {
			if (this.childNodes[i] != obj) {
				childNodes_n.push(this.childNodes[i]);
			} else 
				obj.parentNode = null;
		}
		this.childNodes = childNodes_n;
	}
},cafen.Element.prototype);


cafen.XButton = function(options) {
	if (options == null)
		options = {};
	options.style = cafen.extend({border : '0 none', backgroundColor : 'transparent',fontSize:'12px', margin :'0', padding : '0', cursor : cafen.getCursor()},options.style);
	this.setOptions(cafen.extend(
		{
			tag : 'button', 
			className :'r-rbtnskin', 
			childNodes : cafen.getChildObject(options), 
			attribute :{unselectable : 'on', type : 'button'}
		},options));
	this.initButton();
}


cafen.XButton.prototype = cafen.extendClass({
	isSelected : false,
	initButton : function() {
		this.attachEvent('mouseover', this.buttonOver.bind(this));	
		this.attachEvent('mouseout', this.buttonOut.bind(this));	
		this.attachEvent('mousedown', this.buttonDown.bind(this));	
		this.attachEvent('mouseup', this.buttonOver.bind(this));	
		this.attachEvent('focus', this.buttonFocus.bind(this));	
	},
	buttonFocus : function() {
		this.getElement().blur();
		return true;
	},
	buttonOver : function() {
		this.setClassName('r-over');
		return true;
	},
	buttonOut : function() {
		if (!this.isSelected)
			this.setClassName('r-off');
		else
			this.setClassName('r-on');
		return true;
	},
	buttonDown : function() {
		this.setClassName('r-hit');
		return true;
	},
	setSelected : function(bl) {
		this.isSelected = bl;
		if (this.isSelected)
			this.setClassName('r-on');
		else 
			this.setClassName('r-off');
	}
},cafen.Element.prototype);


cafen.XIcon = function(options) {
	this.movePos = [options.off, options.on, options.over];
	if (options.src != null)
		this.setOptions(cafen.extend({tag : 'button', className :'', attribute :{type : 'button'}, style : {border : '0 none', backgroundColor : 'transparent',overflow : 'hidden', backgroundImage : 'url('+options.src+')',backgroundPosition: '0px -'+options.off+'px'}},options));
	else 
		this.setOptions(cafen.extend({tag : 'button', className :'', attribute :{className:options.icon, 'type' : 'button'}, style : {overflowX : 'hidden', overflowY : 'hidden', backgroundPosition: '0 -'+options.off+'px'}},options));
	this.initButton();
}

cafen.XIcon.prototype = cafen.extendClass({
	movePos : null,
	isSelected : false,
	isDisabled : false,
	initButton : function() {
		this.isSelected = false;
		this.isDisabled = false;
		this.attachEvent('mouseover', this.buttonOver.bind(this));	
		this.attachEvent('mouseout', this.buttonOut.bind(this));	
		this.attachEvent('mouseup', this.buttonOver.bind(this));	
//		this.getElement().onfocus = function() {this.blur();};
		this.attachEvent('focus', this.buttonFocus.bind(this));	
	},
	buttonFocus : function() {
		this.getElement().blur();
		return true;
	},
	setChildDisable : function(bl) {
		var mouseCursor = (!bl) ? cafen.getCursor() : 'default';
		for(var i = 0; i < this.childNodes.length; i++) {
			this.childNodes[i].setStyle({cursor : mouseCursor});
		}	
	},
	setDisable : function(bl) {
		this.isDisabled = bl;
		if (bl) {
			this.setAttribute({disabled : true});
			this.setStyle({cursor : 'default'});
		} else {
			this.setAttribute({disabled : null});
			this.setStyle({cursor : cafen.getCursor()});
		}
		this.setChildDisable(bl);
		this.setButton(false);
	},
	setButton : function(bl) {
		var x = (bl) ? this.movePos[2] : 0;
		var y = null;
		if (this.isDisabled)
			y = this.movePos[0] + this.movePos[1] * 2;
		else 
			y = (this.isSelected) ? this.movePos[0] + this.movePos[1] : this.movePos[0];
		this.setStyle({backgroundPosition : '-'+x+'px -'+y+'px'});
	},
	buttonOver : function() {
		this.setButton(true);
		return true;
	},
	buttonOut : function() {
		this.setButton(false);
		return true;
	},
	toggleSelect : function() {
		this.setSelected(!this.isSelected);
		return this.isSelected;
	},
	setSelected : function(bl) {
		this.isSelected = bl;
		this.setButton(false);
	}
},cafen.Element.prototype);


cafen.XTab = function(options) {
	this.setOptions(
		cafen.extend(
			{
				tag : 'button', 
				className :'r-tab', 
				childNodes : cafen.getChildObject(options), 
				attribute : {unselectable : 'on', type : 'button'}, 
				style : {
					border : '0', 
					padding : '0',
					backgroundColor : 'transparent', 
					cursor : cafen.getCursor(), 
					fontSize : '12px',
					textAlign : 'center',
					verticalAlign: 'middle',
					height : '17px'
				}
			},options
		)
	);
	this.initTab();
}

cafen.XTab.prototype = cafen.extendClass({
	isSelected : false,
	initTab : function() {
		this.attachEvent('mouseover', this.buttonOver.bind(this));	
		this.attachEvent('mouseout', this.buttonOut.bind(this));	
		this.attachEvent('mousedown', this.buttonDown.bind(this));	
		this.attachEvent('mouseup', this.buttonOver.bind(this));
		this.attachEvent('focus', this.buttonFocus.bind(this));
	},
	buttonFocus : function() {
		this.getElement().blur();
	},
	buttonOver : function() {
		if (!this.isSelected)
			this.setClassName('r-over');
		return true;
	},
	buttonOut : function() {
		if (!this.isSelected)
			this.setClassName('r-off');
		return true;
	},
	buttonDown : function() {
		if (!this.isSelected)
			this.setClassName('r-hit');
		return true;
	},
	setSelected : function(bl) {
		if (this.isSelected != bl) {
			this.isSelected = bl;
			if (bl)
				this.setClassName('r-on');
			else 
				this.buttonOut();
		}
	}
},cafen.Element.prototype);

cafen.XTabMenu = function(childNodes, options) {
	if (options == null)
		options = {};
	this._currTbody = null;
	this._currTr = null;
	options.attribute = cafen.extend({cellpadding : 0, cellspacing:0, border : 0, unselectable : 'on' }, options.attribute);
	this.setOptions(cafen.extend({tag : 'table', attribute : {className : 'r-table'},style : {position : 'relative', top : '1px', left : '3px'}},options));	
	this.initTabMenu(childNodes)
}

cafen.XTabMenu.prototype = cafen.extendClass({
	_lastSelected : null,
	initTabMenu : function(childNodes) {
		this.addRow();
		for(var i =0; i < childNodes.length; i++) {
			childNodes[i].parentTab = this;
			this.addCell(childNodes[i]);
			this.addStyle({verticalAlign :'bottom'});
		}
	},
	setSelected : function(obj) {
		if (this._lastSelected != null)
			this._lastSelected.setSelected(false);
		obj.setSelected(true);
		this._lastSelected = obj;
	}
},cafen.TableAuto.prototype);


cafen.XSelect = function(items, item_width, options) {
	this.setOptions(cafen.extend({tag : 'div', attribute :{}, style : {width: item_width +'px', textAlign:'left'}, dropDown : {}},options));
	var itemContents = new cafen.TableAuto({attribute:{width:'100%', border : '0',className : 'r-table'}});
	this.appendChild(itemContents);
	this._displayObj = new cafen.XInput({style : {width:(item_width -20) +'px', height:'17px'}, event : {end : this.sendValue.bind(this)}});
	itemContents.addCell(this._displayObj);
	this._dropdownObj = new cafen.XIcon({icon :'r-iconset', on : -15, off : 75, over : 15, event : {click: this.toggleItem.bind(this)}, style :{width:'15px', height:'15px'}});
	itemContents.addCell(this._dropdownObj);
	itemContents.addStyle({paddingLeft:'3px',width:'20px'});
	
	this._itemObj = new cafen.Div(cafen.extend({className :'r-boxwhite', style : {display : 'none', position : 'absolute', height: 'auto', marginTop : '1px', zIndex:'500'}},this.options.dropDown));
	this.appendChild(this._itemObj);
	this.initSelect(items, item_width - 20, options);	
}

cafen.XSelect.prototype = cafen.extendClass({
	_displayObj : null,
	_itemObj : null,
	_isItemshow : false,
	_selectedItem : null,
	_selectedIndex : null,
	_selectedValue : null,
	_dropdownObj : null,
	_itemChild : [],
	_xMenu : null,
	initSelect : function(items, item_width, options) {
		this.setChildObject(items);
		this._itemwidth = item_width;
	},
	setChildObject : function(items) {
		this._xMenu = null;
		this._itemChild = items;
	},
	drawChild : function() {
		var menuItem = [];
		for(var i = 0; i < this._itemChild.length; i++) 
			menuItem.push({text: this._itemChild[i].text , icon : this._itemChild[i].icon, onclick : this.setIndex.bind(this, i)});
		this._xMenu = new cafen.XMenu(menuItem, this._itemwidth, cafen.extend(this.options,{style:{overflowY : 'auto', overflowX :'hidden'}}));
		this._itemObj.appendChild(this._xMenu);
	},
	sendValue : function(obj) {
		if (this.getValue() != this._selectedValue)
			this._selectedIndex = null;
		this.execEvent("change",null);
	},
	toggleItem : function() {
		if (this._xMenu == null)
			this.drawChild();
		this._isItemshow = ! this._isItemshow;
		if (this._isItemshow) {
			this._itemObj.show();
			this._dropdownObj.setSelected(true);
		} else {
			this._itemObj.hide();
			this._dropdownObj.setSelected(false);
		}
	},
	setIndex : function(no) {
		this._selectedIndex = no;
		this._selectedValue = this._itemChild[no].text;
		this._displayObj.setValue(this._selectedValue);
		this.execEvent("change",null);
		if (this._isItemshow)
			this.toggleItem();
	},
	getIndex : function() {
		return this._selectedIndex;
	},
	getValue : function() {
		return this._displayObj.getValue();
	},
	setValue : function(val) {
		this._displayObj.setValue(val);
	}
},cafen.Element.prototype);


cafen.XMenu = function(menus, menu_width, options) {
	this.setOptions(cafen.extend(options,{tag : 'div', style : {width : menu_width +'px', textAlign:'left'}, attribute : {className : 'r-menu'}}));
	this.initMenu(menus, menu_width, options);	
}

cafen.XMenu.prototype = cafen.extendClass({
	_lastshownChild : null,
	_subItems : [],
	_buttonClassName : null,
	_menuWidth : null,
	isSelected : false,
	initMenu : function(menus, menu_width, options) {
		this._buttonClassName = (options.buttonClass == null) ? 'r-tbtnskin' : options.buttonClass;
		this.onChildSelectBind = this.onChildSelect.bind(this);
		this._subItems = [];
		this._menuWidth = (this.options.style.overflowY != 'hidden' && this.options.style.overflowY != 'show') ? menu_width - 25 : menu_width - 7;
		for(var i = 0; i < menus.length; i++) 
			this.appendItem(menus[i]);
	},
	getSelected : function() {
		var selectedChild = [];
		for(var i =0 ; i < this._subItems.length; i++) {
			if (	this._subItems[i].isSelected)
				selectedChild.push(this._subItems[i]);
		}
		return selectedChild;
	},
	getItems : function() {
		return this._subItems;
	},
	onChildSelect : function(obj) {
		this.execEvent('select', obj);
	},
	reSize : function(menu_width) {
		this._menuWidth = (this.options.style.overflowY != 'hidden' && this.options.style.overflowY != 'show') ? menu_width - 25 : menu_width - 7;
		for(var i = 0; i < this._subItems.length; i++) {
			this._subItems[i].setStyle({width: this._menuWidth +'px'});
		}
	},
	appendItem : function(currMenu) {
		if (typeof currMenu == 'string') {
			var itemObj = new cafen.Div({attribute:{className :'r-line', innerHTML :'&#160;'}, style : {overflow :'hidden', fontSize:'1px', width:'100%'}});
			this.appendChild(itemObj);
			return null;
		} else {
			var text = 	currMenu.text;
			var height = currMenu.height ?  currMenu.height : '18px';
			var itemObj = new cafen.Div({style:{marginBottom : '2px', textAlign:'left'}});
			this.appendChild(itemObj);
			var subitem = null, subItemArea = null;
			if (currMenu.items != null && currMenu.items.length > 0) {
				subItemArea = new cafen.Div({style:{position:'absolute', display: 'none',left :( this._menuWidth+15) +'px'}});
				itemObj.appendChild(subItemArea);
				subitem = new cafen.XMenu(currMenu.items, (currMenu.width) ? currMenu.width : this._menuWidth+15, this.options);
				subItemArea.appendChild(subitem);
			}
			var itemContents = new cafen.TableAuto({attribute:{border : 0, width :  this._menuWidth}});
			if (currMenu.icon != null) 
				itemContents.addCell(new cafen.XImage(currMenu.icon , {style : {width : '16px', height :'16px', overflow : 'hidden'}}));
			else if (currMenu.src != null)
				itemContents.addCell(new cafen.Image(currMenu.src,{}));
			else
				itemContents.addCell(new cafen.Div({}));
			itemContents.addStyle({width : '16px', textAlign:'center'});
			itemContents.addCell(new cafen.Div({attribute:{innerHTML : text}, style : {paddingLeft : '7px', paddingTop : '1px',fontSize:'11px', whiteSpace: 'nowrap', width : (this._menuWidth - ((subitem !=null)?50:16))+'px', overflowX : 'hidden'}}));
			itemContents.addStyle({textAlign:'left', width : (this._menuWidth - 16) +'px'});
			var itemButton = new cafen.XButton(cafen.extend({className : this._buttonClassName , childNodes : [itemContents], attribute : {}, style :{height: height, width : (this._menuWidth) +'px', overflowX : 'hidden', overflowY : 'hidden'}, itemOptions : currMenu.options },{}));
			if (currMenu.disabled == true) 
				itemButton.setDisable(true);
			itemButton.attachEvent('mouseover',this.showSub.bind(this));
			itemButton.attachEvent('mouseout',this.mouseOut.bind(this));
			if (currMenu.onclick != null ) 
				itemButton.attachEvent('click',currMenu.onclick);
			else
				itemButton.attachEvent('click',this.onChildSelectBind);
			if (subitem != null) {
				itemButton.linkObj = subitem;
				itemButton.linkArea = subItemArea;
				itemContents.addCell(new cafen.XImage({className :'r-iconset', x: 0, y:120, w : 15 , h : 16}));
				itemContents.addStyle({textAlign:'right', width:'15px'});
			}
			itemButton.linkName = text;
			this._subItems.push(itemButton);
			itemObj.appendChild(itemButton);
			return itemButton;
		}		
	},
	removeItem : function(obj) {
		var newChild = [];
		for(var i =0 ; i < this._subItems.length; i++) {
			if (obj == this._subItems[i])
				obj.parentNode.parentNode.removeChild(obj.parentNode);
			else
				newChild.push(this._subItems[i]);
		}
		this._subItems = newChild;
	},
	setSelectToggle : function(obj) {
		if (!obj.isSelected)
			obj.setSelected(true);
		else
			obj.setSelected(false);
	},
	showSub : function(obj) {
		if (this._lastshownChild != obj) {
			if (obj.linkArea != null)
				obj.linkArea.show();
			if (this._lastshownChild != null && this._lastshownChild.linkArea != null)
				this._lastshownChild.linkArea.hide();
			this._lastshownChild = obj;
		}
		return true;
	},
	mouseOut : function(obj) {
		return true;
	}
},cafen.Element.prototype);


cafen.XFolder = function(menus, options) {
	options = cafen.extend({useanimate : true}, options);
	this.setOptions(cafen.extend({tag : 'div', style : {overflow : 'hidden', textAlign:'left'}, attribute : {className : 'r-folder'}},options));
	this.initFolder(menus, options);	
}

cafen.XFolder.prototype = cafen.extendClass({
	_lastshownChild : null,
	_subItems : [],
	_isFolder : true,
	_folderIcon : {'trace' : 190, 'folder' : 197, 'exe' : 176, 'bmp' : 180, 'psd' : 186, 'pdf' : 188,'ppt' : 187,'xls' : 184,'mp3' : 179,'doc' : 178,'htm' : 175,'hwp' : 173,'gif' : 175,'jpg' : 172, 'zip' : 183, 'imagefolder' : 195, 'musicfolder' : 194, 'checkfolder' : 196,'openfolder' : 199, 'text' : 192, 'textcolor' : 193, 'cd' : 198},
	initFolder : function(menus, options) {
		this._subItems = [];
		var len = menus.length;
		for(var i = 0; i < len; i++) {
			var tmpOptions = cafen.extend({},options);
			var isLast = (i == (len - 1)) ? true : false;
			var currMenu = menus[i];
			var haveChild = (currMenu.items != null && currMenu.items.length > 0 || currMenu.xmlurl != null) ? true : false;
			var text = 	currMenu.text;
			var itemObj = new cafen.Div({style:{height: 'auto', overflowX : 'hidden', overflowY : 'hidden'}});
			this.appendChild(itemObj);
			var itemContents = new cafen.TableAuto({attribute:{border : 0, width : '400px'}});
			if (currMenu.icon != null) {
				itemContents.addCell(new cafen.XImage(currMenu.icon));
				itemContents.addStyle({width : '17px', paddingLeft : '1px', textAlign:'left'});
			} else if (currMenu.type != null && currMenu.type != '') {
				var iconInfo = {className : 'r-editorset', x : 0, y : 0, w:16, h:16};
				var no = (this._folderIcon[currMenu.type] != null) ? this._folderIcon[currMenu.type] : 192;
				iconInfo.x = (no % 10) * 16;
				iconInfo.y = (Math.floor(no / 10))*16;
				itemContents.addCell(new cafen.XImage(iconInfo));
				itemContents.addStyle({width : '17px', paddingLeft : '1px', textAlign:'left'});
			} else if (currMenu.src != null) {
				itemContents.addCell(new cafen.Image(currMenu.src,{}));
				itemContents.addStyle({width : '17px', paddingLeft : '1px', textAlign:'left'});
			}
			itemContents.addCell(new cafen.Div({attribute:{innerHTML : text}, style : {whiteSpace: 'nowrap',overflow : 'hidden', width:'200px', height :'16px', marginLeft :'3px'}}));
			itemContents.addStyle({textAlign:'left'});
			var folderClass = '';
			if (haveChild)
				folderClass = isLast ? 'r-eclose' : 'r-mclose';
			else
				folderClass = isLast ? 'r-eempty' : 'r-mempty';
			var itemButton = new cafen.Button(cafen.extend({childNodes : [itemContents], attribute : {className : folderClass, unselectable : 'on'}, style :{textAlign:'left',height: '18px'}, seqn : i},currMenu));
			if (currMenu.disabled == true) 
				itemButton.setDisable(true);
			itemButton.attachEvent('click',this.toggleFolder.bind(this));
			itemObj.appendChild(itemButton);
			var subitem = null, subItemArea = null;
			if (haveChild) {
				subItemArea = new cafen.Div({attribute:{className: isLast ? 'r-echild' : 'r-mchild'}, style :{display:'none', overflowX :'hidden'}});
				itemObj.appendChild(subItemArea);
				if (currMenu.items != null && currMenu.items.length > 0) {
					var childOptions = cafen.extend(tmpOptions, {className : '', shadow : false});
					if (currMenu.onclick != null)
						 childOptions.onclick = currMenu.onclick;
					subitem = new cafen.XFolder(currMenu.items, childOptions);
					subItemArea.appendChild(subitem);
				}
			}
			if (currMenu.onclick != null ) 
				itemButton.attachEvent('click',currMenu.onclick);
			else if (tmpOptions.onclick != null ) 
				itemButton.attachEvent('click',tmpOptions.onclick);
			itemButton.getParent = 	function() {
				var parentObj = this.parentNode;
				while (parentObj) {
					if (	parentObj._isFolder) {
						if (parentObj.parentNode && parentObj.parentNode.parentNode) 
							return parentObj.parentNode.parentNode.childNodes[0];
						else
							return null;
					}else
						parentObj = parentObj.parentNode;
				}
				return null;
			}
			itemButton.getData = function(txt,ids) {
				txt = txt || 'text';
				ids = ids || [];
				ids.push(this.getOption(txt));
				var parentObj = this.getParent();
				if (parentObj != null && parentObj.getData)
					parentObj.getData(txt, ids);
				return ids;
			}
			itemButton.getOption = function(txt) {
				txt = txt || 'text';
				return this.options[txt] || '';
			}
			if (subItemArea != null) {
				itemButton.linkObj = subitem;
				itemButton.linkArea = subItemArea;
			}
			itemButton.linkName = text;
			itemButton.isOpened = false;
			itemButton.linkParent = this;
			if (haveChild)
				itemButton.classOpenClose = isLast ? ['r-eclose','r-eopen'] : ['r-mclose','r-mopen'];
			else
				itemButton.classOpenClose = isLast ? ['r-eempty','r-eempty'] : ['r-mempty','r-mempty'];
			this._subItems.push(itemButton);
		}
	},
	openClose : function(bl, seqns) {
		if (seqns != null) {
			if (seqns.length > 0) {
				var findObj = this.get(seqns[0]);
				if (findObj != null) {
					seqns.shift();
					this.openFolder(findObj, bl, true, seqns);
				}
			}
		} else {
			for (var i = 0; i < this._subItems.length; i++) {
				var obj = this._subItems[i];
				this.openFolder(obj, bl, true, null);
			}
		}
	},
	get : function(idx) {
		if (typeof idx == 'number') {
			if (idx < this._subItems.length)
				return this._subItems[idx];
			else 
				return null;
		} else {
			for (var i = 0; i < this._subItems.length; i++) {
				var currObj = this._subItems[i];
				if (currObj.getOption('id') == idx) {
					return currObj;
					break;
				}
			}
			return null;
		}
	},
	openFolder : function(obj, bl, cascade, seqns) {
		if (obj.isOpened != bl) {
			obj.isOpened = bl;
			if (obj.isOpened) {
				if (obj.linkArea != null) {
					if (obj.linkObj == null) {
						obj.linkArea.appendChild(new cafen.Div({attribute:{innerHTML :'xml loading...'}}));
						obj.linkObj = {}
					}
					if (this.options.useanimate)
						obj.linkArea.showAnimate('Y');
					else
						obj.linkArea.show();
				}
				obj.setClassName(obj.classOpenClose[1]);
			} else {
				if (obj.linkArea != null) {
					if (this.options.useanimate)
						obj.linkArea.hideAnimate('Y');
					else
						obj.linkArea.hide();
				}
				obj.setClassName(obj.classOpenClose[0]);
			}
		} 
		if (obj.linkArea != null && cascade) 
			obj.linkArea.childNodes[0].openClose(bl, seqns);
	},
	toggleFolder : function(obj) {
		this.openFolder(obj, !obj.isOpened);
		return true;
	}
},cafen.Element.prototype);



cafen.XPopupTitle = function(poptitle, options) {
	this.setOptions(cafen.extend(options, {tag : 'table', style : {width:'100%'}}));	
	var colObjs = [];
	var titleNode = new cafen.Cell(poptitle, {style : {textAlign:'left', cursor : 'move'}});
	colObjs.push(titleNode);
	titleNode.attachEvent('mousedown', this.startMove.bind(this));
	var optionObjs = [];
	var colseBtn  = new cafen.Button({attribute : {innerHTML : 'X'}, style: {border : '1px solid #121212'}, event : {'click' : this.togglePopup.bind(this)}});
	optionObjs.push(colseBtn);
	var optionsNode = new cafen.Cell('', {style: {width : '30px', textAlign:'right'}, childNodes : optionObjs});
	colObjs.push(optionsNode);
	this.appendChild(new cafen.Tbody([new cafen.Row(colObjs, {})]));
}

cafen.XPopupTitle.prototype = cafen.extendClass({
	isOpen : true,
	startMove : function(obj, event) {
		cafen.startDrag(event, obj, this.parentNode, 'H');
		return true;
	},
	togglePopup : function() {
		this.parentNode.setStyle({height : 'auto'});
		this.isOpen = !this.isOpen;
		if (this.isOpen) 
			this.parentNode.mainObj.setAnimate(null, null, 200, 300);
		else
			this.parentNode.mainObj.setAnimate(null, null, 200, 10);
	}
},cafen.Element.prototype);

cafen.XPopup = function(mainChild, options) {
	var baseClassName = options.className;
	var childNodes = [];	
	this.titleObj = new cafen.XPopupTitle(options.title, options)
	childNodes.push(this.titleObj);
	this.mainObj = new cafen.Div({attribute :{}, style : {border : '1px solid #464646', textAlign:'left', height: '300px'}});
	childNodes.push(this.mainObj);
	this.setOptions(cafen.extend(options, {tag : 'div', className : 'r-btnskin', shadow : true, childNodes : childNodes, attribute :{}, style : {}}));
}

cafen.XPopup.prototype = cafen.extendClass({
	titleObj : null,
	mainObj : null
},cafen.Container.prototype);

cafen.Resizable = function(mainChild, options) {
	mainChild = cafen.$(mainChild);
	var orgParent = mainChild.parentNode;
	this.setOptions(cafen.extend(options, {resize : 'XOOOOOOOO', resizeOption : {minWidth : 10, minHeight : 10, maxWidth : -1, maxHeight : -1, Increment : 1, preserveRatio: false}, tag : null, className : 'r-btnskin', childNodes : [], attribute :{}, style : {}}));
	if (	orgParent != null) {
		orgParent.insertBefore(this.getObject(), mainChild);
		this.setElement(mainChild);
	}	
}

cafen.Resizable.prototype = cafen.extendClass({
},cafen.Element.prototype);


cafen.Slider = function(options) {
	options = cafen.extend({size : 100, def : 0, min : 0, max : 100, step : 1, direct : 'X', useButton : true, event : {end : function() {}}}, options);
	this._objSize = (options.useButton) ? options.size - 36 : options.size;
	this._objDirect = options.direct;
	this._objMin = options.min;
	this._objMax = options.max;
	this._objStep = options.step;
	switch (this._objDirect) {
		case 'Y' : 
			var tmpTable = new cafen.TableAuto({style : {width : '15px', height : options.size +'px'}});
			if (	options.useButton) {
				tmpTable.addRow();
				tmpTable.addCell(new cafen.XIcon({
					icon:'r-iconset', on : 15,  off :255, over :15, 
					event : {
						mousedown : this.moveEvent.bind(this,false), 
						mouseup : this.stopMoveEvent.bind(this)}
				}));
				tmpTable.addStyle({paddingBottom:'3px'});
			}
			this.pointerObj = new cafen.XIcon(
				{
					icon:'r-iconset', on : 15,  off :330, over :15,  
					moveOption : {direction : 'Y', rangeX :null, rangeY :[-7, this._objSize -7]}, 
					event: {'dragend' : this.setMove.bind(this)},
					style:{position : 'absolute', top : '-3px', left :'-5px', width:'15px', height: '15px'}
				}
			);
			this.sliderObj = new cafen.Div({
				tag: 'div', 
				className : 'r-boxwhite',
				childNodes : [this.pointerObj], 
				style : {cursor : cafen.getCursor(), width: '5px', height: this._objSize +'px', position:'relative'},
				event : {click : this.setPointer.bind(this), keydown : this.keypress.bind(this)}
			});
			tmpTable.addRow();
			tmpTable.addCell(this.sliderObj);
			tmpTable.addStyle({paddingLeft:'2px'});
			if (	options.useButton) {
				tmpTable.addRow();
				tmpTable.addCell(new cafen.XIcon({
					icon:'r-iconset', on : 15,  off :240, over :15, 
					event : {
						mousedown : this.moveEvent.bind(this,true), 
						mouseup : this.stopMoveEvent.bind(this)}
				}));
				tmpTable.addStyle({paddingTop:'3px'});
			}
			this.setOptions(cafen.extend(options, {childNodes : [tmpTable]}));
			break;
		default :
			var tmpTable = new cafen.TableAuto({style : {height : '15px', width : options.size +'px'}});
			if (	options.useButton) {
				tmpTable.addCell(new cafen.XIcon({
					icon:'r-iconset', on : 15,  off :255, over :15, 
					event : {
						mousedown : this.moveEvent.bind(this,false), 
						mouseup : this.stopMoveEvent.bind(this)}
				}));
				tmpTable.addStyle({paddingRight:'3px'});
			}
			this.pointerObj = new cafen.XIcon(
				{
					icon:'r-iconset', on : 15,  off :315, over :15,  
					moveOption : {direction : 'X', rangeX :[-7, this._objSize -7], rangeY :null}, 
					event: {'dragend' : this.setMove.bind(this)},
					style:{position : 'absolute', left : '0px', top : '-5px',width:'15px', height: '15px'}
				}
			);
			this.sliderObj = new cafen.Div({
				tag: 'div', 
				className : 'r-boxwhite',
				childNodes : [this.pointerObj], 
				style : {cursor : cafen.getCursor(), width: this._objSize +'px', height:'5px', position:'relative'},
				event : {click : this.setPointer.bind(this), keydown : this.keypress.bind(this)}
			});
			tmpTable.addCell(this.sliderObj);
			if (	options.useButton) {
				tmpTable.addCell(new cafen.XIcon({
					icon:'r-iconset', on : 15,  off :240, over :15, 
					event : {
						mousedown : this.moveEvent.bind(this,true), 
						mouseup : this.stopMoveEvent.bind(this)}
				}));
				tmpTable.addStyle({paddingLeft:'3px'});
			}
			this.setOptions(cafen.extend(options, {childNodes : [tmpTable]}));
			break;
	}
	this.initSlider();
	this.setValue(options.def);
}

cafen.Slider.prototype = cafen.extendClass({
	_objSize : null, 
	_objDirect : null,
	pointerObj : null,
	initSlider : function() {
		this.sliderObj.getElement().style.position = 'relative';
		this.sliderObj.getElement().style.left = '0px';
		this.sliderObj.getElement().style.top = '0px';
	},
	setPointer : function(obj, event) {
		var pos = cafen.pointer(event);
		var currPos = cafen.viewportOffset(this.sliderObj.getElement());
		switch (this._objDirect) {
			case 'Y':
				this.pointerObj.setOffset(null, this.offset2Offset(pos[1] - currPos[1]) - 7);
				break;
			default : 
				this.pointerObj.setOffset(this.offset2Offset(pos[0] - currPos[0]) - 7, null);
				break;
		}
		this.setMove(event);
	},
	moveEvent : function(bl) {
		if (bl)
			this._moveSeqnBind = this.movePlus.bind(this);
		else
			this._moveSeqnBind = this.moveMinus.bind(this);
		this._moveEventSpeed = 200;
		this._moveEventSeqnBind = this.moveEventSeqn.bind(this);
		this.moveEventSeqn();
	},
	moveEventSeqn : function() {
		if (this._moveSeqnBind != null) {
			this._moveSeqnBind();	
			window.setTimeout(this._moveEventSeqnBind, this._moveEventSpeed);
			this._moveEventSpeed = Math.max(10,Math.round(this._moveEventSpeed * 0.7));
		}
	},
	stopMoveEvent : function(obj, event) {
		this._moveSeqnBind = null;
		this._moveEventSpeed = 100;
		this.setMove(event);
	},
	moveMinus : function() {
		if (this._objMax > this._objMin)
			this.setValue(this.getValue() - this._objStep);
		else
			this.setValue(this.getValue() + this._objStep);
	},
	movePlus : function() {
		if (this._objMax > this._objMin)
			this.setValue(this.getValue() + this._objStep);
		else
			this.setValue(this.getValue() - this._objStep);
	},
	keypress : function(obj, event) {
		switch(event.keyCode) {
			case 37 :
			case 38 :
				this.moveMinus();
				this.setMove(event);
				break;
			case 39 :
			case 40 :
				this.movePlus();
				this.setMove(event);
				break;
		}
	},
	offset2Value : function(val) {
		if (this._objMax > this._objMin)
			return Math.min(this._objMax, Math.max(this._objMin, Math.round((val / this._objSize) * (this._objMax - this._objMin) / this._objStep) * this._objStep+ this._objMin));
		else
			return Math.max(this._objMax, Math.min(this._objMin, Math.round((val / this._objSize) * (this._objMax - this._objMin) / this._objStep) * this._objStep+ this._objMin));
	},
	value2Offset : function(val) {
		return Math.min(Math.max(0,Math.round((val -this._objMin) / (this._objMax - this._objMin) * this._objSize)), this._objSize);
	},
	offset2Offset : function(val) {
		return this.value2Offset(this.offset2Value(val));
	},
	setValue : function(val) {
		val = this.value2Offset(val);
		switch (this._objDirect) {
			case 'Y' :
				this.pointerObj.setOffset(null, val -7);
				break;
			default :
				this.pointerObj.setOffset(val -7, null);
		}	
	},
	getValue : function() {
		var pos = this.pointerObj.getOffset() ;
		switch (this._objDirect) {
			case 'Y' :
				return this.offset2Value(pos[1] + 7);
				break;
			default :
				return this.offset2Value(pos[0] + 7);
				break;
		}
	},
	setMoveBy : function(posPlus) {
		var pos = this.pointerObj.getOffset();
		switch (this._objDirect) {
			case 'Y' :
				if (pos[1] + posPlus - 7 > 0 &&  pos[1] + posPlus - 7 < this._objSize)
					this.pointerObj.setOffset(null, this.offset2Offset(pos[1] + posPlus) - 7);
				break;
			default :
				if (pos[0] + posPlus - 7 > 0 &&  pos[0] + posPlus - 7 < this._objSize)
					this.pointerObj.setOffset(this.offset2Offset(pos[0] + posPlus) - 7, null);
				break;
		}
		this.setMove(event);
	},
	setMove : function(event) {
		this.execEvent('end', event);
	}
},cafen.Element.prototype);

cafen.window = function() {}

cafen.window.prototype = cafen.extendClass({
	_parentPop : null,
	_buttonObj : null,
	_titleObj : null,
	_onEndFnc : null,
	_toggleObj : null,
	_contentWidth : null,
	_isOpen : true,
	_popupSize : null,
	_contentObj : null,
	initParam : function(parent, popup_width) {
		this._parentPop = parent;
		this._contentWidth = popup_width;
		this._buttonObj = null;
		this.setOptions({className :'r-btnskin', tag : 'div', tplName : 'top', style : {width:popup_width +'px',textAlign:'center', position :'absolute'}, shadow : false, resize : 'XXXOOOOOO', event :{'resize' : this.freeSize.bind(this)}});
		this._titleObj = new cafen.TableAuto({align:'center', attribute :{width:'100%', height:'auto'}});
		this.appendChild(this._titleObj, 'top');
	},
	setTitle : function(title) {
		this._titleObj.addCell(new cafen.Div({attribute :{innerHTML : title},moveOption : {direction : 'XY', rangeX :null, rangeY :null, link : this}}));
	},
	setToolBar : function() {
		this._toggleObj = new cafen.XIcon({icon:'r-iconset', on : 15,  off :15, over :15, style:{width: '15px', height: '15px'}, event:{'click' : this.setToggle.bind(this,null)}})
		this._titleObj.addCell(this._toggleObj);
		this._titleObj.addChild(new cafen.XIcon({icon:'r-iconset', off :0, on : 0, over :15, style:{width: '15px', height: '15px'},align:'',event:{'click' : this.close.bind(this,null)}}));
		this._titleObj.addStyle({textAlign:'right', width: '40px',verticalAlign: 'top', whiteSpace: 'nowrap'});
	},
	freeSize : function() {
		this._popupSize = null;
	},
	setToggle : function() {
		this._isOpen = ! this._isOpen;
		this._toggleObj.setSelected(!this._isOpen);
		if (this._isOpen)
			this.setAnimate(null, 'max');
		else {
			this.setAnimate(null, 'hidden');
		}
	},
	setContents : function(contents) {
		this.appendChild(new cafen.Div({attribute :{innerHTML : contents},style : {width:'auto',height:'auto', backgroundColor :'#f0f0f0', fontSize:'12px',padding:'5px', margin: '3px', textAlign:'left'}}));
	},
	setObject : function(obj) {
		this.appendChild(obj);
	},
	setButton : function(btnObj) {
		if (this._buttonObj == null) {
			this._buttonObj = new cafen.TableAuto({align:'center', attribute :{height:'27px', cellpadding:'2px'}});
			this.appendChild(this._buttonObj);
		}
		this._buttonObj.addCell(btnObj);
		this._buttonObj.addStyle({padding:'2px'});
	},
	fix2Center : function() {
		if (this._parentPop != null)
			this.setOffsetBy(26, 26);
		else
			this.center();
	},
	onLoad : function() {
		if (this._parentPop == null) {
			cafen.getPopup().appendChild(this.getObject());
			window.onscroll = window.onresize = this.fix2Center.bind(this);
		} else {
			this._parentPop.appendChild(this, 'shadow');
		}
		this.fix2Center();
	},
	onClose : function(val) {
		if (this._onEndFnc != null)
			this._onEndFnc(val);
	},
	close : function(val) {
		if (this._parentPop == null) {
			this.onClose(val);
			window.onscroll = window.onresize = null;
			
			cafen.getPopup().removeChild(this.getObject());
		} else
			this._parentPop.removeChild(this);
	}
},cafen.Element.prototype);

cafen.alert = function(title, contents, parent) {
	this.initParam(parent, 300);
	this.setTitle(title);
	this.setToolBar();
	this.setContents(contents);
	this.setObject(new cafen.XSelect([{text:'111',value:'222'}], 150));
	this.setButton(new cafen.XButton({text:'OK',className : 'r-rbtnskin' , style :{width:'40px'}, align:'center',event:{'click' : this.close.bind(this)}}));
	this.setButton(new cafen.XButton({text:'OK',className : 'r-rbtnskin' , style :{width:'40px'}, align:'center',event:{'click' : this.close.bind(this)}}));
	this.onLoad();
}

cafen.alert.prototype = cafen.extendClass({},cafen.window.prototype);


cafen.message = function(title, contents, base_width, parent) {
	this.initParam(parent, base_width);
	this.setTitle(title);
	this.setToolBar();
	this.setObject(contents);
	this.setButton(new cafen.XButton({text:'OK',className : 'r-rbtnskin' , style :{width:'40px'}, align:'center',event:{'click' : this.close.bind(this)}}));
	this.setButton(new cafen.XButton({text:'OK',className : 'r-rbtnskin' , style :{width:'40px'}, align:'center',event:{'click' : this.close.bind(this)}}));
	this.onLoad();
}

cafen.message.prototype = cafen.extendClass({},cafen.window.prototype);

cafen.confirm = function(title, contents, onEndFnc, parent) {
	this._onEndFnc = onEndFnc;
	this.initParam(parent, 300);
	this.setTitle(title);
	this.setContents(contents);
	this.setToolBar();
	this.setButton(new cafen.XButton({text:'Yes',className : 'r-rbtnskin',style :{width:'40px'},event:{'click' : this.close.bind(this,true)}}));
	this.setButton(new cafen.XButton({text:'No',style :{width:'40px'},event:{'click' : this.close.bind(this,false)}}));
	this.onLoad();
}

cafen.confirm.prototype = cafen.extendClass({},cafen.window.prototype);

cafen.prompt = function(title, contents, onEndFnc, parent) {
	this._onEndFnc = onEndFnc;
	this.initParam(parent, 300);
	this.setTitle(title);
	this.setContents(contents);
	this._inputObj = new cafen.Input({style:{width:'95%', height :'20px'}});
	this.setObject(this._inputObj);
	this.setToolBar();
	this.setButton(new cafen.XButton({text:'OK',tplName : '' , align:'center', style :{width:'40px'},event:{'click' : this.sendValue.bind(this)}}));
	this.onLoad();
}

cafen.prompt.prototype = cafen.extendClass({
	_inputObj : null,
	sendValue : function() {
		var val = this._inputObj.getElement().value;
		if (val.split(' ').join('') != '')
			this.close(val);
	}
},cafen.window.prototype);

cafen.Xprompt = function(title, contents, onEndFnc, parent) {
	this._onEndFnc = onEndFnc;
	this.initParam(parent, 300);
	this.setTitle(title);
	this.setContents(contents);
	this._inputObj = new cafen.Textarea({style:{width:'95%', height :'50px'}});
	this.setObject(this._inputObj);
	this.setToolBar();
	this.setButton(new cafen.XButton({text:'OK',tplName : '' , align:'center', style :{width:'40px'},event:{'click' : this.sendValue.bind(this)}}));
	this.onLoad();
}
cafen.Xprompt.prototype = cafen.extendClass({},cafen.prompt.prototype);

cafen.CPoint = function(x,y) {
	this.x = x; 	this.y = y;	
}
cafen.CPoint.prototype = {x : null, y : null}

cafen._CanvasElement = function(options) {
	this.setOptions(cafen.extend(options, {tag : 'div', attribute :{}, style : {}}));
	this.initCanvas();
}


cafen._CanvasElement.prototype = cafen.extendClass({
	_canvasObject : null, 
	_canvasStyle : {
		bgColor : "#ffffff",
		strokeWeight : "1",
		strokeColor : "#000000",
		strokeJoinStyle : "miter",
		strokeDashStyle : "dotted",
		strokeOpacity : "1.0",
		strokeLineStyle : "single",
		fillColor1 : "#ffffff",
		fillColor2 : "#ffffff",
		fillType : "",
		fillMethod : "",
		fillAngle : "",
		fillOpacity : "1.0",
		shadowType : "",
		backgroundColor : "#ffffff",
		border : "solid 1px #585c6c",
		fontFamily : "dotum,sans-serif",
		fontColor : "#333333",
		fontSize : "11px",
		fontWeight : "normal",
		textAlign : "center",
		lineHeight : "16px"
	},
	initCanvas : function() {
		this._canvasObject = this.getElement();
	},
	setStrokeStyle : function(obj, _style){
		if (obj instanceof Array) {
			for(var i = 0; i < obj.length; i++)
				this._setStrokeStyle(obj[i], _style);
		} else 
			this._setStrokeStyle(obj, _style);
	},
	_setStrokeStyle : function() {},
	setFillStyle: function (obj, _style){
		if (obj instanceof Array) {
			for(var i = 0; i < obj.length; i++)
				this._setFillStyle(obj[i], _style);
		} else 
			this._setFillStyle(obj, _style);
	},
	_setFillStyle : function() {},
	createLine : function(start, end){},
	updateLine : function(line, start, end){},
	drawLine : function(start, end){},
	createRect : function(start, end){},
	updateRect : function(rect, start, end){},
	drawRect : function(start, end) {},
	createPolyLine : function(rPoints){},
	drawPolyLine : function(rPoints) {},
	createPolygon : function(rPoints){},
	addPolygonPoints : function(element, rPoints){},
	drawPolygon : function(rPoints){},
	createCircle : function(rPoint, radius){},
	updateCircle : function(circle, rPoint, radius){},
	drawCircle: function(rPoint, radius) {},
	createOval : function(rPoint, radiusX, radiusY){},
	updateOval : function(eclipse, rPoint, radiusX, radiusY){},
	drawOval : function(rPoint, radiusX, radiusY) {},
	_drawOval : function(sPoint, ePoint){},
	createText : function(rPoint, msg){},
	updateText : function(text, rPoint, msg){},
	drawText: function(rPoint, msg, options){},
	updateStar : function(star, center, radius, dir){
		this.unDraw(star);
		return star = this.drawStar(center, radius, dir);
	},
	drawStar : function(center, radius, dir){
		dir = (dir == null) ? 0 : (dir / 180) * Math.PI;
		var points = [];
		for(var i = 0 ; i < 5; i++) {
			points.push(new cafen.CPoint(Math.sin(i/2.5*Math.PI + dir)*radius + center.x , Math.cos(i/2.5*Math.PI + dir)*radius + center.y));
			points.push(new cafen.CPoint(Math.sin((i+3)/2.5*Math.PI + dir)*radius + center.x , Math.cos((i+3)/2.5*Math.PI + dir)*radius + center.y));
		}
		return this.drawPolyLine(points);
	},
	b1Bezier : function(t) { return (t*t*t); },
	b2Bezier : function(t) { return (3*t*t*(1-t)); },
	b3Bezier : function(t) { return (3*t*(1-t)*(1-t)); },
	b4Bezier : function(t) { return ((1-t)*(1-t)*(1-t)); },
	getBezier : function(percent,C1,C2,C3,C4) {
		return new cafen.CPoint(
			C1.x * this.b1Bezier(percent) + C2.x * this.b2Bezier(percent) +C3.x * this.b3Bezier(percent) + C4.x * this.b4Bezier(percent),
			C1.y * this.b1Bezier(percent) + C2.y * this.b2Bezier(percent) + C3.y * this.b3Bezier(percent) + C4.y * this.b4Bezier(percent)
		);
	},
	drawCurve : function(start, leftpo, rightpo,end, rate) {
		var points = [];
		var step = 100/rate;
		for(var i = 0; i <= 100; i += step) 
			points.push(this.getBezier(i/100, start, leftpo, rightpo, end));	
		return this.drawPolyLine(points);
	},
	unDraw : function(obj) {
		if (obj.length != null) {
			for(var i = 0; i < obj.length; i++)
				this.unDraw(obj[i]);
		} else if (obj.parentNode != null)
			obj.parentNode.removeChild(obj);
	}
},cafen.Element.prototype);

cafen._CanvasSGV = function(options) {
	this.setOptions(cafen.extend({tag : 'div', attribute :{}, style : {}},options));
	this.initCanvas();
}

cafen._CanvasSGV.prototype = cafen.extendClass({
	namespace : 'http://www.w3.org/2000/svg',
	initCanvas : function() {
        this._canvasObject = document.createElementNS(this.namespace, "svg");
        this.getElement().appendChild(this._canvasObject);
	},
	_setStrokeStyle : function(obj, _style){
		var _style = _style || this._canvasStyle;
		if (_style.strokeColor != null)
			obj.setAttribute("stroke", _style.strokeColor);
		if(_style.strokeDashStyle == "dash")
			obj.setAttribute("stroke-dasharray", "5, 5, 5");
		else if(_style.strokeDashStyle == "dashdot")
			obj.setAttribute("stroke-dasharray", "5, 2, 5");
		if (_style.strokeOpacity != null)
			obj.setAttribute("stroke-opacity", _style.strokeOpacity);
		if (_style.strokeWeight != null)
			obj.setAttribute("stroke-width", _style.strokeWeight);
		if (_style.strokeJoinStyle != null)
			obj.setAttribute("stroke-linejoin", _style.strokeJoinStyle);
	},
	_setFillStyle: function (parentObj, _style){
		var _style = _style || this._canvasStyle;
		if (_style.fillColor1 != null)
			parentObj.setAttribute("fill", _style.fillColor1);
		if (_style.fillOpacity != null)
			parentObj.setAttribute("fill-opacity", _style.fillOpacity)
	},
	setObjectStyle : function(obj, style) {
		for(var name in style) {
			switch(name) {
				case 'rotation' :
					var center = this.getObjectCenter(obj);
					obj.setAttribute('transform','rotate('+style[name] +','+center[0]+','+center[1]+')');
					break;
				default :
					obj.setAttribute(name,style[name]);
					break;
			}
		}
	},
	getObjectCenter : function(obj) {
		if (obj.getAttribute('points') != null) {
			var points_str = obj.getAttribute('points');
			var xMin = 0,yMin = 0, xMax = 0, yMax = 0;
			var points = points_str.split(' ');
			for(var i = 0; i < points.length; i++) {
				var xypoint = points[i].split(',');
				var currX = parseInt(xypoint[0]);
				var currY = parseInt(xypoint[1]);
				if (i == 0) {
					xMax = xMin = currX;
					xMax = yMin = currY;
				} else {
					xMin = Math.min(xMin, currX);
					xMax = Math.max(xMax, currX);
					yMin = Math.min(yMin, currY);
					yMax = Math.max(yMax, currY);
				}
			}
			var x = Math.round((xMin + xMax)/2);
			var y = Math.round((yMin + yMax)/2);
			return [x, y];
		} else if (obj.getAttribute('x1') != null)
			return [(obj.getAttribute('x1') + obj.getAttribute('x2'))/2, (obj.getAttribute('y1') + obj.getAttribute('y2'))/2];
		else if (obj.getAttribute('cx') != null)
			return [obj.getAttribute('cx'), obj.getAttribute('cy')];
		else {
			return [0,0];
		}
	},
	createLine : function(start, end){
		var line = document.createElementNS(this.namespace, "line");
		this.updateLine(line, start, end);
		return line;
	},
	updateLine : function(line, start, end){
		line.setAttribute("x1", start.x);
		line.setAttribute("y1", start.y);
		line.setAttribute("x2", end.x);
		line.setAttribute("y2", end.y);
		line.sPoint = start; line.ePoint = end;
	},
	drawLine : function(start, end){
		var line = this.createLine(start, end);
		this.setStrokeStyle(line);
		this._canvasObject.appendChild(line);
		return line;
	},
	createRect : function(start, end){
		var rect = document.createElementNS(this.namespace, "rect");
		this.updateRect(rect, start, end);
		return rect;
	},
	updateRect : function(rect, start, end){
		var xOffset = end.x - start.x;
		var yOffset = end.y - start.y;
		var width = Math.abs(xOffset);
		var height = Math.abs(yOffset);
		var x = (xOffset) > 0 ? start.x : end.x;
		var y = (yOffset) > 0 ? start.y : end.y;
		rect.setAttribute("x", x);
		rect.setAttribute("y", y);
		rect.setAttribute("width", width);
		rect.setAttribute("height", height);
		rect.setAttribute("gtype", "rect");
	},
	drawRect : function(start, end) {
		var rect = this.createRect(start, end);
		this.setStrokeStyle(rect);
		this.setFillStyle(rect);
		this._canvasObject.appendChild(rect);
		return rect;
	},
	createPolyLine : function(rPoints){
		if(rPoints.length > 0){
			var polyline = document.createElementNS(this.namespace, "polyline");
			var points = [];
			for(var i=0,len=rPoints.length; i<len; i++){
				points.push(rPoints[i].x);
				points.push(rPoints[i].y);
			}
			polyline.setAttribute("points", points.join(","));
			return polyline;
		}
	},
	drawPolyLine : function(rPoints) {
		var polyline = this.createPolyLine(rPoints);
		this.setStrokeStyle(polyline);
		this.setFillStyle(polyline, {fillColor1 : 'transparent'});
		this._canvasObject.appendChild(polyline);
		return polyline;
	},
	createPolygon : function(rPoints){
		if(rPoints.length > 0){
			var polygon = document.createElementNS(this.namespace, "polygon");
			var points = [];
			for(var i=0,len=rPoints.length; i<len; i++){
				points.push(rPoints[i].x);
				points.push(rPoints[i].y);
			}
			polygon.setAttribute("points", points);
			polygon.dpoints = rPoints;
			return polygon;
		}
	},
	addPolygonPoints : function(element, rPoints){
		for(var i=0,len=rPoints.length; i<len; i++)
			element.dpoints.push(rPoints[i]);
		var points = [];
		for(var i=0,len=element.dpoints.length; i<len; i++){
			points.push(element.dpoints[i].x);
			points.push(element.dpoints[i].y);
		}
		element.setAttribute("points", points);
	},
	drawPolygon : function(rPoints){
		var polygon = this.createPolygon(rPoints);
		this.setStrokeStyle(polygon);
		this.setFillStyle(polygon);
		this._canvasObject.appendChild(polygon);
		return polygon;
	},
	createCircle : function(rPoint, radius){
		var circle = document.createElementNS(this.namespace, "circle");
		this.updateCircle(circle, rPoint, radius);
		return circle;
	},
	updateCircle : function(circle, rPoint, radius){
		circle.setAttribute("cx", rPoint.x);
		circle.setAttribute("cy", rPoint.y);
		circle.setAttribute("r", radius);
	},
	drawCircle: function(rPoint, radius) {
		var circle = this.createCircle(rPoint, radius);
		this.setStrokeStyle(circle);
		this.setFillStyle(circle);
		this._canvasObject.appendChild(circle);
		return circle;
	},
	createOval : function(rPoint, radiusX, radiusY){
		var eclipse = document.createElementNS(this.namespace, "ellipse");
		this.updateOval(eclipse, rPoint, radiusX, radiusY);
		return eclipse;
	},
	updateOval : function(eclipse, rPoint, radiusX, radiusY){
		eclipse.setAttribute("cx", rPoint.x);
		eclipse.setAttribute("cy", rPoint.y);
		eclipse.setAttribute("rx", radiusX);
		eclipse.setAttribute("ry", radiusY);
		eclipse.setAttribute("gtype", "oval");
	},
	drawOval : function(rPoint, radiusX, radiusY) {
		var eclipse = this.createOval(rPoint, radiusX, radiusY);
		this.setStrokeStyle(eclipse);
		this.setFillStyle(eclipse);
		this._canvasObject.appendChild(eclipse);
		return eclipse;
	},
	_drawOval : function(sPoint, ePoint){
		var cx = Math.min(sPoint.x, ePoint.x) + (Math.max(sPoint.x, ePoint.x) - Math.min(sPoint.x, ePoint.x))/2;
		var cy = Math.min(sPoint.y, ePoint.y) + (Math.max(sPoint.y, ePoint.y) - Math.min(sPoint.y, ePoint.y))/2;
		var rx = (Math.max(sPoint.x, ePoint.x) - Math.min(sPoint.x, ePoint.x))/2;
		var ry = (Math.max(sPoint.y, ePoint.y) - Math.min(sPoint.y, ePoint.y))/2;
		return this.drawOval(new cafen.CPoint(cx, cy), rx, ry);
	},
	createText : function(rPoint, msg){
		var text = daum.maps.TemplateGenerator.getLayer();
		this.updateText(text, rPoint, msg);
		return text;
	},
	updateText : function(text, rPoint, msg){
		text.style.position = "absolute";
		text.style.zIndex = "50";
		text.style.left = rPoint.x + "px";
		text.style.top = rPoint.y + "px";
		text.style.color = this.style.fontColor;
		text.style.fontSize = this.style.fontSize;
		text.style.fontWeight = this.style.fontWeight;
		text.style.textAlign = this.style.textAlign;
		text.style.lineHeight = this.style.lineHeight;
		text.wrap.style.fontFamily = this.style.fontFamily;
		text.wrap.style.padding = "0 5px";
		text.wrap.style.letterSpacing = "-1px";
		text.wrap.innerHTML = msg;
	},
	drawText: function(rPoint, msg, options){
		var options = options || { align : "left", valign : "top", offsetX : 0, offsetY : 0 };
		var text = this.createText(rPoint, msg);
		this.container.appendChild(text);
		if(options.align == "right"){
			text.style.left = (parseInt(text.style.left) - text.offsetWidth)+ 'px';
		}
		if(options.valign == "bottom"){
			text.style.top = (parseInt(text.style.top) - text.offsetHeight)+ 'px';
		}
		daum.Element.setPosition(text, parseInt(text.style.top) + options.offsetY, parseInt(text.style.left) + options.offsetX);
		daum.maps.TemplateGenerator.setBackLayer(text);
		return text;
	}
},cafen._CanvasElement.prototype);


cafen._CanvasVML = function(options) {
	this.setOptions(cafen.extend(options, {tag : 'div', attribute :{}, style : {overflowY:'hidden',overflowX:'hidden',overflow:'hidden'}}));
	this.initCanvas();
}

cafen._CanvasVML.prototype = cafen.extendClass({
	namespace : 'urn:schemas-microsoft-com:vml',
	initCanvas : function() {
		document.namespaces.add("v", this.namespace);
		try {
		document.createStyleSheet().addRule("v\\:*", "behavior: url(#default#VML);");
		} catch(ex) {}
        var tmpObj = new cafen.Div({style:{width:'100%',height:'100%', position:'absolute',overflow : 'hidden', display:'inline-block',zIndex: '1000'}});
        this.appendChild(tmpObj);
        this._canvasObject = tmpObj.getElement();
		var size = this.getSize();
		this.width = size[0];
		this.height = size[1];
	},
	_setStrokeStyle : function(parent, _style){
		var _style = _style || this._canvasStyle;
		var obj = null;
		if (parent.getElementsByTagName("stroke").length > 0) {
			obj = parent.getElementsByTagName("stroke")[0];
		} else {
			obj = document.createElement("v:stroke");
			parent.appendChild(obj);
		}
		if (_style.strokeDashStyle != null)
			obj.dashstyle = _style.strokeDashStyle;
		if (_style.strokeLineStyle != null)
			obj.linestyle = _style.strokeLineStyle;
		if (_style.strokeJoinStyle != null)
			obj.joinstyle = _style.strokeJoinStyle;
		if (_style.strokeOpacity != null)
			obj.opacity = _style.strokeOpacity;
		if (_style.strokeColor != null)
			parent.strokecolor = _style.strokeColor;
		if (_style.strokeWeight != null)
			parent.strokeweight = _style.strokeWeight;
		if (_style.startarrow != null)
			obj.startarrow = _style.startarrow;
		if (_style.startarrowwidth != null)
			obj.startarrowwidth = _style.startarrowwidth;
		if (_style.startarrowlength != null)
			obj.startarrowlength = _style.startarrowlength;
		if (_style.endarrow != null)
			obj.endarrow = _style.endarrow;
		if (_style.endarrowwidth != null)
			obj.endarrowwidth = _style.endarrowwidth;
		if (_style.endarrowlength != null)
			obj.endarrowlength = _style.endarrowlength;
	},
	_setFillStyle : function(parent, _style){
		var _style = _style || this._canvasStyle;
		var obj = null;
		if (parent.getElementsByTagName("fill").length > 0) {
			obj = parent.getElementsByTagName("fill")[0];
		} else {
			obj = document.createElement("v:fill");
			parent.appendChild(obj);
		}
		obj.on = "true";
		if (_style.fillColor1 != null)
			obj.color = _style.fillColor1;
		if (_style.fillColor2 != null)
			obj.color2 = _style.fillColor2;
		if (_style.fillType != null)
			obj.type = _style.fillType;
		if (_style.fillMethod != null)
			obj.method = _style.fillMethod;
		if (_style.fillAngle != null)
			obj.angle = _style.fillAngle;
		if (_style.fillOpacity != null)
			obj.opacity = _style.fillOpacity;
	},
	setObjectStyle : function(obj, style) {
		for(var name in style) 
			obj.style[name] = style[name];
	},
	createLine : function(start, end){
		var line = document.createElement("v:line");
		this.updateLine(line, start, end);
		return line;
	},
	updateLine : function(line, start, end){
		line.style.position = "absolute";
		line.from = start.x + ", " + start.y;
		line.to = end.x + ", " + end.y;
	},
	drawLine : function(start, end){
		var line = this.createLine(start, end);
		this.setStrokeStyle(line);
		this._canvasObject.appendChild(line);
		return line;
	},
	createRect : function(start, end, options){
		var rect = document.createElement(options.rectType);
		this.updateRect(rect, start, end, options || {});
		return rect;
	},
	updateRect : function(rect, start, end, options){
		var options = options || {};
		var xOffset = end.x - start.x;
		var yOffset = end.y - start.y;
		rect.style.position = "absolute";
		rect.style.left = ((xOffset) > 0 ? start.x : end.x) + "px";
		rect.style.top = ((yOffset) > 0 ? start.y : end.y) + "px";
		rect.style.width = Math.abs(xOffset) + "px";
		rect.style.height = Math.abs(yOffset) + "px";
		rect.gtype = "rect";
		if(options.arcsize) 
			rect.arcsize = options.arcsize;
	},
	drawRect: function(start, end) {
		var rect = this.createRect(start, end, {rectType : "v:rect"});
		this.setStrokeStyle(rect);
		this.setFillStyle(rect);
		this._canvasObject.appendChild(rect);
		return rect;
	},
	createPolyLine : function(rPoints){
		if(rPoints.length > 0){
			var pLine = document.createElement("v:polyline");
			pLine.style.position = "absolute";
			pLine.style.width = this.width + "px";
			pLine.style.height = this.height + "px";
			pLine.coordorigin = "0 0";
			pLine.coordsize = this.width + " " + this.height;
			var points = [];
			for(var i=0,len=rPoints.length; i<len; i++){
				points.push(rPoints[i].x);
				points.push(rPoints[i].y);
			}
			pLine.points = points.join(",");
			pLine.dpoints = rPoints;
			return pLine;
		}
	},
	drawPolyLine : function(rPoints){
		if(rPoints.length > 0) {
			var pLine = this.createPolyLine(rPoints);
			this.setStrokeStyle(pLine);
			this.setFillStyle(pLine, {fillColor1 : 'none', fillOpacity : 0});
			this._canvasObject.appendChild(pLine);
			return pLine;
		}
	},
	getPathInfo: function(points) {
		var pathInfo = [];
		for (var i=0,len=points.length; i<len;){
			if(i == 0){
				pathInfo.push("m " + points[i] + "," + points[i+1]);
			}else if(i == 2){
				pathInfo.push(" l " + points[i] + "," + points[i+1]);
			}else{
				pathInfo.push(", " + points[i] + "," + points[i+1]);
			}
			i += 2;
		}
		pathInfo.push(" x e");
		return pathInfo.join(' ');
	},
	createPolygon : function(rPoints){
		if(rPoints.length > 0){
			this.width = document.body.clientWidth;
			this.height = document.body.clientHeight;
			var pGon = document.createElement("v:shape");
			pGon.style.position = "absolute";
			pGon.style.width = this.width + "px";
			pGon.style.height = this.height + "px";
			pGon.coordorigin = "0 0";
			pGon.coordsize = this.width + " " + this.height;
			var points = [];
			for(var i=0,len=rPoints.length; i<len; i++){
				points.push(rPoints[i].x);
				points.push(rPoints[i].y);
			}
			pGon.path = this.getPathInfo(points);
			return pGon;
		}
	},
	addPolygonPoints : function(element, rPoints){
		for(var i=0,len=rPoints.length; i<len; i++){
			element.dpoints.push(rPoints[i]);
		}
		var points = [];
		for(var i=0,len=element.dpoints.length; i<len; i++){
			points.push(element.dpoints[i].x);
			points.push(element.dpoints[i].y);
		}
		element.path = this.getPathInfo(points);
	},
	drawPolygon: function(rPoints){
		if(rPoints.length > 0) {
			var pGon = this.createPolygon(rPoints);
			this.setStrokeStyle(pGon);
			this.setFillStyle(pGon);
			this._canvasObject.appendChild(pGon);
			return pGon;
		}
	},
	drawCircle : function(rPoint, radius) {
		return this.drawOval(rPoint, radius, radius);
	},
	updateCircle : function(circle, rPoint, radius){
		this.updateOval(circle, rPoint, radius, radius);
	},
	createOval : function(rPoint, radiusX, radiusY){
		var circle = document.createElement("v:oval");
		this.updateOval(circle, rPoint, radiusX, radiusY);
		return circle;
	},
	updateOval : function(circle, rPoint, radiusX, radiusY){
		circle.style.position = "absolute";
		circle.style.left = rPoint.x - radiusX + "px";
		circle.style.top = rPoint.y - radiusY + "px";
		circle.style.width = radiusX * 2  + "px";
		circle.style.height = radiusY * 2  + "px";
		circle.gtype = "oval";
	},
	drawOval : function(rPoint, radiusX, radiusY) {
		var circle = this.createOval(rPoint, radiusX, radiusY);
		this.setStrokeStyle(circle);
		this.setFillStyle(circle);
		this._canvasObject.appendChild(circle);
		return circle;
	},
	_drawOval : function(sPoint, ePoint){
		var cx = Math.min(sPoint.x, ePoint.x) + (Math.max(sPoint.x, ePoint.x) - Math.min(sPoint.x, ePoint.x))/2;
		var cy = Math.min(sPoint.y, ePoint.y) + (Math.max(sPoint.y, ePoint.y) - Math.min(sPoint.y, ePoint.y))/2;
		var rx = (Math.max(sPoint.x, ePoint.x) - Math.min(sPoint.x, ePoint.x))/2;
		var ry = (Math.max(sPoint.y, ePoint.y) - Math.min(sPoint.y, ePoint.y))/2;
		return this.drawOval(new cafen.CPoint(cx, cy), rx, ry);
	},
	createText : function(rPoint, msg){
		this.updateText(text, rPoint, msg);
		return text;
	},
	updateText : function(text, rPoint, msg){
		text.style.position = "absolute";
		text.style.zIndex = "50";
		text.style.left = rPoint.x + "px";
		text.style.top = rPoint.y + "px";
		text.style.color = this._canvasStyle.fontColor;
		text.style.fontSize = this._canvasStyle.fontSize;
		text.style.fontWeight = this._canvasStyle.fontWeight;
		text.style.textAlign = this._canvasStyle.textAlign;
		text.style.lineHeight = this._canvasStyle.lineHeight;
		text.wrap.style.styleFloat = "left";
		text.wrap.style.fontFamily = this._canvasStyle.fontFamily;
		text.wrap.style.padding = "0 5px";
		text.wrap.style.letterSpacing = "-1px";
		text.wrap.style.lineHeight = this._canvasStyle.lineHeight;
		text.wrap.style.overflow = "hidden";
		text.wrap.innerHTML = msg;
	},
	drawText: function(rPoint, msg, options){
		var options = options || { align : "left", valign : "top", offsetX : 0, offsetY : 0 };
		var text = this.createText(rPoint, msg);
		if(options.align == "right"){
			text.style.left = (parseInt(text.style.left) - text.offsetWidth)+'px';
		}
		if(options.valign == "bottom"){
			text.style.top = (parseInt(text.style.top) - text.offsetHeight)+ 'px';
		}
		return text;
	}		
},cafen._CanvasElement.prototype);


cafen.Canvas = function(options) {
	this.setOptions(cafen.extend(options, {tag : 'div', attribute :{}, style : {}}));
	this.initCanvas();
}

cafen.Canvas.prototype = (document.namespaces && document.namespaces.add) ? cafen._CanvasVML.prototype : cafen._CanvasSGV.prototype ;




cafen.XWindow = function(options) {
	this.initOptions(cafen.extend({className :'', style : {left: '0px',top:'0px',width:'1px', height : '1px', fontSize : '1px',zIndex :500}, shadow : false, position : 'relative'},options));
}

cafen.XWindow.prototype = cafen.extendClass({
	_popupOptions : null,
	_parentPop : null,
	_buttonObj : null,
	_titleObj : null,
	_onEndFnc : null,
	_toggleObj : null,
	_contentWidth : null,
	_isOpen : true,
	_popupSize : null,
	_contentObj : null,
	_lastOpenChild : null,
	initOptions : function(options) {
		this.setOptions(cafen.extend({className :'r-btnskin', tag : 'div', style : { textAlign:'center', position :'absolute',zIndex:500}, shadow : true}, options));
	},
	initParam : function(parent, popup_width) {
		this._parentPop = parent;
		this._contentWidth = popup_width;
		this._buttonObj = null;
		this.setOptions({className :'r-btnskin', tag : 'div', tplName : 'top', style : {width:popup_width +'px',textAlign:'center', position :'absolute'}, shadow : false, resize : 'XXXOOOOOO', event :{'resize' : this.freeSize.bind(this)}});
		this._titleObj = new cafen.TableAuto({align:'center', attribute :{width:'100%', height : '19'}});
		this.appendChild(this._titleObj, 'top');
	},
	addChild : function(obj, bl) {
		this.appendChild(obj);
	},
	closeChild : function(obj) {
		if (this._lastOpenChild != null) {
			this._lastOpenChild.closeHide();
			this._lastOpenChild = null
		}
	},
	checkTitleObject : function() {
		if (this._titleObj == null) {
			this._titleObj = new cafen.TableAuto({align:'center', attribute :{width:'100%', height:'20', border:0}, style : {position:'relative', top : '0px', width : '100%'}});
			this.appendChild(this._titleObj, 'top');
		}
	},
	setTitle : function(title) {
		this.checkTitleObject();
		if (!cafen.getLicence()) {
			this._titleObj.addCell(new cafen.XIcon({icon:'r-winset-logo', off :184, on : 20,  over :45, event : {click : cafen.openPopup.bind(cafen, 'http://cafen.net')}, style : {width:'16px',height:'16px'}}));
			title += ' <a href="http://www.cafen.net" target=_blank><img src="'+_cafen_service_url+'images/ico_pwbycafen2.gif" border=0 hspace=5 vspace=3 align=absmiddle></a>'; 
		} else
			this._titleObj.addCell(new cafen.XIcon({icon:'r-winset-logo', off :222, on : 20,  over :45}));
		this._titleObj.addStyle({width: '20px'});
		this._titleObj.addCell(new cafen.Div({attribute :{innerHTML:'<font size=2>' +title+'</font>'} ,moveOption : {direction : 'XY', rangeX :null, rangeY :null, link : this}, style : {whiteSpace: 'nowrap'}}));
	},
	setToolBar : function(bl) {
		this.checkTitleObject();
		if (bl == null || bl) {
			this._toggleObj = new cafen.XIcon({icon:'r-winset-minmax', off :0, on : 20,  over :45, event:{'click' : this.setToggle.bind(this,null)}, style : {width:'26px',height:'19px'}})
			this._titleObj.addCell(this._toggleObj);
		} else {
			this._titleObj.addCell('&nbsp;');
		}
		this._titleObj.addChild(new cafen.XIcon({icon:'r-winset-close', off :40, on : 0, over :45 ,event:{'click' : this.close.bind(this,null)}, style : {width:'44px',height:'19px'}}));
		this._titleObj.addStyle({textAlign:'right', width: '70px',verticalAlign: 'top', whiteSpace: 'nowrap'});
	},
	setToggle : function() {
		this._isOpen = ! this._isOpen;
		this._toggleObj.setSelected(!this._isOpen);
		this.closeChild();
		if (this._isOpen)
			this.setAnimate(null, 'max');
		else {
			this.setAnimate(null, 'hidden');
		}
	},
	setContents : function(contents, pos) {
		if (this.options.sticker != null && pos != null) {
			if (pos.x != null)
				this.options.sticker.x = pos.x;
			if (pos.y != null)
				this.options.sticker.y = pos.y;
			if (pos.plus != null)
				this.options.sticker.plus = pos.plus;
		}
		if (this.contentsObj == null) {
			this.contentsObj = new cafen.Div({attribute :{innerHTML : contents},style : {lineHeight:'170%',fontSize:'12px'}});
			this.appendChild(this.contentsObj);
		} else {
			this.contentsObj.getElement().innerHTML = contents;
		}
	},
	setObject : function(obj) {
		this.appendChild(obj);
	},
	setButton : function(btnObj) {
		if (this._buttonObj == null) {
			this._buttonObj = new cafen.TableAuto({align:'center', attribute :{height:'35px', cellpadding:'2'}});
			this.appendChild(this._buttonObj);
		}
		this._buttonObj.addCell(btnObj);
		this._buttonObj.addStyle({padding:'2px'});
	},
	onLoad : function(sticker, bl, do_nothing) {
		if(do_nothing!=null) this.do_nothing = do_nothing;
		if(this.do_nothing==null) this.do_nothing = false;
		//alert(this.do_nothing);

		if (sticker != null) 
			this.options.sticker = sticker;
		else if (bl)
			this.options.sticker = null;
		if (this.parentNode != null) {
			if (this.parentNode.closeChild && this.parentNode._lastOpenChild != null)
				this.parentNode.closeChild();
			this.parentNode._lastOpenChild = this;
		} else {
			this.parentNode = cafen.getPopup();
			this.parentNode.appendChild(this.getObject());
		}
		this.show();

		// newly added
		if(!this.do_nothing) {

		if (this.options.sticker != null) {
			var parentOffset = (this.parentNode.cumulativeOffset) ? this.parentNode.cumulativeOffset() : cafen.cumulativeOffset(this.parentNode);
			var stickerOffset = (this.options.sticker.obj.cumulativeOffset) ? this.options.sticker.obj.cumulativeOffset() : cafen.cumulativeOffset(this.options.sticker.obj);
			var stickerSize = (this.options.sticker.obj.getSize) ?  this.options.sticker.obj.getSize() : cafen.getSize(this.options.sticker.obj);
			var selfSize = this.getSize();
			var offsetX = stickerOffset[0] - parentOffset[0]	;
			var offsetY = stickerOffset[1] - parentOffset[1];
			switch(this.options.sticker.x) {
				case 'left' :
					offsetX += 0;
					break;
				case 'exleft' :
					offsetX -= selfSize[0];
					break;
				case 'right' :
					offsetX += stickerSize[0];
					break;
				case 'exright' :
					offsetX += (stickerSize[0] - selfSize[0]);
					break;
				default :
					offsetX += (stickerSize[0] - selfSize[0])/2;
					break;
			}
			switch(this.options.sticker.y) {
				case 'top' :
					offsetY += 0;
					break;
				case 'extop' :
					offsetY -= selfSize[1];
					break;
				case 'bottom' :
					offsetY += stickerSize[1];
					break;
				case 'exbottom' :
					offsetY += (stickerSize[1] - selfSize[1]);
					break;
				default :
					offsetY += (stickerSize[1] - selfSize[1])/2;
					break;
			}
			if (this.options.sticker.plus != null) {
				offsetX += this.options.sticker.plus[0];
				offsetY += this.options.sticker.plus[1];
			}
			this.setOffset(offsetX, offsetY);
			if (this.options.linkButton != null)
				this.options.linkButton.setSelected(true);
			if (this.onPopup != null)
				this.onPopup();
		} else {
			var scrollVal = cafen.getPageScroll();
			var pageVal = cafen.getPageSize();
			var selfSize = this.getSize();
			var offsetX = scrollVal[0]+(pageVal[0] -selfSize[0])/2;
			var offsetY = scrollVal[1]+(pageVal[1] -selfSize[1])/2;
			this.setOffset(offsetX , (offsetY > 0) ? offsetY : 0);
			if (this.onPopup != null)
				this.onPopup();
		}
		//alert('bbbbb');
		if (!this._isOpen)
			this.setToggle();

		} //if(!do_nothing) {
	},
	sendValue : function(val) {
		this.close();
		if (this._popupOptions.onClose != null) 
			this._popupOptions.onClose(val);
	},
	close : function() {
		if (this.onClose != null)
			this.onClose();
		if (this.parentNode != null && this.parentNode.closeChild)
			this.parentNode.closeChild(this);
//		else if (this.parentNode != null && this.parentNode.parentNode != null && this.parentNode.parentNode.closeChild)
//			this.parentNode.parentNode.closeChild(this);
		else
			this.closeHide();
	},
	closeHide : function() {
		this.hide();
		if (this.options.linkButton != null)
			this.options.linkButton.setSelected(false);
	}
},cafen.Element.prototype);

cafen.XAlert = function(options) {
	options = options || {}
	this._popupOptions = options;
	this.initOptions(cafen.extend({className :'r-popskin', tag : 'div', tplName : 'top', style : {width:'200px',textAlign:'center', position :'absolute'}, shadow : true, resize : 'XXXOOOOOO'}, options));
	if (options.title != null)
		this.setTitle(options.title);
	this.setToolBar();
	if (options.contents != null)
		this.setContents(options.contents);
	this.setButton(new cafen.XButton({text: cafenMsg.get('com_close'), style :{width:'40px'}, align:'center',event:{'click' : this.close.bind(this)}}));
}

cafen.XAlert.prototype = cafen.extendClass({

},cafen.XWindow.prototype);


cafen.XFaceBox = function(options) {
	options = options || {}
	this._popupOptions = options;
	var tmpOptions = cafen.extend({className :'r-popskin', tag : 'div', tplName : 'top', style : {width:'200px',textAlign:'center', position :'absolute'}, shadow : true, resize : 'XXXOOOOOO'}, options);
	this.initOptions(tmpOptions);


	if (this.options.tplName != '') {
		if (options.title != null)
			this.setTitle(options.title);
		this.setToolBar();
	} else {
		var tmp = new cafen.Div({attribute :{className : 'topButton'}, style : {position:'relative'}});
		this.topArea = new cafen.Div({attribute :{className : 'moveBtn'}, moveOption : {direction : 'XY', rangeX :null, rangeY :null, link : this}, style : {}});
		tmp.appendChild(this.topArea);
		this.topArea.appendChild(new cafen.Div({attribute :{className : 'closeBtn'},event:{'click' : this.close.bind(this)}}));
		this.appendChild(tmp);
		options.hideClose = true;
	}
	if (options.contents != null)
		this.setAjaxContents(options.contents);
	else if (options.ajax_url != null) {
		this.setContents('Processing');
		this.loadAjax(options.ajax_url, options.ajax_data || {});
	}

	if (!options.hideClose)
		this.setButton(new cafen.XButton({text: cafenMsg.get('com_close'), style :{width:'40px'}, align:'center',event:{'click' : this.close.bind(this)}}));
}

cafen.XFaceBox.prototype = cafen.extendClass({
	setAjaxContents : function(html, obj) {
		this.setSize('auto','auto');
		if (obj != null)
			this.options.sticker = obj;
		this.setContents(html);
		this.onLoad(this.options.sticker);
		var objs = this.contentsObj.getElement().getElementsByTagName('div');
		var fileObjs = [];
		for(var i = 0; i < objs.length; i++) {
			var child = objs[i];
			if (child.className.match(new RegExp("(^|\\s)formFile(\\s|$)"))) 
				fileObjs.push(child);
		}
		fileBoxParse(fileObjs);
		var selfSize = this.getSize();
		if (	this.topArea) {
			this.topArea.setSize(selfSize[0]-7);
		}

	},
	onClose : function() {
		//this.setContents('');
		//this.setContents('<div></div>');
	},
	loadAjax : function(theURL, data) {
		cafen.smallSWFAjax.getFlashXml(data || {},this.setAjaxContents.bind(this), theURL);
	},
	loadHtml : function(html, obj) {
		this.setAjaxContents(html, obj);
	}
},cafen.XWindow.prototype);

cafen.XImageViewer = function(options, editorObj) {
	this._popupOptions = options;
	this.initOptions(cafen.extend({className :'r-popskin', tag : 'div', tplName : 'top', style : {width:'200px',textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.setTitle(cafenMsg.get('com_imageview'));
	if (editorObj) {
		this.setToolBar(false);
		this._editorObj = editorObj;
		this._uploadScript = this._editorObj.getUploadScript();
		this._uploadUrl = this._editorObj.getUploadUrl();
		this._previewWidth = parseInt(this.options.style.width) - 170;
		this._previewHeight = parseInt(this.options.style.height) - 10;
		var tmpTable = new cafen.TableAuto({style : {}});
		var tmpTable2 = new cafen.TableAuto({className : 'r-boxblue', style : {width : '150px', margin :'2px'}});
		tmpTable.addCell(tmpTable2);
		tmpTable.addStyle({verticalAlign: 'top'});
		tmpTable2.addRow();
		this.skinArea = new cafen.Div({className : 'r-boxwhite', style :{width:'144px', height: '70px',overflowX : 'auto', overflowY : 'hidden'}});
		tmpTable2.addCell(this.skinArea);
		tmpTable2.addRow();
		this.buttonArea = new cafen.TableAuto({style : {}});
		tmpTable2.addCell(this.buttonArea);
		tmpTable2.addStyle({verticalAlign: 'top'});

		this.contentsObj = new cafen.Div(cafen.extend({className : 'r-boxwhite', style : this.options.style},{style:{width : this._previewWidth+'px', height : this._previewHeight+'px', overflow:'hidden', overflowY:'auto', overflowX:'auto', position :'relative', textAlign:'left', margin :'2px'}}));
		tmpTable.addCell(this.contentsObj);
		tmpTable.addStyle({verticalAlign: 'top'});
		this.setObject(tmpTable);
		this.drawMenu();	
	} else {
		this.setToolBar(true);
		this._previewWidth = parseInt(this.options.style.width) - 6;
		this._previewHeight = parseInt(this.options.style.height) - 6;
		this.contentsObj = new cafen.Div(cafen.extend({style : this.options.style},{style:{overflow:'hidden', overflowY:'hidden', overflowX:'hidden', position :'relative', textAlign:'left'}}));
		this.setObject(this.contentsObj);
	}
}

cafen.XImageViewer.prototype = cafen.extendClass({
	drawMenu : function() {
		this._lastSkinNo = null;
		this._skinOptions = {};
		this.menuInfo = [
			{cmd : 'E', name :cafenMsg.get('ed_0067'), min : 0, max : 3, step : 1, def : 0},
			{cmd : 'M', name :cafenMsg.get('ed_0054'), min : 30, max : 100, step : 5, def : 100},
			{cmd : 'W', name :cafenMsg.get('ed_0055'), min : 0, max : 200, step : 10, def : 100 },
			{cmd : 'A', name :cafenMsg.get('ed_0056'), min : 0, max : 200, step : 10, def : 100 },
			{cmd : 'H', name :cafenMsg.get('ed_0057'), min : 0, max : 360, step : 10, def : 0 },
			{cmd : 'G', name :cafenMsg.get('ed_0058'), min : 0, max : 1, step : 1, def : 0 },
			{cmd : 'N', name :cafenMsg.get('ed_0059'), min : 0, max : 1, step : 1, def : 0 },
			{cmd : 'C', name :cafenMsg.get('ed_0060'), min : 50, max : 150, step : 10, def : 100 },
			{cmd : 'B', name :cafenMsg.get('ed_0061'), min : 5, max : 15, step : 1, def : 10 },
			{cmd : 'R', name :cafenMsg.get('ed_0062'), min : 0, max : 4, step : 1, def : 0 }
		];
		this.skin_obj = new cafen.TableAuto({style : {tableLayout:'fixed', cursor : cafen.getCursor(), width : 'auto'}});
		this.skinArea.appendChild(this.skin_obj);
		var setValueBind = this.setValue.bind(this);
		for(var i = 0 ;  i < this.menuInfo.length; i++) {
			var currObj = this.menuInfo[i];
			this.buttonArea.addRow();
			this.buttonArea.addCell('<font size=2>' + currObj.name+'</font>');
			this.buttonArea.addStyle({textAlign:'right',width:'60px'});
			currObj.obj = new cafen.Slider({cmd : currObj.cmd , className : 'r-boxwhite',def : currObj.def, min : currObj.min, max : currObj.max , step : currObj.step , size : 80, event : {end : setValueBind}});
			this.buttonArea.addCell(currObj.obj);
			this.buttonArea.addStyle({padding:'1px'});
		}
		this.buttonArea.addRow();
		var tmpButtonArea = new cafen.TableAuto({style : {}, attribute :{align:'center', cellSpacing:2}});
		tmpButtonArea.addCell(
			new cafen.XButton({text: cafenMsg.get('com_done'), style :{width : '37px'},event:{'click' : this.send2Editor.bind(this)}})
		);
		tmpButtonArea.addCell(
			new cafen.XButton({text: cafenMsg.get('com_init'), style :{width : '37px'},event:{'click' : this.initOption.bind(this)}})
		);
		tmpButtonArea.addCell(
			new cafen.XButton({text: cafenMsg.get('com_close'), style :{width : '37px'},event:{'click' : this.close.bind(this)}})
		);
		this.buttonArea.addCell(tmpButtonArea);
		this.buttonArea.addAttribute({colspan : 2});
		cafen.smallSWFAjax.getFlashXml({mode:'SKIN'}, this.setSkinType.bind(this), this._uploadScript, false);
	},
	initOption : function() {
		for(var i = 0; i < this.menuInfo.length; i++) 
			this.menuInfo[i].obj.setValue(this.menuInfo[i].def);
		this._skinOptions = {};
		this.setSkin(null);
	},
	preViewImage : function(bl) {
		var imgurl = this.getImageUrl();
		if (imgurl != '') {
			if (bl)
				this._send2Editor = true;
			else
				this._send2Editor = false;
			this.showProcess(true);
			cafen.smallSWFAjax.getFlashXml({mode:'THUMB', base_dir : 'thumb_junk/', makenew : (bl) ? 'Y' : 'N', name : imgurl}, this.setImageUrl.bind(this), this._uploadScript, false);
		} else {
			if (bl) {
				var html_tag = '<div align=center width=100%><img src='+this._uploadUrl+this.baseFileObj+'></div>';
				if (this._editorObj.insertHTML)
					this._editorObj.insertHTML(html_tag);
				this.close();
			} else
				this.setImage(this._uploadUrl+this.baseFileObj);
		}
	},
	send2Editor : function() {
		this.preViewImage(true);
	},
	setFileObj : function(obj) {
		this._send2Editor = false;
		this.baseFileObj = obj.server;
		this.baseFileOrg = obj;
		this.tmpImage = new Image();
		this.tmpImage.src = this._uploadUrl+this.baseFileObj;
		this.initOption();
	},
	setSkinType : function(xml) {
		var rssObj = new cafen.xmlParser(xml);
		var contentsObj = null;
		var datas = [];
		var skinurl = null;
		if (contentsObj = rssObj.getNext()) {
			var item = null;
			skinurl = contentsObj.getNode('skinurl');
			while(item = contentsObj.getNext()) {
				var name = item.getNode('name');
				var seqn = item.getNode('seqn');
				var icon = 'icon/' +item.getNode('icon');
				var description = item.getNode('description');
				datas.push({name : name, seqn : seqn, icon : icon, text : description});
			}			
		}
		this.skinObject = datas;
		this.skin_obj.addRow();
		this.skin_obj.setStyle({width : (this.skinObject.length*70) +'px'});
		for(var i = 0; i < this.skinObject.length; i++) {
			var currObj = this.skinObject[i];
			var tmpCell = this.skin_obj.addCell('&nbsp;');
			this.skin_obj.addStyle({border : '2px solid transparent',width : '70px', height: '70px', backgroundImage: 'url('+skinurl + currObj.icon+')'});
			tmpCell.attachEvent("click", this.setSkin.bind(this, i));
			currObj.obj = tmpCell;
		}
	},
	setSkin : function(no) {
		if (this._lastSkinNo != null) 
			this.skinObject[this._lastSkinNo].obj.setStyle({border : '2px solid transparent'}); 
		if (no != null && this._lastSkinNo != no) {
			this.skinObject[no].obj.setStyle({border : '2px dotted #b36836'}); 
			this._lastSkinNo = no;
		} else 
			this._lastSkinNo = null;
		this.preViewImage(false);
	},
	setValue : function(obj) {
		var cmd = obj.options.cmd;
		this._skinOptions[cmd] = obj.getValue();
		this.preViewImage(false);
		return true;
	},
	getImageUrl : function() {
		var theUrl = [];
		if (this._imageMax == null) 
			this._imageMax = Math.max(this.tmpImage.width, this.tmpImage.height);
		if (this._imageMax != null && this._skinOptions['M'] != null && this._skinOptions['M'] != 100) {
			var tmpWidth = Math.round(this._imageMax * this._skinOptions['M']/100);
			theUrl.push('M'+Math.max(100,Math.min(tmpWidth,900)));
		}
		if (this._skinOptions['W'] != null && this._skinOptions['W'] != 100)
			theUrl.push('W'+this._skinOptions['W']);
		if (this._skinOptions['A'] != null && this._skinOptions['A'] != 100)
			theUrl.push('A'+this._skinOptions['A']);
		if (this._skinOptions['H'] != null && this._skinOptions['H'] != 0)
			theUrl.push('H'+this._skinOptions['H']);
		if (this._skinOptions['G'] != null && this._skinOptions['G'] != 0) 
			theUrl.push('G');
		if (this._skinOptions['N'] != null && this._skinOptions['N'] != 0)
			theUrl.push('N');
		if (this._skinOptions['C'] != null && this._skinOptions['C'] != 100)
			theUrl.push('C'+this._skinOptions['C']);
		if (this._skinOptions['B'] != null && this._skinOptions['B'] != 10)
			theUrl.push('B'+this._skinOptions['B']);
		if (this._skinOptions['R'] != null && this._skinOptions['R'] != 0)
			theUrl.push('R'+this._skinOptions['R']);
		if (this._lastSkinNo != null) {
			theUrl.push('K'+this._lastSkinNo+'');
			if (this._skinOptions['E'] != null && this._skinOptions['E'] != 0) {
				switch(this._skinOptions['E']) {
					case 1 :
						theUrl.push('M');
						break;
					case 2 :
						theUrl.push('MD');
						break;
					case 3 :
						theUrl.push('MDT');
						break;
				}
			}
		}			
		if (theUrl.length > 0) 
			return this.baseFileObj +'_'+theUrl.join('')+'.png';
		else
			return '';
	},
	setImageUrl : function(xml) {
		var rssObj = new cafen.xmlParser(xml);
		var contentsObj = null;
		var fileObj = {};
		if (contentsObj = rssObj.getNext()) {
			var item = null;
			while(item = contentsObj.getNext()) {
				fileObj = {
					fileName : item.getNode('filename'),
					extension : item.getNode('fileext'),
					server : item.getNode('fileserver'),
					size : parseInt(item.getNode('filesize')),
					html_tag : ''
				}
			}
		}
		this.showProcess(false);
		this.setImage(this._uploadUrl+fileObj.server);
		if (this._send2Editor) {
			fileObj.html_tag = '<div align=center width=100%><img src='+this._uploadUrl+fileObj.server+'></div>';
			fileObj.fileName = cafenMsg.get('ed_0074') +this.baseFileOrg.fileName; 
			if (this._editorObj.execCommand('attach',true,fileObj)) {
				this._send2Editor = false;
				this.close();
			} else {
				this.showMsg(cafenMsg.get('ed_0019', cafen.getSize2Short(this._editorObj.editorAttachView.attachSize,2), cafen.getSize2Short(this._editorObj.editorAttachView.maxUpload,2), cafen.getSize2Short(fileObj.size,2)), true);
			}
		}
	},
	showProcess : function(bl) {
		if (bl) {
			if (this.processViewer == null) {
				this.processViewer = new cafen.TableAuto({style : {}, attribute :{align:'center', cellSpacing:2, width : '100%', height: '100%'}});
				this.processViewer.addRow();
				this.processViewer.addCell(cafenMsg.get('com_process'));
				this.processViewer.addStyle({textAlign:'center'});
				this.processViewer.addAttribute({className:'r-gride'});
				this.contentsObj.appendChild(this.processViewer);
			}
			if (this.processViewer != null)
				this.processViewer.show();
			if (this.imgViewer != null)
				this.imgViewer.hide();
		} else {
			if (this.processViewer != null)
				this.processViewer.hide();
			if (this.imgViewer != null)
				this.imgViewer.show();
		}
	},
	setImage : function(src) {
		if (this.imgViewer == null) {
			if (this._editorObj)
//				this.imgViewer = new cafen.Image(src, {style : cafen.extend(this.options.style,{position :'relative', width : this._previewWidth +'px', height : this._previewHeight +'px'}), scale : 'max'});
				this.imgViewer = new cafen.Image(src, {style : cafen.extend(this.options.style,{width : this._previewWidth +'px', height : this._previewHeight +'px'})});
			else
				this.imgViewer = new cafen.Image(src, {style : cafen.extend(this.options.style,{position :'relative', width : this._previewWidth +'px', height : this._previewHeight +'px'}), scale : 'max'});
			this.contentsObj.appendChild(this.imgViewer);
		} else {
			this.imgViewer.setImage(src);
		}
	},
	showMsg : function(msg) {
		if (this.msgObj == null) {
			this.msgObj = new cafen.XAlert({title :cafenMsg.get('com_alert'), contents :'', sticker : {obj : this, x : 'center', y : 'middle'}, style : {width: '300px'}});
			this.addChild(this.msgObj);
		}
		this.msgObj.setContents(msg, {x : 'center', y : 'middle', plus : [0, 5]});
		this.msgObj.onLoad();
	},
	onPopup : function() {
		if (	this._editorObj != null && this._editorObj.saveFocus) 
			this._editorObj.saveFocus();
	}
},cafen.XWindow.prototype);


cafen.XMovieViewer = function(options, editorObj) {
	this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r-popskin', tag : 'div', tplName : 'top', style : {width:'200px',textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.setTitle(cafenMsg.get('com_movieview'));
	if (editorObj) {
		this.setToolBar(false);
		this._editorObj = editorObj;
		this._uploadScript = this._editorObj.getUploadScript();
		this._uploadUrl = this._editorObj.getUploadUrl();
		this._mediaparam = (this._editorObj.getMediaPlayerParam) ? this._editorObj.getMediaPlayerParam(true) : '';
		this._previewWidth = parseInt(this.options.style.width) - 170;
		this._previewHeight = parseInt(this.options.style.height) - 10;
		var tmpTable = new cafen.TableAuto({style : {}});
		var tmpTable2 = new cafen.TableAuto({className : 'r-boxblue', style : {width : '150px', margin :'2px'}});
		tmpTable.addCell(tmpTable2);
		tmpTable.addStyle({verticalAlign: 'top'});
		tmpTable2.addRow();
		this.buttonArea = new cafen.TableAuto({style : {}});
		tmpTable2.addCell(this.buttonArea);
		tmpTable2.addStyle({verticalAlign: 'top'});

		this.contentsObj = new cafen.Div(cafen.extend({className : 'r-boxwhite', style : this.options.style},{style:{width : this._previewWidth+'px', height : this._previewHeight+'px', overflow:'hidden', overflowY:'auto', overflowX:'auto', position :'relative', textAlign:'left', margin :'2px'}}));
		tmpTable.addCell(this.contentsObj);
		tmpTable.addStyle({verticalAlign: 'top'});
		this.setObject(tmpTable);
		this.drawMenu();	
	} else {
		this.setToolBar(true);
		this._previewWidth = parseInt(this.options.style.width) - 6;
		this._previewHeight = parseInt(this.options.style.height) - 6;
		this.contentsObj = new cafen.Div(cafen.extend({style : this.options.style},{style:{overflow:'hidden', overflowY:'hidden', overflowX:'hidden', position :'relative', textAlign:'left'}}));
		this.setObject(this.contentsObj);
	}
}

cafen.XMovieViewer.prototype = cafen.extendClass({
	drawMenu : function() {
		this._lastSkinNo = null;
		this._skinOptions = {};
		this.menuInfo = [
			{cmd : 'S', name :cafenMsg.get('ed_0080'), min : 0, max : 100, step : 5, def : 0},
			{cmd : 'T', name :cafenMsg.get('ed_0081'), min : 0, max : 100, step : 5, def : 100},
			{cmd : 'Q', name :cafenMsg.get('ed_0079'), min : 0, max : 1, step : 1, def : 0 },
			{cmd : 'P', name :cafenMsg.get('ed_0082'), min : 0, max : 100, step : 5, def : 0 }
		];
		var setValueBind = this.setValue.bind(this);
		for(var i = 0 ;  i < this.menuInfo.length; i++) {
			var currObj = this.menuInfo[i];
			this.buttonArea.addRow();
			this.buttonArea.addCell('<font size=2>' + currObj.name+'</font>');
			this.buttonArea.addStyle({textAlign:'right', width: '60px'});
			currObj.obj = new cafen.Slider({cmd : currObj.cmd , className : 'r-boxwhite',def : currObj.def, min : currObj.min, max : currObj.max , step : currObj.step , size : 80, event : {end : setValueBind}});
			this.buttonArea.addCell(currObj.obj);
			this.buttonArea.addStyle({padding:'1px'});
		}
		this.buttonArea.addRow();
		var tmpButtonArea = new cafen.TableAuto({style : {}, attribute :{align:'center', cellSpacing:2}});
		tmpButtonArea.addCell(
			new cafen.XButton({text: cafenMsg.get('com_done'), style :{width : '37px'},event:{'click' : this.send2Editor.bind(this)}})
		);
		tmpButtonArea.addCell(
			new cafen.XButton({text: cafenMsg.get('com_init'), style :{width : '37px'},event:{'click' : this.initOption.bind(this)}})
		);
		tmpButtonArea.addCell(
			new cafen.XButton({text: cafenMsg.get('com_close'), style :{width : '37px'},event:{'click' : this.close.bind(this)}})
		);
		this.buttonArea.addCell(tmpButtonArea);
		this.buttonArea.addAttribute({colspan : 2});
	},
	initOption : function() {
		for(var i = 0; i < this.menuInfo.length; i++) 
			this.menuInfo[i].obj.setValue(this.menuInfo[i].def);
		this._skinOptions = {};
		this.preViewMovie(false);
	},
	setValue : function(obj) {
		var cmd = obj.options.cmd;
		this._skinOptions[cmd] = obj.getValue();
		switch (cmd) {
			case 'S' :
				var startValue = this._skinOptions[cmd];
				if (this._skinOptions['T'] != null && startValue >= this._skinOptions['T']) {
					this._skinOptions['T'] = Math.min(startValue + 5, 100);
					this.menuInfo[1].obj.setValue(this._skinOptions['T']);
				}
				break;
			case 'T' :
				var endValue = this._skinOptions[cmd];
				if (this._skinOptions['S'] != null && endValue <= this._skinOptions['S']) {
					this._skinOptions['S'] = Math.max(endValue - 5, 0);
					this.menuInfo[0].obj.setValue(this._skinOptions['S']);
				}
				break;
		}
		this.preViewMovie(false);
		return true;
	},
	preViewMovie : function(bl) {
		var movie_url = this.getMovieUrl();
		if (movie_url != '') {
			var img_url = this.getThumbUrl();
			if (bl)
				this._send2Editor = true;
			else
				this._send2Editor = false;
			this.showProcess(true);
			cafen.smallSWFAjax.getFlashXml({mode:'MOVIE', base_dir : 'thumb_junk/', makenew : (bl) ? 'Y' : 'N', name : movie_url, img : img_url}, this.setMovieUrl.bind(this), this._uploadScript, false);
		} else {
			if (bl) {
				var html_tag = '<div align=center width=100%><img src='+this._uploadUrl+this.baseFileObj+'></div>';
				this._editorObj.insertHTML(html_tag);
				this.close();
			} else
				this.setMovie(this._uploadUrl+this.baseFileObj);
		}
	},
	getMovieUrl : function() {
		var theUrl = [];
		if (this._skinOptions['S'] != null && this._skinOptions['S'] != 0)
			theUrl.push('S'+this._skinOptions['S']);
		else
			theUrl.push('S0');
		if (this._skinOptions['T'] != null && this._skinOptions['T'] != 100)
			theUrl.push('T'+this._skinOptions['T']);
		else
			theUrl.push('T100');
		if (this._skinOptions['Q'] != null && this._skinOptions['Q'] != 0)
			theUrl.push('Q1');
		else
			theUrl.push('Q0');
		if (theUrl.length > 0) 
			return this.baseFileObj +'_'+theUrl.join('')+'.flv';
		else
			return '';
	},
	setMovieUrl : function(xml) {
		var rssObj = new cafen.xmlParser(xml);
		var contentsObj = null;
		var fileObj = {};
		if (contentsObj = rssObj.getNext()) {
			var item = null;
			while(item = contentsObj.getNext()) {
				fileObj = {
					fileName : item.getNode('filename'),
					extension : item.getNode('fileext'),
					server : item.getNode('fileserver'),
					size : parseInt(item.getNode('filesize')),
					extra : item.getNode('extra'),
					html_tag : ''
				}
			}
		}
		this.showProcess(false);
		var str = _cafen_service_url+'images/mediaplayer.swf?file='
				+ this._uploadUrl + fileObj.server +'&amp;image='
				+ this._uploadUrl + fileObj.extra + this._mediaparam;
		this.setMovie(str);
		if (this._send2Editor) {
			var objs = [];
			objs.push('<embed type="application/x-shockwave-flash" wmode="transparent" align=center ');
			objs.push('src="'+str+'" ');
			objs.push('allowFullScreen="true" width="440px" height="320px" quality="high"  ');
			objs.push(' ></embed>');
			fileObj.html_tag = '<div align=center width=100%>' +objs.join('')+'</div>';
			fileObj.fileName = cafenMsg.get('ed_0074') +this.baseFileOrg.fileName; 
			if (this._editorObj.execCommand('attach',true,fileObj)) {
				this._send2Editor = false;
				this.close();
			} else {
				this.showMsg(cafenMsg.get('ed_0019', cafen.getSize2Short(this._editorObj.editorAttachView.attachSize,2), cafen.getSize2Short(this._editorObj.editorAttachView.maxUpload,2), cafen.getSize2Short(fileObj.size,2)), true);
			}
		}
	},
	getThumbUrl : function() {
		var theUrl = [];
		if (this._skinOptions['P'] != null && this._skinOptions['P'] != 0)
			theUrl.push('S'+this._skinOptions['P']);
		else
			theUrl.push('S0');
		if (theUrl.length > 0) 
			return this.baseFileObj +'_'+theUrl.join('')+'.png';
		else
			return '';
	},
	showProcess : function(bl) {
		if (bl) {
			if (this.processViewer == null) {
				this.processViewer = new cafen.TableAuto({style : {}, attribute :{align:'center', cellSpacing:2, width : '100%', height: '100%'}});
				this.processViewer.addRow();
				this.processViewer.addCell(cafenMsg.get('com_process'));
				this.processViewer.addStyle({textAlign:'center'});
				this.processViewer.addAttribute({className:'r-gride'});
				this.contentsObj.appendChild(this.processViewer);
			}
			if (this.processViewer != null)
				this.processViewer.show();
			if (this.movieViewer != null)
				this.movieViewer.hide();
		} else {
			if (this.processViewer != null)
				this.processViewer.hide();
			if (this.movieViewer != null)
				this.movieViewer.show();
		}
	},
	send2Editor : function() {
		this.preViewMovie(true);
	},
	setFileObj : function(obj) {
		this._send2Editor = false;
		this.baseFileObj = obj.server;
		this.baseFileOrg = obj;
		this.initOption();
	},
	setMovie : function(src) {
		if (this.movieViewer == null) {
			this.movieViewer = new cafen.Div({style :{width:this._previewWidth +'px', height : this._previewHeight +'px'}});
			this.contentsObj.appendChild(this.movieViewer);
		}
		var objs = [];
		objs.push('<embed type="application/x-shockwave-flash" wmode="transparent" align=center ');
		objs.push('src="'+src+'" ');
		objs.push('allowFullScreen="true" width="'+this._previewWidth+'px" height="'+this._previewHeight+'px" quality="high"  ');
		objs.push(' ></embed>');
		this.movieViewer.getElement().innerHTML = objs.join('');
	},
	showMsg : function(msg) {
		if (this.msgObj == null) {
			this.msgObj = new cafen.XAlert({title :cafenMsg.get('com_alert'), contents :'', sticker : {obj : this, x : 'center', y : 'middle'}, style : {width: '300px'}});
			this.addChild(this.msgObj);
		}
		this.msgObj.setContents(msg, {x : 'center', y : 'middle', plus : [0, 5]});
		this.msgObj.onLoad();
	},
	onPopup : function() {
		if (	this._editorObj != null && this._editorObj.saveFocus) 
			this._editorObj.saveFocus();
	}
},cafen.XWindow.prototype);


cafen.XMapViewer = function(options) {
	this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r-popskin', tag : 'div', tplName : 'both', style : {width:'200px',textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.setTitle(cafenMsg.get('com_mapview'));
	this.setToolBar();
	this.contentsObj = new cafen.Div(cafen.extend({style : this.options.style},{style:{overflow:'hidden', overflowY:'hidden', overflowX:'hidden', position :'relative', textAlign:'left'}}));
	this.setObject(this.contentsObj);
	this.initMapViewer();
}

cafen.XMapViewer.prototype = cafen.extendClass({
	initMapViewer : function() {
		this.buttonArea = new cafen.TableAuto({className : 'r-boxblue', style : {width : (parseInt(this.options.style.width)-12) +'px', margin :'2px'}});
		this.contentsObj.appendChild(this.buttonArea);
		this.mapInfo = {lat:34.949738, lon : 127.7822176, zoom : 15, marker : [], poly : [], maptype : 'satellite', width : parseInt(this.options.style.width)-12, height : parseInt(this.options.style.height)-40};
		this.clickStatus = {};
		this.mapObj = new cafen.Div({className : 'r-boxwhite', style : {width : this.mapInfo.width +'px', height : this.mapInfo.height +'px', margin :'2px'}});
		this.contentsObj.appendChild(this.mapObj);
		this.drawToolbar();
	},
	drawToolbar : function() {
		var buttonInfo = cafenMsg.getObject('map_buttonInfo');
		var groupstart = false;
		var groupmiddle = false;
		var groupend = false;
		var toolbarSet = cafenMsg.getObject('map_menu').mini;
		var cnt = toolbarSet.length;
		var currRowObj = null;
		this.statusButton = [];
		this.actionButton = {};
		var iconMargin = null;
		if(cafen.browser.isIE) 
			iconMargin = '0 0 0 3px';
		else if(cafen.browser.isFF) 
			iconMargin = '-1 0 0 0px';
		else
			iconMargin = '3px 0px 3px 2px';
		for(var i = 0; i < cnt ; i++) {
			if (currRowObj == null) {
				currRowObj = new cafen.TableAuto({align:'left', attribute : {border:0},style : {}});
				this.buttonArea.addRow();
				this.buttonArea.addCell(currRowObj);
				currRowObj.addRow();
			}
			var idx = toolbarSet[i];
			switch(idx) {
				case 'separator':
					break;
				case 'group' :
				case '[' :
					groupstart = true;
					groupmiddle = false;
					groupend = false;
					break;
				case 'break' :
				case ']' :
					groupstart = false;
					groupmiddle = false;
					groupend = false;
					currRowObj.addCell();
					currRowObj.addStyle({width:'3px'});
					currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					break;
				case 'blank' :
					currRowObj.addCell();
					currRowObj.addStyle({width:'3px'});
					currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					break;
				case 'linebreakb' :
				case 'linebreak' :
					groupstart = false;
					groupmiddle = false;
					groupend = false;
					this.buttonArea.addRow();
					this.buttonArea.addCell();
					this.buttonArea.addStyle({height:'3px'});
					currRowObj = null;
					break;
				default :
					var currButton = buttonInfo[idx];
					var buttonNo = currButton[2];
					var x = (buttonNo % 10) * 16;
					var y = Math.floor(buttonNo /10) * 16;
					var icon = null;
					var bindCommand = null;
					switch(idx) {
						case 'polycolor':
							icon = new cafen.XImage({className :'r-mapset',x: x,y : y}, {style:{cssFloat : 'left',margin : iconMargin, width:'16px', height:'16px'},attribute :{unselectable : 'on'}, childNodes : [new cafen.RMap.ButtonColor()]});
							bindCommand = (currButton[0] != null) ? this.execCommand.bind(this,currButton[0],'','') : this.actionCommand.bind(this,idx,'','');
							break;
						case 'search' :
							icon = new cafen.TableAuto({style:{cssFloat : 'left',margin : '3px 5px 3px 3px', position :'relative'}});
							this.inputSearch = new cafen.Input({style:{width:'75px', height:'16px',fontSize:'11px',padding :'0px'},attribute :{}, event :{end : this.searchKeyword.bind(this)}});
							icon.addCell(this.inputSearch);
							icon.addCell(new cafen.Button({style:{width:'20px', height:'16px'},attribute :{unselectable : 'on'}, event : {click : this.showSearchResult.bind(this)}}));
							break;
						default :
							icon = new cafen.XImage({className :'r-mapset',x: x,y : y}, {style:{cssFloat : 'left',margin : iconMargin, width:'16px', height:'16px'},attribute :{unselectable : 'on'}});
							bindCommand = (currButton[0] != null) ? this.execCommand.bind(this,currButton[0],'','') : this.actionCommand.bind(this,idx,'','');
							break;
					}
					var tmpButton = null;
					var baseBgPos = 0,baseSize =0 , basePadding = 0; 
					if (currButton[5] != null ) {
						if (currButton[5] > 60) {
							baseBgPos = 792;
							baseSize  = 100;
						} else if (currButton[5] > 30) {
							baseBgPos = 528;
							baseSize  = 56;
						} else {
							baseBgPos = 0;
							baseSize  = 33;
						}
						basePadding = 0;
					} else {
						baseBgPos = 264;
						baseSize  = 24;
						basePadding = 0;
					}
					if (icon != null) {
					var nextidx = (cnt -1 >= i +1) ? toolbarSet[i+1] : '';
					var tagButton = (bindCommand != null ) ? 'button' : 'div';
					var eventBind = (bindCommand == null ) ? {} : {click:bindCommand};
					if (!groupstart) {
						tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r-wordset', off : baseBgPos+132, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on'}, event :eventBind, childNodes : [icon]}) ;
						currRowObj.addCell(tmpButton);
						currRowObj.addStyle({width:baseSize +'px'});
						currRowObj.addCell();
						currRowObj.addStyle({width:'3px'});
						currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					} else {
						if (nextidx == 'group' || nextidx == 'break' || nextidx == ']'  || nextidx == ']' || nextidx == 'linebreak' || nextidx == 'linebreakb')
							groupend = true;
						if (!groupmiddle && groupend) {
							tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r-wordset', off : baseBgPos+198, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : currButton[1]}, event :eventBind, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else if (!groupmiddle) {
							tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r-wordset', off : baseBgPos, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : currButton[1]}, event :eventBind, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else if (groupend) {
							tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r-wordset', off : baseBgPos+132, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : currButton[1]}, event :eventBind, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else {
							tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r-wordset', off : baseBgPos+66, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : currButton[1]}, event :eventBind, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						}
						this.actionButton[idx] = {classObj : null, obj : tmpButton};
						if (currButton[4])
							this.statusButton.push({cmd : idx, obj : tmpButton});
						groupmiddle = true;
					}}
					break;
			}
		}	
	},
	setMapType : function(no) {
		switch(no) {
			case 0 :
				this.mapInfo.maptype = 'roadmap';
				this.actionButton['mtmap'].obj.setSelected(true);
				this.actionButton['mtsat'].obj.setSelected(false);
				this.actionButton['mthyb'].obj.setSelected(false);
				break;
			case 1 :
				this.mapInfo.maptype = 'satellite';
				this.actionButton['mtmap'].obj.setSelected(false);
				this.actionButton['mtsat'].obj.setSelected(true);
				this.actionButton['mthyb'].obj.setSelected(false);
				break;
			case 2 :
				if (this.mapInfo.maptype == 'mobile')
					this.mapInfo.maptype = 'terrain';
				else if (this.mapInfo.maptype == 'terrain')
					this.mapInfo.maptype = 'hybrid';
				else 
					this.mapInfo.maptype = 'mobile';
				this.actionButton['mtmap'].obj.setSelected(false);
				this.actionButton['mtsat'].obj.setSelected(false);
				this.actionButton['mthyb'].obj.setSelected(true);
				break;
		}
		this.preView();
	},
	setZoom : function(level) {
		this.mapInfo.zoom -= level;
		if (this.mapInfo.zoom > 20)
			this.mapInfo.zoom = 20;
		else if (this.mapInfo.zoom < 5)
			this.mapInfo.zoom = 5;
		this.preView();
	},
	execCommand : function(cmd) {
		switch(cmd.toLowerCase()) {
			case 'typemap' : 
				this.setMapType(0);
				break;
			case 'typesat' : 
				this.setMapType(1);
				break;
			case 'typehyb' : 
				this.setMapType(2);
				break;
			case 'zoomout' : 
				this.setZoom(1);
				break;
			case 'zoomin' : 
				this.setZoom(-1);
				break;
			case 'moveup' :
				this.setMap(this.pixelToLatLng(0,-100, this.mapInfo.zoom));
				break;
			case 'movedown' :
				this.setMap(this.pixelToLatLng(0,100, this.mapInfo.zoom));
				break;
			case 'moveleft' :
				this.setMap(this.pixelToLatLng(-100,0, this.mapInfo.zoom));
				break;
			case 'moveright' :
				this.setMap(this.pixelToLatLng(100,0, this.mapInfo.zoom));
				break;
			case 'deleteuser' :
				this.mapInfo.marker = [];
				this.preView();				
				break;
			case 'deletepoly' :
				this.mapInfo.poly = [];
				this.preView();				
				break;
			case 'poly' :
			case 'user' :
				if (this.imgview != null) {
					this.clickStatus[cmd] = this.actionButton[cmd].obj.toggleSelect();
					if (this.clickStatus['poly'] || this.clickStatus['user']) {
						if (!this.clickStatus.click) {
							this.clickStatus.click = true;
							if (this.clickBind == null)
								this.clickBind = this.setMarker.bind(this);
							this.imgview.attachEvent('click' , this.clickBind);
						}
					} else {
						this.clickStatus.click = false;
						this.imgview.detachEvent('click' , this.clickBind);
					}
				}
				break;
			default :
				break;
		}
	},
	latLngToPixel : function(lat, lng, zoom) {
 		var centerPoint=Math.pow(2,zoom+7),
 			totalPixels=centerPoint*2,
 			pixelsPerLngDegree=totalPixels/360,
 			pixelsPerLngRadian=totalPixels/(2*Math.PI),
 			siny=Math.min(Math.max(Math.sin(lat*(Math.PI/180)),-0.9999),0.9999);
 		return{
 			x:Math.round(centerPoint+lng*pixelsPerLngDegree),
 			y:Math.round(centerPoint-0.5*Math.log((1+siny)/(1-siny))*pixelsPerLngRadian)
 		}
	},
	pixelToLatLng : function(x, y, zoom) { 
 		var centerPoint=Math.pow(2,zoom+7),
 			totalPixels=centerPoint*2,
 			pixelsPerLngDegree=totalPixels/360,
 			pixelsPerLngRadian=totalPixels/(2*Math.PI);
		var oldxy = this.latLngToPixel(this.mapInfo.lat, this.mapInfo.lon,zoom);
		y  += oldxy.y; 
		x  += oldxy.x; 
		return {
			lat : (2*Math.atan(Math.exp(-(y-centerPoint)/pixelsPerLngRadian))-Math.PI/2) /(Math.PI/180), 
			lon : (x-centerPoint)/pixelsPerLngDegree
		};
	},
	actionCommand : function(cmd,obj) {
		switch(cmd) {
			case 'save' :
				if (this.mapImg != null ) 
					this.execEvent('done');
				break;
		}
	},	
	showMsg : function(msg) {
		if (this.statusObj == null) {
			this.statusObj = new cafen.Div({style : {marginTop:'5px', paddingLeft: '4px'}});
			this.appendChild(this.statusObj, 'bottom');
		}
		this.statusObj.getElement().innerHTML = msg;
	},
	searchKeyword : function(obj) {
		var keyword = obj.getValue();
		if (keyword.split(' ').join('') == '') {
			this.showMsg(cafenMsg.get('map_0005'));
			this.inputSearch.focus();
		} else {
			if (cafen.checkAPI('GMap')) {
				var param = {
					q: keyword,
					output : 'json',
					oe:'utf8',
					hl :'ko',
					sensor:'false',
					key: cafen.getAPI('GMap')
				};
				cafen.smallSWFAjax.getFlashXml(param,this.setkeywordResult.bind(this),'http://maps.google.com/maps/geo');	
			} else {
				this.showMsg(cafenMsg.get('com_nullkey'));
			}
		}
	},
	setkeywordResult : function(txt) {
		var json = cafen.getString2Json(txt);
		if (json.Status) {
			if (json.Status.code == 200 && json.Placemark)  {
				if (json.Placemark.length > 0) {
					var Lon = json.Placemark[0].Point.coordinates[0];
					var Lat = json.Placemark[0].Point.coordinates[1];
					this.setMap({lat: Lat, lon : Lon});			
				} else
					this.showMsg(cafenMsg.get('com_nodata'));
			} else
				this.showMsg(cafenMsg.get('com_nodata'));
		} else
			this.showMsg(cafenMsg.get('com_nodata'));
	},
	showSearchResult : function() {

	},
	setMarker : function(obj, event) {
		var pos1 = cafen.pointer(event || window.event);
		var pos2 = obj.cumulativeOffset();
		var x =  (pos1[0] - pos2[0]) - this.mapInfo.width / 2;
		var y =  (pos1[1] - pos2[1]) - this.mapInfo.height / 2;
		var latlon = this.pixelToLatLng(x,y, this.mapInfo.zoom);
		if (this.clickStatus['user'])
			this.mapInfo.marker.push(latlon);
		if (this.clickStatus['poly'])
			this.mapInfo.poly.push(latlon);
		this.preView();
	},
	setMap : function(mapInfo) {
		if (mapInfo != null && typeof mapInfo == 'string') {
			var tmpUrl = 	mapInfo.split('?');
			mapInfo = {};
			if (tmpUrl[1] != null) {
				var mapData =tmpUrl[1].split('&');
				for(var i = 0 ; i < mapData.length; i++) {
					var tmpVal = 	mapData[i].split('=');
					switch(tmpVal[0]) {
						case 'center' :
							var latLon = tmpVal[1].split(',');
							mapInfo.lat = parseFloat(latLon[0]);
							mapInfo.lon = parseFloat(latLon[1]);
							break;
						case 'zoom' :
							mapInfo.zoom = parseInt(tmpVal[1]);
							break;
					}
				}
			}
		}
			
		if (mapInfo != null && mapInfo.lat != null && mapInfo.lon) {
			this.mapInfo.lat = mapInfo.lat;
			this.mapInfo.lon = mapInfo.lon;
			if (mapInfo.zoom != null) 
				this.mapInfo.zoom = mapInfo.zoom;
			this.mapInfo.marker = [];
		}
		this.preView();
	},
	preView : function() {
		if (cafen.checkAPI('GMap')) {
			var params = [];
			params.push('center='+this.mapInfo.lat+','+this.mapInfo.lon);
			params.push('size='+this.mapInfo.width+'x'+this.mapInfo.height);
			params.push('key='+cafen.getAPI('GMap'));
			params.push('maptype='+this.mapInfo.maptype);
			params.push('zoom='+this.mapInfo.zoom);
			if (this.mapInfo.marker.length > 0) {
				var colorInfo = ['black', 'brown', 'green', 'purple', 'yellow', 'blue', 'gray', 'orange','red', 'white'];
				var alphaInfo = 'abcdefghijklmnopqrstuvwxyz';
				var markerparam = [];
				for(var i = 0 ; i < this.mapInfo.marker.length; i++) {
					var marker = this.mapInfo.marker[i];
					markerparam.push(marker.lat+','+marker.lon+','+colorInfo[i %10]+alphaInfo.charAt(i%26));
				}
				params.push('markers='+markerparam.join('|'));
			}
			if (this.mapInfo.poly.length > 0) {
				var markerparam = [];
				for(var i = 0 ; i < this.mapInfo.poly.length; i++) {
					var marker = this.mapInfo.poly[i];
					markerparam.push(marker.lat+','+marker.lon);
				}
				params.push('path=rgb:0xff0000,weight:3|'+markerparam.join('|'));
			}
			params.push('sensor=false');
			params.push('format=jpg');
			 
			this.mapImg = 'http://maps.google.co.kr/staticmap?'+ params.join('&');
			if (this.imgview == null) {
				this.imgview = new cafen.Image(this.mapImg, {style :{width : this.mapInfo.width +'px' , height : this.mapInfo.height +'px'}, scale : 'max'});
				this.mapObj.appendChild(this.imgview);	
			} else
				this.imgview.setImage(this.mapImg);
		} else {
			this.mapObj.getElement().innerHTML = cafenMsg.get('com_nullkey');
			this.mapObj.setStyle({textAlign:'center', paddingTop:'20px'});
		}
	},
	getMap : function() {
		return this.mapImg;
	},
	getMapInfo : function() {
		return this.mapInfo;
	},
	getType : function() {
		return this.mapInfo.maptype;
	},
	getLat : function() {
		return this.mapInfo.lat;
	},
	getLng : function() {
		return this.mapInfo.lon;
	},
	getZoom : function() {
		return this.mapInfo.zoom;
	},
	getMarker : function() {
		return this.mapInfo.marker;	
	},
	getPolyline : function() {
		return this.mapInfo.poly;	
	}
},cafen.XWindow.prototype);


cafen.XConfirm = function(options) {
	this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r-popskin', tag : 'div', tplName : 'top', style : {width:'300px',textAlign:'center', position :'absolute'}, shadow : true, resize : 'XXXOOOOOO'}, options));
	if (options.title != null)
		this.setTitle(options.title);
	this.setToolBar();
	if (options.contents != null)
		this.setContents(options.contents);
	this.setButton(new cafen.XButton({text: cafenMsg.get('util_0004'), style :{width : '60px'}, align:'center',event:{'click' : this.sendValue.bind(this,true)}}));
	this.setButton(new cafen.XButton({text: cafenMsg.get('util_0005'), style :{width : '60px'}, align:'center',event:{'click' : this.sendValue.bind(this, false)}}));
}

cafen.XConfirm.prototype = cafen.extendClass({

},cafen.XWindow.prototype);


cafen.XCalendar = function(options) {
	this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r-popskin', tag : 'div', tplName : 'top', style : {width:'200px',textAlign:'center', position :'absolute', padding: '2px'}, shadow : true}, options));
	if (options.title != null)
		this.setTitle(options.title);
	this.setToolBar();
	this.initCalendar();
}

cafen.XCalendar.prototype = cafen.extendClass({
	_calTable : null,
	_topObj : null,
	_inputObj : null,
	_currentData : null,
	_DOMonth : [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], 
	_lDOMonth : [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
	_NameEng : null,
	_monthDate : [], 
	initCalendar : function() {
		this._NameEng = cafenMsg.getObject('com_dayname');
		this._currentData = new Date();
		this._topObj = new cafen.TableAuto({attribute:{border :'0', width :'100%', cellPadding:2}});
		this._inputObj = new cafen.XInput({style : {width: '100px'}, event : {blur : this.setDateInput.bind(this)}});
		this._topObj.addCell(this._inputObj);
		this._topObj.addCell();
		this._topObj.addStyle({textAlign:'right', width :'31px', verticalAlign: 'bottom'});
		this._topObj.addChild(new cafen.XIcon({icon: 'r-iconset', off : 180, on : 0, over : 15, event : {click : this.movePrev.bind(this)}, style : {width : '15px', height : '15px'}}));
		this._topObj.addChild(new cafen.XIcon({icon: 'r-iconset', off : 165, on : 0, over : 15, event : {click : this.moveNext.bind(this)}, style : {width : '15px', height : '15px'}}));
		this.appendChild(this._topObj);
		this._calTable = new cafen.TableAuto({attribute:{border :0, width :'100%', cellpadding : 2, cellspacing:1}, style : {marginTop : '3px'}});
		this.appendChild(this._calTable);
		for (var i =0 ; i < 7; i++) {
			this._calTable.addRow();
			for (var j =0 ; j < 7; j++) {
				var cell = this._calTable.addCell();
				if (i == 0) { 
					this._calTable.addText(this._NameEng[j]);
					this._calTable.addStyle({textAlign:'center', padding:'2px', fontSize : '12px',border : '1px solid #d0d0d0',width : '14.28%'});
				} else {
					cell.attachEvent('click',this.setDate.bind(this, (i -1) * 7 +j));
					this._calTable.addStyle({textAlign:'right', cursor : cafen.getCursor(), padding: '3px',fontSize : '12px', borderRight : '1px dotted #d0d0d0', borderLeft: '1px none transparent', borderTop: '1px none transparent', borderBottom: '1px dotted #d0d0d0'});
				}
			}
		}
		this.showMonth(this._currentData.getFullYear(), this._currentData.getMonth() +1);
	},
	getDaysOfMonth : function(year, month) { 
		if ((year % 4) == 0) { 
			if ((year % 100) == 0 && (year % 400) != 0) return this._DOMonth[month]; 
			return this._lDOMonth[month]; 
		} else return this._DOMonth[month]; 
	},
	getFirstDay : function(year, month) {
		var tmpDate = new Date(); 
		tmpDate.setDate(1); 
		tmpDate.setMonth(month); 
		tmpDate.setFullYear(year); 
		return tmpDate.getDay(); 
	},
	getLastDay : function(year, month) {
		var tmpDate = new Date(); 
		tmpDate.setMonth(month); 
		tmpDate.setFullYear(year); 
		tmpDate.setDate( getDaysOfMonth(year, month) ); 
		return tmpDate.getDay(); 
	},
	moveNext : function() {
		this.showMonth(this._currentData.getFullYear(), this._currentData.getMonth() + 2);
	},
	movePrev : function() {
		this.showMonth(this._currentData.getFullYear(), this._currentData.getMonth());
	},
	clearMonth : function() {
		for (var i =1 ; i < 7; i++) 
			for (var j =0 ; j < 7; j++) 
				this._calTable.addText('&nbsp;', j, i);
	},
	getMonthYear : function() {
		var txt  = this._currentData.getFullYear() +'/';
		var month = this._currentData.getMonth() +1;
		return (month > 9) ? txt + month : txt + '0'+month;
	},
	setDate : function(no) {
		if (typeof no == 'number') {
			var day  = this._monthDate[no];
			if (day != null) {
				var dayTxt = [];
				dayTxt.push(this._currentData.getFullYear());
				var month = this._currentData.getMonth() +1;
				month = (month > 9) ? month : '0' +month;
				dayTxt.push(month);
				day = (day > 9) ? day : '0' +day;
				dayTxt.push(day);
				this.sendValue(dayTxt.join('/'));
			}
		} else {
			var reg = null;
			if (reg = cafen.find('([0-9][0-9][0-9][0-9])\\/([0-9]+)', no)) {
				this.showMonth(parseInt(reg[1]), parseInt(reg[2]));	
			} else {
				this._inputObj.setValue(this.getMonthYear());
			}
		}
	},
	setDateInput : function(obj) {
		var txt = obj.getValue();
		var reg = null;
		if (reg = cafen.find('([0-9][0-9][0-9][0-9])\\/([0-9]+)', txt)) {
			this.showMonth(parseInt(reg[1]), parseInt(reg[2]));	
		} else {
			this._inputObj.setValue(this.getMonthYear());
		}
	},
	showMonth : function (year, month) {
		this._currentData = new Date(year,month -1,1);
		this._monthDate = [];
		var cnt = this.getDaysOfMonth(this._currentData.getFullYear(), this._currentData.getMonth());
		this._inputObj.setValue(this.getMonthYear());
		this.clearMonth();
		var start = (this.getFirstDay(this._currentData.getFullYear(), this._currentData.getMonth())) % 7;
		for (var i =0; i < 42 ; i++)
			this._monthDate.push(null);
		for (var i = 1; i <= cnt ; i++) {
			this._monthDate[start] = i;
			var row = Math.floor(start/7) +1;
			var col = start % 7;
			this._calTable.addText(i, col, row);
			start++;
		}
	}
},cafen.XWindow.prototype);

cafen.XColorpicker = function(options) {
		this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r-popskin', tag : 'div', tplName : 'both', style : {width:'auto',textAlign:'left', position :'absolute', overflowX : 'hidden', padding: '2px'}, shadow : true}, options));
	if (options.title != null)
		this.setTitle(options.title);
	this.setToolBar();
	this.initColorpicker();
}

cafen.XColorpicker.prototype = cafen.extendClass({
	_colorTable : null,
	_buttonObj : null,
	_currColorIdx : null,
	_toggleObj : null,
	_hsvObj : null,
	_chartBase : [
		{
			title : 'Normal',
			obj : null,
			color : [
		 		'#000000', '#444444', '#666666','#999999','#cccccc','#eeeeee','#f3f3f3','#ffffff',
		 		'#ff0000', '#ff9900', '#ffff00','#00ff00','#00ffff','#0000ff','#9900ff','#ff00ff',
		 		'#f4cccc', '#fce5cd', '#fff2cc','#d9ead3','#d0e0e3','#cfe2f3','#d9d2e9','#ead1dc',
		 		'#ea9999', '#f9cb9c', '#ffe599','#b6d7a8','#a2c4c9','#9fc5e8','#b4a7d6','#d5a6bd',
		 		'#e06666', '#f6b26b', '#ffd966','#93c47d','#76a5af','#6fa8dc','#b4a7d6','#c27ba0',
		 		'#cc0000', '#e69138', '#f1c232','#6aa84f','#45818e','#3d85c6','#674ea7','#a64d79',
		 		'#990000', '#b45f06', '#bf9000','#38761d','#134f5c','#0b5394','#351c75','#741b47',
		 		'#660000', '#783f04', '#7f6000','#274e13','#0c343d','#073763','#20124d','#4c1130'
			]
		},
		{
			title : 'Black',
			obj : null,
			color : [
				'#000000','#4D1A00','#1A1A00','#001A00','#001A33','#000040','#1A1A4D','#1A1A1A',
				'#400000','#803300','#404000','#004000','#004040','#000080','#33334D','#404040',
				'#800000','#804C00','#4D6600','#1A4D33','#1A6666','#1A3380','#400040','#4D4D4D',
				'#80007F','#806500','#7F8000','#668066','#668080','#4D6680','#4D1A33','#606060',
				'#804D66','#80664D','#80804D','#668066','#668080','#4D6680','#664D80','#808080'
			]
		},
		{
			title : 'White',
			obj : null,
			color : [
				'#7F7F7F','#CC997F','#99997F','#7F997F','#7F99B2','#7F7FBF','#9999CC','#999999',
				'#BF7F7F','#FFB27F','#BFBF7F','#7FBF7F','#7FBFBF','#7F7FFF','#B2B2CC','#BFBFBF',
				'#FF7F7F','#FFCB7F','#CCE57F','#99CCB2','#99E5E5','#99B2FF','#BF7FBF','#CCCCCC',
				'#FF7FFE','#FFE47F','#FEFF7F','#7FFF7F','#7FFEFF','#7FE4FF','#CC99B2','#DFDFDF',
				'#FFCCE5','#FFE5CC','#FFFFCC','#E5FFE5','#E5FFFF','#CCE5FF','#E5CCFF','#FFFFFF'
			]
		}
	],
	_currentData : null,
	initColorpicker : function() {
		this._topObj = new cafen.TableAuto({attribute:{border :'0', width :'auto',height:'30px',cellpadding : 2}});
		this._previewObj = new cafen.Div({style : {width: '30px', height:'20px', border : '1px dotted #d0d0d0', cursor: cafen.getCursor()}, attribute : {title : cafenMsg.get('com_morecolor')},event:{click: this.toggleHSV.bind(this)}});
		this._topObj.addCell(this._previewObj);
		this._inputObj = new cafen.XInput({style : {width: '60px', marginLeft:'3px'}, event : {blur : this.setColorInput.bind(this), end : this.setColorInput.bind(this)}});
		this._topObj.addCell(this._inputObj);
		this._buttonObj = new cafen.XButton({text:cafenMsg.get('com_ok'), event : {click : this.sendColor.bind(this)}, style : { marginLeft:'3px'}});
		this._topObj.addCell(this._buttonObj);
		this.appendChild(this._topObj);
		var tabInfo = [];
		for(var i = 0; i < this._chartBase.length; i++) {
			this._chartBase[i].obj = new cafen.XTab({text: this._chartBase[i].title, align:'left', event : {click : this.setColorChart.bind(this, i), style : {width:'auto'}}});
			tabInfo.push(this._chartBase[i].obj);
		}
		this._tabObj = new cafen.XTabMenu(tabInfo);
		this.appendChild(this._tabObj);
		this.tmpTableSkin = new cafen.Div({className :'r-boxwhite', attribute:{}, style : {width:'200px'}});
		this.appendChild(this.tmpTableSkin);
		this._colorTable = new cafen.TableAuto({attribute:{border :0, width :'100%', cellpadding : 1, cellspacing:1}, style : {width : '100%'}});
		this.tmpTableSkin.appendChild(this._colorTable);
		for (var i =0 ; i < 8; i++) {
			this._colorTable.addRow();
			for (var j =0 ; j < 8; j++) {
				var cell = this._colorTable.addCell();
				cell.attachEvent('click',this.setColor.bind(this, i * 8 +j));
				cell.attachEvent('mouseover',this.showColor.bind(this, i * 8 +j));
				
				this._colorTable.addText('&nbsp;');
				this._colorTable.addStyle({textAlign:'center', width: '12.5%',cursor : 'hand', fontSize : '1px', height : '17px'});
			}
		}
		this._statusObj = new cafen.Div({style:{width:'90%', marginTop:'5px'}});
		this.appendChild(this._statusObj, 'bottom');
		this.setColorChart(0);
	},
	toggleHSV : function() {
		if (this._hsvObj == null) {
			this._hsvObj = new cafen.XColorpickerHSV({event :{end : this.setHSVColor.bind(this)}});
			this.appendChild(this._hsvObj);
			this._hsvObj.setColor(this.getColor());
		}
		if (!this._hsvObj._isShown) {
			this._tabObj.hide();
			this.tmpTableSkin.hide();
		}else {
			this._tabObj.show();
			this.tmpTableSkin.show();
		}
		this._hsvObj.toggleHSV();
	},
	setHSVColor : function(obj) {
		var incolor = obj.getColor();
		this._inputObj.setValue(incolor);
		this._previewObj.setStyle({backgroundColor: incolor});
	},
	setColorInput : function(obj) {
		var incolor = this._inputObj.getValue();
		if (cafen.find('^#[0-9a-fA-F]{6}$', incolor)) {
			this.setPreivew(incolor);
		} else  {
			this._inputObj.setError();
		}
	},
	setColorChart : function(no) {
		this._currentData = [];
		var currColor = this._chartBase[no].color;
		if (this._currColorIdx != null)
			this._chartBase[this._currColorIdx].obj.setSelected(false);
		this._chartBase[no].obj.setSelected(true);
		this._currColorIdx = no;
		for(var i = 0; i < 64; i++) {
			var row = Math.floor(i/8);
			var col = i % 8;
			var color = currColor[i];
			if (color != null) {
				this._currentData.push(color);
				this._colorTable.addStyle({backgroundColor :color},col, row);
			} else {
				this._currentData.push(null);
				this._colorTable.addStyle({backgroundColor :'transparent'},col, row);
			}
		}
	},
	setPreivew : function(color) {
		this._previewObj.setStyle({backgroundColor: color});
		if (this._hsvObj != null)
			this._hsvObj.setColor(color);
	},
	sendColor : function() {
		var incolor = this.getColor();
		if (cafen.find('^#[0-9a-fA-F]{6}$', incolor)) 
			this.sendValue(incolor);
		else
			this._inputObj.setError();
	},
	setColor : function(no) {
		if (typeof no == 'number') {
			if (this._currentData[no] != null) {
				var incolor = this._currentData[no].toUpperCase();
				this._inputObj.setValue(incolor);
				this.setPreivew(incolor);
				var row = Math.floor(no/8);
				var col = no % 8;
			}
			return true;
		} else {
			this._inputObj.setValue(no);
			this.setPreivew(no);
		}
	},
	showColor : function(no) {
		if (this._currentData[no] != null) {
			var incolor = this._currentData[no].toUpperCase();
			this._statusObj.getElement().innerHTML = incolor;
		}
		return true;
	},
	getColor : function () {
		return this._inputObj.getValue();
	}
},cafen.XWindow.prototype);



cafen.XColorpickerHSV = function(options) {
	this.setOptions(cafen.extend(options, {tag : 'div', className : 'r-boxwhite',attribute :{}, style : {width:'200px', textAlign:'center', height:'auto', overflow : 'hidden',position : 'relative'}}));
	this.initColorpicker();
}

cafen.XColorpickerHSV.prototype = cafen.extendClass({
	_colorSatValObj : null, 
	_cursorObj : null,
	_hueObj : null,
	_satObj : null,
	_briObj : null,
	_isShown : false,
	_currentHSV : null,
	initColorpicker : function() {
		var contentsObj = new cafen.TableAuto({attribute :{width:'100%', height:'auto', cellpadding: 3, align : 'center'}, style : {position : 'relative'}});
		this.appendChild(contentsObj);
		if (cafen.isPngAlphaSupport()) {
			this._colorSatValObj = new cafen.Div({align:'center', style :{
				margin:'5px',
				width:'170px',
				height:'170px',
				backgroundColor : '#FF0000',
				cursor:'crosshair',
				position : 'relative',
				backgroundImage : 'url('+_cafen_service_url+'images/SatVal.png)'
			}});
		} else {
			this._colorSatValObj = new cafen.Div({align:'center', style : {
				margin:'5px',
				width:'170px',
				height:'170px',
				textAlign: 'left',
				backgroundColor : '#FF0000',
				cursor:'crosshair',
				position : 'relative',
				filter : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+_cafen_service_url+"images/SatVal.png')"
			}});
		}
		this._colorSatValObj.attachEvent('click',this.setSVColor.bind(this));
		contentsObj.addRow();
		contentsObj.addCell(this._colorSatValObj);
		contentsObj.addStyle({textAlign:'center'});
		this._cursorObj = new cafen.XIcon({icon :'r-iconset', on : 0, off : 240, over : 15, style :{width:'15px', height:'15px', position:'absolute', left : '0px', top: '0px'}});
		this._colorSatValObj.appendChild(this._cursorObj);
		contentsObj.addRow();
		var hsvObj = new cafen.TableAuto({attribute :{width:'auto', height:'auto', cellpadding: 1}, style : {}});
		contentsObj.addCell(hsvObj);
		contentsObj.addStyle({textAlign:'center'});
		hsvObj.addCell();
		hsvObj.addStyle({textAlign:'right', fontSize :'12px', width: '30px'});
		hsvObj.addText('Hue:');
		this._hueObj = new cafen.Slider({size : 120, direct : 'X', event:{end : this.setHue.bind(this)}});
		hsvObj.addCell(this._hueObj);
		hsvObj.addStyle({textAlign:'left'});
		hsvObj.addRow();
		hsvObj.addCell();
		hsvObj.addStyle({textAlign:'right', fontSize :'12px'});
		hsvObj.addText('Sat:');
		this._satObj = new cafen.Slider({size : 120, direct : 'X', event:{end : this.setSat.bind(this)}});
		hsvObj.addCell(this._satObj);
		hsvObj.addStyle({textAlign:'left'});
		hsvObj.addRow();
		hsvObj.addCell();
		hsvObj.addStyle({textAlign:'right', fontSize :'12px'});
		hsvObj.addText('Bri:');
		this._briObj = new cafen.Slider({size : 120, direct : 'X', event:{end : this.setBri.bind(this)}});
		hsvObj.addCell(this._briObj);
		hsvObj.addStyle({textAlign:'left'});
	},
	toggleHSV : function() {
		this._isShown = ! this._isShown;
		if (this._isShown) { 
			this.show();
		} else {
			this.hide();
		}
	},
	setColor : function(color) {
		var rgb = this.hex2rgb(color);
		var hsv = this.rgb2hsv(rgb.r, rgb.g, rgb.b);
		this._currentHSV = hsv;
		var bgColor = this.hsv2hex(hsv.h, 100, 100);
		this._colorSatValObj.setStyle({backgroundColor : bgColor});
		var x = hsv.s /100*170;
		var y = (100 -hsv.v) /100*170;
		this._hueObj.setValue(this._currentHSV.h / 360 * 100);
		this._satObj.setValue(this._currentHSV.s);
		this._briObj.setValue(100 - this._currentHSV.v);
		this._cursorObj.setStyle({left: (x - 9) +'px', top : (y -9) +'px'});
	},
	updateHSV : function() {
		var bgColor = this.hsv2hex(this._currentHSV.h, 100, 100);
		this._colorSatValObj.setStyle({backgroundColor : bgColor});
		var x = this._currentHSV.s /100*170;
		var y = (100 -this._currentHSV.v) /100*170;
		this._cursorObj.setStyle({left: (x - 9) +'px', top : (y -9) +'px'});
		this.execEvent('end');
	},
	setHue : function(obj) {
		this._currentHSV.h = obj.getValue() * 360 /100;
		this.updateHSV();
	},
	setSat : function(obj) {
		this._currentHSV.s = obj.getValue();
		this.updateHSV();
	},
	setBri : function(obj) {
		this._currentHSV.v = 100 - obj.getValue();
		this.updateHSV();
	},
	setSVColor : function(obj, event) {
		var posPoint = cafen.pointer(event);
		var posObj = cafen.viewportOffset(obj.getElement());
		var x = Math.max(0,Math.min(170,(posPoint[0] - posObj[0])));
		var y = Math.max(0,Math.min(170,(posPoint[1] - posObj[1])));
		this._currentHSV.s = (x/170)*100; 
		this._currentHSV.v = (170-y)/170*100;
		this._cursorObj.setStyle({left: (x - 9) +'px', top : (y -9) +'px'});
		this.execEvent('end');
		return true;
	},
	getColor : function() {
		return this.hsv2hex(this._currentHSV.h, this._currentHSV.s, this._currentHSV.v);
	},
	checkHex : function(hex) {
		var m = '';
		if (m = hex.match(/#?([0-9a-f]{6}|[0-9a-f]{3})/i)) {
			if (m[1].length == 3) {
				m = m[1].match(/./g).findAll(function(c){return c+c});
			} else {
				m = m[1].match(/../g);
			}
			return '#'+m[0]+m[1]+m[2];
		} else
			return '';
	},
	hsv2hex : function(h,s,v) {
		var rgb = this.hsv2rgb(h,s,v);
		return this.rgb2hex(rgb.r,rgb.g,rgb.b);
	},
	rgb2hex : function(r, g, b) {
		r = r.toString(16); if (r.length==1) r = '0'+r;
		g = g.toString(16); if (g.length==1) g = '0'+g;
		b = b.toString(16); if (b.length==1) b = '0'+b;
		return '#' + r+g+b;
	},
	hex2rgb : function(hex) {
		hex = this.checkHex(hex);
		if (hex != '') {
			if (m = hex.match(/#?([0-9a-f]{6})/i))
				m = m[1];
			m = m.match(/../g);
			return {
				r : Number("0x" + m[0]),
				g : Number("0x" + m[1]),
				b : Number("0x" + m[2])
			}
		} else {
			return {
				r : Number("0xff"),
				g : Number("0xff"),
				b : Number("0xff")
			}
		}
	},
	rgb2hsv : function(r, g, b) {
		var max=Math.max(r,g,b);
		var delta=max-Math.min(r,g,b), H, S, V;
		if(max!=0) { 
			S=delta/max*100;
			if(r==max) 
				H=(g-b)/delta; 
			else if(g==max) 
				H=2+(b-r)/delta; 
			else if(b==max) 
				H=4+(r-g)/delta;
			var H=Math.min(H*60,360); 
			if(H<0) H+=360;
		}
		return {h:H?H:0,s:S?S:0,v:(max/255)*100};
	},
	hsv2rgb : function(h, s, v) {
		var R,B,G,S=s/100,V=v/100,H=h/360;
		if(S>0) { 
			if(H>=1) H=0;
			H=6*H; F=H-Math.floor(H);
			A=Math.round(255*V*(1.0-S));
			B=Math.round(255*V*(1.0-(S*F)));
			C=Math.round(255*V*(1.0-(S*(1.0-F))));
			V=Math.round(255*V); 
			switch(Math.floor(H)) {
				case 0: R=V; G=C; B=A; break;
				case 1: R=B; G=V; B=A; break;
				case 2: R=A; G=V; B=C; break;
				case 3: R=A; G=B; B=V; break;
				case 4: R=C; G=A; B=V; break;
				case 5: R=V; G=A; B=B; break;
			}
			return {r:R?R:0,g:G?G:0,b:B?B:0};
    	} else {
    		V=Math.round(V*255);
    		return {r:V,g:V,b:V};
    	}
	}
},cafen.Element.prototype);

cafen.XLayer = function(options) {
	this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r-btnskin', tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.setObject(options.childNode);
}

cafen.XLayer.prototype = cafen.extendClass({

},cafen.XWindow.prototype);



/**
 * xml 파싱 
 * @class xml 파싱 
 * @constructor 
 * @param {object} feed 대상 Feed
 */


cafen.xmlParser = function(feed) {
	this.initxmlParser(feed);	
};

cafen.xmlParser.prototype = {
	initxmlParser : function(feed) {
		var tmp_feed = null;
		if (typeof window.debug_mode != 'undefined' && window.debug_mode) {
			if (typeof feed == 'string')
				cafen.debugMessage(feed);
			else
				cafen.debugMessage(feed.responseText);
		}
		if (typeof feed != 'string' && typeof feed.isxmlhttp != 'undefined' && typeof feed.responseText != 'undefined') {
			feed = feed.responseText;
		}
		if (typeof feed == 'string') {
			if (typeof DOMParser != 'undefined')
				tmp_feed =  new DOMParser().parseFromString(feed, "text/xml");
			else {
				var xml = new window.ActiveXObject("Microsoft.XMLDOM");
				xml.async = "false";
				xml.loadXML(feed); 
				tmp_feed= xml;
			}
		} else {
			if (typeof DOMParser != 'undefined')
				tmp_feed =  new DOMParser().parseFromString(feed.responseText, 'text/xml');
			else {
				tmp_feed =  feed.responseXML;
			}
		}
		this.feed = tmp_feed;
		this.current_no = 0;
		try {
			var xml_channels = tmp_feed.documentElement.getElementsByTagName("channel");
		} catch(ex) {}
		this.channels = (xml_channels != null) ? xml_channels : [];
	},
	getChildNodes : function() {
		return new cafen.xmlParser.node(this.feed);
	},
/**
 * 채널 가져오기
 * @param {int} no 대상 순번
 * @return {cafen.xmlParser.Channel} cafen.xmlParser.Channel
 */
	getChannel : function(no) {
		if (this.channels.length > no) 
			return new cafen.xmlParser.Channel(this.channels[no]);
		else
			return null;
	},
/**
 * 다음채널 가져오기
 * @return {cafen.xmlParser.Channel} cafen.xmlParser.Channel
 */
	getNext : function() {
		var channel = this.getChannel(this.current_no);
		if (channel) {
			this.current_no++;
			return channel;
		} else 
			return null
	}
}

cafen.xmlParser.node = function(feed) {
	this.initNode(feed);	
};

cafen.xmlParser.node.prototype = {
	initNode : function(feed) {
		this.feed = feed;
	},
	getObject : function () {
		return this.feed;
	},
	getElements : function (name) {
		var objs = this.feed.getElementsByTagName(name);
		if (objs.length > 0) {
			var childNodes = [];
			for(var i = 0; i < objs.length; i++)
				childNodes.push(new cafen.xmlParser.node(objs[i]));
			return childNodes;
		} else
			return null;
	},
	getElement : function() {
		var obj = this.getObject();
		var len = (arguments.length -1);
		var seqn = 0 ;
		while(len >= seqn) {
			var nextTag = arguments[seqn];
			if (obj != null) {
				var objs = obj.getElementsByTagName(nextTag);
				if (objs.length > 0)
					obj = objs[0];
				else
					obj = null;
				seqn++;
			}
		}
		if (obj != null)
			return new cafen.xmlParser.node(obj);
		else
			return null;
	},
	getAttribute : function(name) {
		return this.feed.getAttribute(name);	
	},
	getInt : function(name) {
		return parseInt(this.getAttribute(name));
	},
	get : function(name) {
		return this.getAttribute(name);
	}
}

/**
 * xml 오류 채널
 * @class xml 오류 채널 통제
 * @constructor 
 * @param {object} options 오류 Object
 */
cafen.xmlParser.Error = function(options) {
	this.initError(options);	
};
cafen.xmlParser.Error.prototype = {
	options : {title : '', domain : '', contents : ''},
	initError : function(options) {
		this.options = cafen.extend(this.options, options);
	},
	getNext : function() {
		return null;
	},
	checkMsg : function() {
		return true;
	},
	getMsg : function() {
		return this.options;
	}
}

/**
 * xml 채널 통제
 * @class xml 채널 통제
 * @constructor 
 * @param {object} obj 대상 Channel
 * @param {object} items 대상 Item [강제 Item 설정시에만 사용]
 */
cafen.xmlParser.Channel = function(obj, items) {
	this.initChannel(obj, items);	
};
cafen.xmlParser.Channel.prototype = {
	initChannel : function(obj, items) {
		this.channel = obj;
		this.current_no = 0;
		if (items != null)
			this.items = items;
		else {
			this.items = [];
			for(var i = 0 ; i < obj.childNodes.length; i++)
				if (obj.childNodes[i].tagName == 'item')
					this.items.push(obj.childNodes[i]);
		}
	},
/**
 * 특정 조건을 만족하는 Item 가져오기
 * @param {function} func 조건 함수
 * @return {cafen.xmlParser.Channel}
 */
	findAll : function(func) {
		this.current_no = 0;
		var result = [];
		for(var i = 0; i < this.items.length; i++) {
			var item = new cafen.xmlParser.Channel(null,this.items[i]);
			if (func(item)) result.push(item);
		}
		return new cafen.xmlParser.Channel(null,result);
	},
/**
 * 특정 Node 명을 가진 첫번째 객체 가져오기
 * @param {object} nodeName Node 명
 * @return {object} node Object
 */
	getNode : function(nodeName) {
		var nodeValue = cafen.getFirstChildNode(this.channel,nodeName);
		return (nodeValue) ? nodeValue : '';
	},
/**
 * 특정 Node 명을 가진 첫번째 객체 가져오기
 * @param {object} nodeName Node 명
 * @return {object} node Object
 */
	getChannel : function(nodeName) {
		var nodeValue = cafen.getChildrenByTagName(this.channel,nodeName);
		if (nodeValue) 
			return new cafen.xmlParser.Channel(nodeValue);
		else 
			return null;
	},
/**
 * 메세지 여부 확인
 * @return {boolean}
 */
	checkMsg : function() {
		return (this.getNode('servermsg') == '') ? false : true;
	},
/**
 * 메세지 가져오기
 * @return {object} {title:제목, domain : 도메인 , contents : 메세지}
 */
	getMsg : function() {
		var msg = this.getNode('servermsg');
		var msginfo = msg.split('|');
		return {title : msginfo[0], domain : msginfo[1], contents : msginfo[2]}
	},
/**
 * 특정 번째의 Item 가져오기
 * @param {int} no 순번
 * @return {cafen.xmlParser.item}
 */
	getItem : function(no) {
		if (this.getItems().length > no) 
			return new cafen.xmlParser.Channel(this.items[no]);
		else
			return null
	},
/**
 * 다음 Item 가져오기
 * @return {cafen.xmlParser.item}
 */
	getNext : function() {
		var item = this.getItem(this.current_no);
		if (item) {
			this.current_no++;
			return item;
		} else 
			return null
	},
/**
 * 전체 Item 가져오기
 * @return {array}
 */
	getItems : function() {
		return this.items;
	},
/**
 * 페이지 정보 가져오기
 * @param {int} current_no 현재 번호
 * @param {int} ppage 페이지당 표시수
 * @return {object} {cline : 현재번호,total : 전체수,page : 현재페이지,pages : 전체페이지,start : 시작 시점,end : 마지막시점}
 */
	getPage : function (current_no, ppage) {
		if (current_no != undefined) 
			this.current_no = current_no;
		else 
			current_no = this.current_no;
		var total = this.getItems().length;
		if (current_no > total) 
			this.current_no = current_no = total;
		var start_line = (total > current_no)?current_no:0;
		var end_line = (total > start_line + ppage)?start_line + ppage:total;
		var curr_page = parseInt(start_line/ppage) + 1;
		var total_page = Math.ceil(total/ppage);
		return {
			cline : current_no,
			total : total,
			page : curr_page,
			pages : total_page,
			start : start_line,
			end : end_line
		}
	},
/**
 * 현재 channel 을 Object 형으로 가져오기
 * @return {object} Object
 */
	getObject : function() {
		var result_obj = null;
		var rsstype = this.getNode('rsstype');
		var description = this.getNode('description');
		switch(rsstype) {
			case 'html' : 	
			case 'text' : 	
				result_obj = document.createElement('div');
				this.setStyle(result_obj, {width:'100%',border:'1px solid #464646',padding:'3px'});
				if (rsstype == 'html')
					result_obj.innerHTML = description
				else {
					description = description.replace(/\r/g, '');
					description = description.replace(/\n/g, '<br>');
					result_obj.innerHTML = description;
				}
				break;
			case 'object' : 	
					try {
						eval('var testevalfunc = function(){' +description+ '} ');
						result_obj = testevalfunc();
					} catch(ex) {}
				break;
				
		}
		return result_obj;
	}
}


cafen.Ajax_basexmlurl = '/BLOGJS/UPLOAD_SRC/upload_fileswf.php';

/**
 * Ajax 통신
 * @class Ajax 통신
 * @constructor 
 * @param {object} send_data 전송할 데이타 {}
 * @param {function} call_back 전송완료시 호출 함수
 * @param {string} base_url 호출 프로그램 URL
 * @param {string} xml_method 호출 Method [get|post]
 */
cafen.Ajax = function(send_data, call_back, base_url, xml_method) {
	this.initAjax(send_data, call_back, base_url, xml_method);
};

cafen.Ajax.prototype = {
	initAjax : function(send_data, call_back, base_url, xml_method) {
		try {		
		if (typeof send_data.domain == 'undefined')
			send_data.domain = document.domain;
		} catch(ex) {}
		if (xml_method == undefined)
			xml_method = 'post';
		if (typeof base_url == 'undefined' || base_url == null || base_url == '') 
			base_url = cafen.Ajax_basexmlurl;
		this.base_url = base_url;
		if (typeof call_back == 'function') {
			this.call_back  = call_back;
			this.obj = new cafenAjax.Ajax(base_url, {params :send_data, method : xml_method, onLoad : this.onComplete.bind(this), onError: this.onFailure.bind(this)});
		} else {

		}
	},
/**
 * 완료
 * @param {object} response 호출 결과
 */
	onComplete : function(response) {
		var channel, xml = new cafen.xmlParser(response);
		if (channel = xml.getNext()) {
				this.call_back(channel);
		} else {
			this.onFailure({status:-1});
		}
	},
/**
 * 실패
 * @param {object} transport Transport
 * @param {object} json Json
 */
	onFailure : function(transport, json) {
		var msg = '';
		if (transport.status == null)
			return ;
		switch(transport.status) {
			case 404 : 
				msg = cafenMsg.get('util_0045');
				break;
			case -1 :
				msg = cafenMsg.get('util_0046');
				break;
			default :
				msg = cafenMsg.get('util_0047') + transport.status;
				break;
		}
		this.call_back(new cafen.xmlParser.Error({title : cafenMsg.get('util_0048'), domain : this.base_url , contents : msg}));
	}
}

cafen.Attribute = function(obj) {
	this.obj = obj;
	try {
		this.nodeName = (typeof this.obj.nodeName != 'undefined') ? this.obj.nodeName : null;
	} catch(ex) {
		this.nodeName = null;
	}
}

cafen.Attribute.prototype = {
/**
 * The target Object
 * @type object
 */
	obj : null,
/**
 * The node name of current Object
 * @type string
 */
	nodeName : null,
/**
 * get String Attribute from Object
 * @param {string} key The key value of Attribute
 * @param {string} def The default value of Attribute, If the Attribute is null, the Def will by returned
 * @return {string}
 */
	getString : function(key, def) {
		if (def == null) def = '';
		if (typeof def != 'string') def = '' + def;
		var value =  (this.obj.getAttribute) ?  this.obj.getAttribute(key) : def;
		if (value == null)
			value = '';
		return (value == '') ? def : value;
	},
/**
 * alias if getString
 * @param {string} key The key value of Attribute
 * @param {string} def The default value of Attribute, If the Attribute is null, the Def will by returned
 * @return {string}
 */
	get : function(key, def) {
		return this.getString(key, def);
	},
/**
 * get Int Attribute from Object
 * @param {string} key The key value of Attribute
 * @param {string} def The default value of Attribute, If the Attribute is null, the Def will by returned
 * @return {int}
 */
	getInt : function(key, def) {
		return parseInt(this.get(key, def));
	},
/**
 * get Float Attribute from Object
 * @param {string} key The key value of Attribute
 * @param {string} def The default value of Attribute, If the Attribute is null, the Def will by returned
 * @return {float}
 */
	getFloat : function(key, def) {
		return parseFloat(this.get(key, def));
	},
/**
 * get Boolean Attribute from Object
 * @param {string} key The key value of Attribute
 * @param {string} def The default value of Attribute, If the Attribute is null, the Def will by returned
 * @return {boolean}
 */
	getBoolean : function(key, def) {
		var val = this.get(key, def);
		if (val == 'null')
			return null;
		else
			return (val.toLowerCase() == 'true' || val == '1') ? true : false;
	},
/**
 * get Array Attribute from Object
 * @param {string} key The key value of Attribute
 * @return {boolean}
 */
	getArray : function(key) {
		var val = this.get(key);
		return val.split(',');
	},
/**
 * get the current Object is Node or not
 * @return {boolean}
 */
	isNode : function() {
		return (this.nodeName != null && this.nodeName != '#text') ? true : false;
	},
/**
 * get the innerHTML of current Object 
 * @return {string}
 */
	getText : function() {
		try {
			return (cafen.browser.isIE) ? this.obj.innerText : this.obj.innerHTML.replace(/<[^>]+>/g,''); 
		} catch(ex) {
			return '';
		}
	},
/**
 * get the first Element data Attribute by given tag
 * @param {string} key The key value of Attribute
 * @return {boolean}
 */
	getFirstChildByTagName:function(key) {
		var childobj = this.obj.getElementsByTagName(key);
		if (childobj.length > 0)
			return childobj[0].getAttribute('data');
		else
			return '';
	},
/**
 * get the child nodes of current Object
 * @return {array}
 */
	getChildNodes : function() {
		var childs = [];
		for(var i = 0; i < this.obj.childNodes.length; i++) {
			if (this.obj.childNodes[i].nodeType == 1) {
				var child = new cafen.Attribute(this.obj.childNodes[i]);
				if (child.isNode())
					childs.push(child);
			}
		}
		return childs;
	}
}


var cafenAjax = {
	onLoadObject : [],
	isReady : false,
	movieName : null,
	settings : {
		flash_url : _cafen_service_url+'images/cafenajax.swf',
		flash_color : '#FFFFFF',
		debug : false
	},
	initFlash : function(flash_url, jsonData, debug) {
		this.isReady = false;		
		if(flash_url != null) 
			this.settings.flash_url =flash_url ;
		if(debug != null) 
			this.settings.debug = debug ;
		this.movieName = 'tmpSwf'+(new Date).getMilliseconds()+Math.floor(Math.random()*100000);
		if ( jsonData != null)
			this.addOnReady( jsonData);
		this.drawFlash();
	},
	drawFlash : function() {
		var targetElement = document.getElementById('_cafenAjaxDiv');
		if (targetElement != null) {
			targetElement.innerHTML = this.getFlashHTML();
		} else {
			targetElement = document.getElementsByTagName("body")[0];
			var container = document.createElement("div");
			container.style.width = "1px";
			container.style.height = "1px";
			targetElement.appendChild(container);
			container.innerHTML = this.getFlashHTML();
		}
	},
	getFlashVars : function() {
		var flashvars = [];
		flashvars.push('flashReady=' + encodeURIComponent('cafenAjax.onReady'));
		flashvars.push('debugEnabled=' + ((this.settings.debug) ?'true':'false'));
		if (this.settings.debug)
			flashvars.push('debugCallback=' +encodeURIComponent('cafen.debugMessage'));
		return flashvars.join('&amp;');
	},
	getFlashHTML : function () {
		return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="1" height="1" style="-moz-user-focus: ignore;">',
					'<param name="movie" value="', this.settings.flash_url, '" />',
					'<param name="bgcolor" value="', this.settings.flash_color, '" />',
					'<param name="quality" value="high" />',
					'<param name="menu" value="false" />',
					'<param name="allowScriptAccess" value="always" />',
					'<param name="flashvars" value="' + this.getFlashVars() + '" />',
					'</object>'].join("");
	},
	onReady : function() {
		this.isReady = true;
		for (var i = 0; i < this.onLoadObject.length; i++)
			this.getFlash().setObject(this.onLoadObject[i]);
	},
	setRequest : function(obj) {
		if (this.isReady) {
			this.getFlash().setObject(obj);
		} else {
			this.addOnReady(obj);	
			if (this.movieName == null)
				this.initFlash(null, null, (typeof window.debug_mode != 'undefined' && window.debug_mode));
		}	
	},
	addOnReady : function( jsonData) {
		this.onLoadObject.push( jsonData);
	},
	getFlash : function() {
		return document.getElementById(this.movieName);
	},
	obj2json : function(obj) {
		switch (typeof obj) {
			case 'boolean':
			case 'number':
				return '"' + obj.toString() + '"';
				break;
			case 'string':
				return '"' + obj + '"';
				break;
			case 'object':
				if (obj === null) return 'null';
				if (obj instanceof Function) return this.obj2json(obj());
				if (obj instanceof Array) {
					var a = new Array;
					for(var i=0; i < obj.length; i++) {
						a.push(this.obj2json(obj[i]));
					};
					return '['+a.join(',')+']';
				}
				if (obj instanceof Object) {
					var a = new Array;
					for(var objkey in obj) {
						var objvalue = obj[objkey];
						if (objvalue instanceof Function) objvalue = objvalue();
						a.push(this.obj2json(objkey)+':'+this.obj2json(objvalue));
					};
					return '{'+a.join(',')+'}';
				}
				break;
			case 'undefined':
			default:
				return '""';
				break;
		}
	}
}

cafenAjax.Ajax = function(theURL) {
	this.options = cafen.extend({
		method   : 'GET',
		async    : true,
		interval : 0,
		params   : null,
		suspend  : false,
		charset  : 'utf-8',
		preventCache     : false,
		ignoreWhiteSpace : false,
		contentType : 'application/x-www-form-urlencoded',
		headers : {},
		onLoad  : function(req){},
		onError : function(){}
	}, arguments[1]||{});
	this._url = theURL;
	var domain = String(document.location.href).match(/https?:\/\/([a-z0-9_\-\.]+)/i)[1];
	if (!(/^https?:\/\//i.test(theURL))) this._crossDom = false;
	else this._crossDom = !(new RegExp("^https?://"+domain+"(:[0-9]+)?(?:/|$)","i")).test(theURL);
	this._request  = this._getXMLHTTP();
	this._headers = this.options.headers;
	if (!this.options.suspend) 
		this.request();
}

cafenAjax.Ajax.prototype = {
	_url : '',
	_request  : null,
	_response : null,
	_headers  : {},
	_crossDom : false, 
	_loaded   : false,
	_getXMLHTTP : function() {
		if (this._crossDom) {
			return new cafenAjax.swfHTTPRequest();
		} else if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if (ActiveXObject) {
			try { return new ActiveXObject('MSXML2.XMLHTTP'); }
			catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
			return null;
		}
	},
	_onReadyStateChange : function() {
		if (this._request.readyState == 4 && !this._loaded) {
			this._loaded = true;
			if (this._request.responseXML != null ||this._request.responseText != null)
				this.options.onLoad(this._request);
			else
				this.options.onError({status:404});
			if(this.options.interval > 0) {
				this._timer = setTimeout(this.request.bind(this), this.options.interval*1000);
			}
		}
	},
	_getData : function() {
		var i, a = [], t=this;
		for(var pkey in this.options.params) 
			a.push(pkey+'='+encodeURIComponent(this.options.params[pkey]));
		return a.join('&');
	},
	request : function() {
		var o = this.options;
		var m = o.method.toUpperCase();
//		o.method = m;
		o.method = 'POST';
		var req = this._request;
		if (this._crossDom) req.charset = this.options.charset;
		req.open(o.method, this._url, o.async);
		req.setRequestHeader('Content-Type', o.contentType+'; charset=utf-8');
		req.setRequestHeader('charset', 'utf-8');
		for (var x in this._headers) {
			if(this._headers.propertyIsEnumerable && typeof(this._headers[x]) != 'function') {
				req.setRequestHeader(x, this._headers[x]);
			}
		}
		if (typeof req.onload != 'undefined') {
			req.onload = this._onReadyStateChange.bind(this);
		} else {
			req.onreadystatechange = this._onReadyStateChange.bind(this);
		}
		this._loaded = false;
		req.send(this._getData());
	},
	abort : function() {
		this._request.abort();
	},
	setRequestHeader : function(key, val) {
		this._headers[key] = val;
	},
	getResponseHeader : function(key) {
		return this._request.getResponseHeader(key);
	}
};


cafenAjax.swfHTTPRequest = function( ) {
	this._tmpId = 'tmpSwf'+(new Date).getMilliseconds()+Math.floor(Math.random()*100000);
}

cafenAjax.swfHTTPRequest.prototype = {
	_url     : '',
	_method  : 'GET',
	_headers : {},
	charset  : 'utf-8',
	readyState  : 1,
	responseText : '',
	onreadystatechange : function(){},
	_onLoad : function(success, data) {
		if (success &&  typeof data != 'undefined') {
			this.responseText = decodeURIComponent(data);
			this.responseXML = null;
			try {
				this.responseXML = this._parseXML(this.responseText);
			} catch(e){}
			this.readyState = 4;
			this.onreadystatechange();
		} else {
			this.responseText = '';
			this.responseXML = null;
			this.readyState = 4;
			this.onreadystatechange();
		}
	},
	_parseXML : function(xmlStr) {
		var xdoc = null;
		try {
			xdoc = new ActiveXObject("Microsoft.XMLDOM");
			xdoc.async = "false";
			xdoc.loadXML(xmlStr);
		} catch(e) {
			var parser = new DOMParser();
			xdoc=parser.parseFromString(xmlStr,"text/xml");
		}
		return xdoc;
	},
	abort : function() {},
	open : function(method, url) {
		this._method = method;
		this._url    = url;
	},
	send : function(data) {
		var t   = this;
		var dat = {}, key, val, pos;
		var swf = cafenAjax.getFlash();
		data = (data || '').split(/&/);
		for(var i=0; i < data.length; i++) {
			pos = data[i].indexOf('=');
			key = data[i].substring(0,pos);
			val = data[i].substring(pos+1);
			dat[key] = decodeURIComponent(val);
		}
		cafenAjax.swfHTTPRequest['callback_'+this._tmpId] = function() {
			t._onLoad.apply(t,arguments);
		};
		cafenAjax.setRequest({
				'url'  : this._url,
				'type' : this._method,
				'data' : dat,
				'charset' : this.charset.toUpperCase(),
				'callback'     : 'cafenAjax.swfHTTPRequest.callback_'+this._tmpId,
				'headers_json' : this._headers
		});
	},
	setRequestHeader : function(key, val) {
		this._headers[key] = val;
	},
	getResponseHeader : function(key) {
		return '';
	}
};


cafen.smallSWFAjax = {
	ajaxOnLoad : [],
	isunderRequest : false,
	getTranslate : function(str, lng, callback) {
		this.last_transcallBack = callback;
		var dat = {
			'v' : '1.0',
			'q' : str,
			'format' : 'html',
			'langpair' : '|' + lng	
		}
		cafenAjax.setRequest({
				'url'  : 'http://ajax.googleapis.com/ajax/services/language/translate',
				'type' : 'get',
				'data' : dat,
				'charset' : 'UTF-8',
				'callback'     : 'cafen.smallSWFAjax.setTranslate'
		});
	},
	setTranslate : function(success, data) {
		var result = {translation: null, error : null}
		var responseText = '';
		if (success &&  typeof data != 'undefined') {
			responseText = decodeURIComponent(data);
			var json = cafen.getString2Json(responseText);
			if ( json.responseStatus && json.responseStatus == 200) {
				if ( json.responseData) {
					if ( json.responseData.translatedText) 
						result.translation = json.responseData.translatedText;
					if ( json.responseData.detectedSourceLanguage) 
						result.language = json.responseData.detectedSourceLanguage;
				} else {
					result.error = {message : 'unknown'}	
					if ( json.responseDetails) 
						result.error.message = json.responseDetails;
				}
			} else {
				result.error = {message : 'unknown'}	
				if ( json.responseDetails) 
					result.error.message = json.responseDetails;
			}
		} else {
			result.error = {message : 'connection fail'}	
		} 
		this.last_transcallBack(result);
	},
	getFlashXml : function(dat, callBack, theURL, useProxy) {
		if (useProxy == null)
			useProxy = false;
		if (!this.isunderRequest) {
			this.last_callBack = callBack;
			this.isunderRequest = true;
			if (useProxy == null || useProxy != false) {
				cafenAjax.setRequest({
						'url'  :  cafenGlobalConf.httpproxy,
						'type' : 'post',
						'data' : {url : theURL +'?'+ cafen.getQueryString(dat),domain : cafen.getDomain()},
						'charset' : 'UTF-8',
						'callback'     : 'cafen.smallSWFAjax.onloadXML'
					});
			} else {
				var domain = String(document.location.href).match(/https?:\/\/([a-z0-9_\-\.]+)/i)[1];
				if (!(/^https?:\/\//i.test(theURL))) 
					this._crossDom = false;
				else 
					this._crossDom = !(new RegExp("^https?://"+domain+"(:[0-9]+)?(?:/|$)","i")).test(theURL);
				if (!this._crossDom) {
					new cafenAjax.Ajax(theURL, {params :dat, method : 'get', onLoad : this.onloadHTML.bind(this)});
					this.isunderRequest = false;
				} else {
					cafenAjax.setRequest({
							'url'  :  theURL,
							'type' : 'get',
							'data' : dat,
							'charset' : 'UTF-8',
							'callback'     : 'cafen.smallSWFAjax.onloadXML'
						});
				}
			}
		} else {
			this.ajaxOnLoad.push({data : dat, callBack: callBack, URL: theURL, useProxy : useProxy });
		}
	},
	onloadHTML : function(channel) {
		this.last_callBack(channel.responseText);
	},
	onloadXML : function(success, data) {
		var responseText = null;
		if (success &&  typeof data != 'undefined') {
			if (typeof data == 'string') 
				responseText = decodeURIComponent(data);
			else
				responseText = data;
		} 
		this.isunderRequest = false;
		this.last_callBack(responseText);
		if (this.ajaxOnLoad.length > 0) {
			var currObj  = this.ajaxOnLoad[0];
			this.ajaxOnLoad.shift();
			this.getFlashXml(currObj.data, currObj.callBack, currObj.URL, currObj.useProxy);	
		}
	}
}

cafen.JQueryObject = function(selector, context) {
	context = context || document;
	if (typeof selector == 'object')
		return [selector];
	var findObj = [];
	var selectors = selector.split(' ');
	var selectorArr = selectors[0].split(':');
	var currSelector = selectorArr[0];
	if (currSelector.indexOf('#') == 0) {
		var id = currSelector.slice(1);
		var childObjs = (context instanceof Array) ? context  : cafen.getElementsByTagName("*");
		for(var j = 0; j < childObjs.length; j++) 
			if(childObjs[j].id==id) 
				findObj.push(childObjs[j]);
	} else if (currSelector.indexOf('.') == 0) {
		var className = currSelector.slice(1);
		var childObjs = (context instanceof Array) ? context  : cafen.getElementsByTagName("*");
		for(var j = 0; j < childObjs.length; j++) {
			if (childObjs[j].className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) 
				findObj.push(childObjs[j]);
		}
	} else {
		if (context instanceof Array) {
			for(var j = 0; j < context.length; j++) 
				if (context[j].tagName == currSelector)
					findObj.push(context[j]);
		} else {
			var childObjs = context.getElementsByTagName(currSelector);
			for(var j = 0; j < childObjs.length; j++) 
				findObj.push(childObjs[j]);
		}
	}
	if (findObj.length > 0) {
		switch(selectorArr[1]) {
			case 'first' :
				findObj = [findObj[0]];
				break;
			case 'last' :
				findObj = [findObj[findObj.length-1]];
				break;
			case 'even' :
				var childs = findObj;
				findObj = [];
				for(var i = 0 ;  i < childs.length; i++) 
					if (i % 2 == 0)
						findObj.push(childs[i]);
				break;
			case 'odd' :
				var childs = findObj;
				findObj = [];
				for(var i = 0 ;  i < childs.length; i++) 
					if (i % 2 == 1)
						findObj.push(childs[i]);
				break;
			case 'first-child' :
				var childs = findObj;
				findObj = [];
				for(var i = 0 ;  i < childs.length; i++) {
					if (	childs[i].childNodes.length > 0)
						findObj.push(childs[i].childNodes[0]);
				}
			case 'last-child' :
				var childs = findObj;
				findObj = [];
				for(var i = 0 ;  i < childs.length; i++) {
					if (	childs[i].childNodes.length > 0)
						findObj.push(childs[i].childNodes[childs[i].childNodes.length-1]);
				}
				break;
			default :
				if (selectorArr[1] != null && selectorArr[1] != '') {
					var reg = [];
					if (reg = cafen.find('eq\\(([0-9]+)\\)', selectorArr[1])) {
						var idx = parseInt(reg[1]);
						var childs = findObj;
						findObj = [];
						if ((childs.length - 1) >= idx)
							findObj.push(childs[idx]);
					} else if (reg = cafen.find('lt\\(([0-9]+)\\)', selectorArr[1])) {
						var idx = parseInt(reg[1]);
						var childs = findObj;
						findObj = [];
						for(var i = 0 ;  i < childs.length; i++) 
							if (	i < idx)
								findObj.push(childs[i]);
							else
								break;
					} else if (reg = cafen.find('gt\\(([0-9]+)\\)', selectorArr[1])) {
						var idx = parseInt(reg[1]);
						var childs = findObj;
						findObj = [];
						for(var i = 0 ;  i < childs.length; i++) 
							if (	i > idx)
								findObj.push(childs[i]);
					}
				}
				break;
		}
		selectors.shift();
		if (selectors.length > 0) 
			findObj = this.JQueryObject(selectors.join(' '), findObj);
	}
	return findObj;
}


cafen.J$ = function (ids) {
	return new cafen.JQuery(this.JQueryObject(ids));
}

cafen.JQuery = function(objs) {
	this._Objects = objs;
	this.length = this._Objects.length;
	this.eventQueues = {};
}

cafen.JQuery.prototype = {
	length : 0,
	size : function() {
		return this.length;
	},
	cafenEditor : function() {
		var editorObj = new cafenEditor();
		editorObj.renderElements(this._Objects);
		return this;
	},
	cafenPreview : function() {
		var editorObj = new cafenPreview();
		editorObj.renderElements(this._Objects);
		return this;
	},
	cafenAttach : function() {
		var attachObj = new cafenAttach();
		attachObj.renderElements(this._Objects);
		return this;
	},
	ofc2js : function() {
		var ofc2jsObj = new cafenOFC2JS();
		ofc2jsObj.renderElements(this._Objects);
		return this;
	},
	cafenAttach : function() {
		var attachObj = new cafenAttach();
		attachObj.renderElements(this._Objects);
		return this;
	},
	cafenMap : function() {
		var mapObj = new cafenMap();
		mapObj.renderElements(this._Objects);
		return this;
	},
	cafenFolder : function() {
		for(var i =0; i < this._Objects.length; i++) {
			var menus = this.getFolderAttribute(cafen.C$(this._Objects[i],'li'));
			var attrib = new cafen.Attribute(this._Objects[i]);
			var baseWidth = attrib.getInt('width', 200);
			var baseHeight = attrib.getInt('height', 0);
			var tmpObj = new cafen.Div({className : attrib.get('cafenclass', ''), tplName : attrib.get('tpl', ''), shadow : attrib.getBoolean('shadow', false) ,style:{width : baseWidth +'px',height : (baseHeight > 0) ? baseHeight + 'px' : 'auto',overflowY : 'auto'}});
			if (attrib.get('tpl', '') == 'top')
				tmpObj.appendChild(attrib.get('title', ''),'top');  
			var xfolder = new cafen.XFolder(
				menus, 
				{
					onclick : cafen.getString2Function(attrib.get('ondone', '')), 
					useanimate : attrib.getBoolean('animate', true),
					style : {width : 	baseWidth +'px'}
				}
			);
			tmpObj.appendChild(xfolder);
			this._Objects[i].parentNode.insertBefore(tmpObj.getObject(),this._Objects[i]);
			this._Objects[i].openClose = xfolder.openClose.bind(xfolder);
		}

		this.hide();
		return this;
	},
	getFolderAttribute : function(objs) {
		if (objs.length > 0 ) {
			var resultArr = [];
			for(var i = 0; i < objs.length; i++ ) {
				var currObj = objs[i];
				var text = (currObj.childNodes.length > 0 ) ? currObj.childNodes[0].nodeValue : currObj.innerText;
				resultArr.push({
					text : text,
					type : currObj.getAttribute('icon') || null,
					id : currObj.getAttribute('id') || '',
					onclick :cafen.getString2Function(currObj.getAttribute('ondone')) ,
					items : this.getFolderAttribute(cafen.C$(currObj,'ul li'))
				});
			}
			return resultArr;
		} else 
			return [];
	},
	cafenRender : function() {
		for(var i =0; i < this._Objects.length; i++) 
			cafen.renderElement(this._Objects[i]);
		return this;
	},
	syntaxHighlighter : function(options) {
		var syntaxObj = new cafenSyntaxHighlighter();
		syntaxObj.renderElements(this._Objects);
		return this;
	},
	cafenGraph : function() {
		var graphObj = new cafenGraph();
		graphObj.renderElements(this._Objects);
		return this;
	},
	colorPicker : function(options) {
		options = options || {x : 'right', y : 'top'}
		for(var i =0; i < this._Objects.length; i++) {
			var obj = this._Objects[i];
			obj.linkObj = obj.getAttribute('linkObj') ? cafen.$(obj.getAttribute('linkObj')) : obj;
			obj.setColor = function (val) {
				if (this.linkObj.tagName == 'INPUT')
					this.linkObj.value = val;
				else 
					this.linkObj.style.backgroundColor = val;
			}
			obj.onclick = function() {
				if (this.colorPicker == null) 
					this.colorPicker = new cafen.XColorpicker({title : 'ColorPicker', sticker : {obj : this, x : options.x, y : options.y}, onClose : this.setColor.bind(this)});
				if (this.linkObj.tagName == 'INPUT')
					this.colorPicker.setColor(this.linkObj.value);
				else 
					this.colorPicker.setColor(this.linkObj.style.backgroundColor);
				this.colorPicker.onLoad();
			}
		}
		return this;
	},
	datePicker : function(options) {
		options = options || {x : 'right', y : 'top'}
		for(var i =0; i < this._Objects.length; i++) {
			var obj = this._Objects[i];
			obj.linkObj = obj.getAttribute('linkObj') ? cafen.$(obj.getAttribute('linkObj')) : obj;
			obj.setDate = function (val) {
				if (this.linkObj.tagName == 'INPUT')
					this.linkObj.value = val;
				else 
					this.linkObj.innerHTML = val;
			}
			obj.onclick = function() {
				if (this.calPicker == null) 
					this.calPicker = new cafen.XCalendar({title : 'Calendar', sticker : {obj : this , x : options.x, y : options.y}, onClose : this.setDate.bind(this)});
				if (this.linkObj.tagName == 'INPUT')
					this.calPicker.setDate(this.linkObj.value);
				else
					this.calPicker.setDate(this.linkObj.innerHTML);
				this.calPicker.onLoad();
			}
		}
		return this;
	},
	mapPicker : function(options) {
		options = options || {x : 'right', y : 'top'}
		for(var i =0; i < this._Objects.length; i++) {
			var obj = this._Object[i];
			obj.setMap = function (mapObj) {
				var linkObj = obj.linkObj ? cafen.$(obj.linkObj) : obj;
				mapObj.close();
				var val =mapObj.getMap();
				if (linkObj.tagName == 'IMG')
					linkObj.src = val;
				else if (linkObj.tagName == 'INPUT')
					linkObj.value = val;
				else 
					linkObj.innerHTML = val;
			}
			obj.onclick = function() {
				if (obj.mapPicker == null) 
					obj.mapPicker = new cafen.XMapViewer({style : {width:'600px', height : '300px'}, event :{done : obj.setMap}, sticker : {obj : obj , x : options.x, y : options.y}});
				var linkObj = obj.linkObj ? cafen.$(obj.linkObj) : obj;
				if (linkObj.tagName == 'IMG') 
					obj.mapPicker.setMap(linkObj.src);
				else if (linkObj.tagName == 'INPUT') 
					obj.mapPicker.setMap(linkObj.value);
				else
					obj.mapPicker.setMap(linkObj.innerHTML);
				obj.mapPicker.onLoad();
			}
		}
		return this;
	},
	get : function(idx, sel) {
		return cafen.J$(sel || null , this._Objects[idx]);
	},
	eventQueues : {}, 
	css : function(style) {
		for(var i =0; i < this._Objects.length; i++) {
			for(var name in style) {
				if (name == 'opacity')
					this.setOpacity(this._Objects[i],style[name]);
				else
					this._Objects[i].style[name] = style[name];
			}
		}	
		return this;
	},
	setOpacity : function(element, opa) {
		if (document.all) {
			element.style.filter = "alpha(opacity = "+opa+"%)";
		 }else 
			element.style.opacity =  opa/100;
	},
	doEvent : function(eventName, obj) {
		if (this.eventQueues[eventName] != null)
			this.eventQueues[eventName](obj);
	},
	attachEvent : function(name , event) {
		if (this.eventQueues[name] == null) {
			for(var i =0; i < this._Objects.length; i++) 
				cafen.Event.observe(this._Objects[i], name , this.doEvent.bind(this,name, this._Objects[i]));
		}
		this.eventQueues[name] = event;
		return this;
	},
	attr : function (attributes) {
		for(var i =0; i < this._Objects.length; i++) {
			for(var name in attributes)
			this._Objects.setAttribute(name, attributes[name]);
		}
	},
	animateStopProp : {},
	animateCallBack : null,
	animateSpeed : 100,
	animate: function( prop, speed, callback ) {
		this.animateStopProp = prop;
		this.animateSpeed = speed;
		this.animateCallBack = callback;
		for(var name in prop) {
			switch(name) {
				default :
					this.animateStart(name, prop[name] > 1 ? 1 : 100 , prop[name]);
					break;
			}
		}
	},
	animateStart : function(proP, value, end) {
		var styles = {};
		switch(proP) {
			case 'top' :
			case 'left' :
			case 'height' :
			case 'width' :
				styles[proP] = value +'px';
				break;
			case 'opacity' :
				styles[proP] = value;
				break;
		}
		for(var i =0; i < this._Objects.length; i++) 
			this.css(styles);
		if (value != end) {
			if (value > end) 
				window.setTimeout(this.animateStart.bind(this, proP, value - Math.round(Math.max(1,(value - end)/2)) , end), this.animateSpeed);
			else {
				window.setTimeout(this.animateStart.bind(this, proP, value + Math.round(Math.max(1,(end - value)/2)) , end), this.animateSpeed);
			}
		} else if (this.animateCallBack != null) {
			this.animateStopProp[proP] = null;
			var checkAllAni = true;
			for (var name in this.animateStopProp) {
				if (this.animateStopProp[name] != null) {
					checkAllAni = false;
					break;
				}
			}
			if (checkAllAni) 
				this.animateCallBack();
		}
	},
	click : function(event) {
		this.attachEvent('click', event);
		return this;
	},
	mouseOver : function(event) {
		this.attachEvent('mouseover', event);
		return this;
	},
	mouseOut : function(event) {
		this.attachEvent('mouseout', event);
		return this;
	},
	show : function() {
		this.css({display:'block'});
		return this;
	},
	hide : function() {
		this.css({display:'none'});
		return this;
	}
}


cafen.smartLoad = function() {}

cafen.smartLoad.prototype = {
	params : null,
	script_url : '',
	renderObjs : [],
	checkLoad : function() {
		return true;	
	},
	getScript : function() {
		return this.script_url;
	},
	setParam : function(params) {
		this.params = params;
		cafen.load(this);
	},
	renderElement : function(obj) {
		this.renderObjs.push(obj);
		if (this.renderObjs.length == 1)
			cafen.load(this);
	},
	renderElementsByClassName : function(className) {
		var objs = cafen.getElementsByTagName('*');
		var renderObjs = [];
		for(var i =0; i < objs.length; i++) {
			var child = objs[i];
			if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) 
				renderObjs.push(child);
		}
		this.renderElements(renderObjs);
	},
	renderElements : function(elements) {
		this.renderObjs = elements;
		if (this.renderObjs.length > 0)
			cafen.load(this);
	},
	renderElementsById : function(id) {
		if (document.getElementById(id) != null) {
			var renderObjs = [];
			var objs = document.getElementsByTagName(document.getElementById(id).tagName);
			for(var i=0;i<objs.length;i++){
				if(objs[i].id==id) 
					renderObjs.push(objs[i]);
			}
			this.renderElements(renderObjs);
		}
	},
	renderElementsByName : function(objName) {
		var objs = cafen.getElementsByTagName('*');
		var renderObjs = [];
		for(var i =0; i < objs.length; i++) {
			var child = objs[i];
			if (child.getAttribute('name') == objName) 
				renderObjs.push(child);
		}
		this.renderElements(renderObjs);
	}
}

if (typeof cafen.Editor == 'undefined') {
	cafen.Editor = function() {
		this.setParam(arguments);
	}
	cafen.Editor.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenEditor_utf.js?v090805',
		checkLoad : function() {
			if (typeof cafenEditor_HTC != 'undefined' && typeof SWFUpload != 'undefined') {
				var editorObj = new cafen.Editor(this.params[0],this.params[1]);
				cafen.extendClassMax(this, editorObj);
				return true;
			} else 
				return false;
		}
	}, cafen.smartLoad.prototype);
	
	var cafenEditor = function() {
		this.renderObjs = [];
	}
	cafenEditor.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenEditor_utf.js?v090805',
		checkLoad : function() {
			if (typeof cafenEditor_HTC != 'undefined' && typeof SWFUpload != 'undefined') {
				var editorObj = new cafenEditor();
				cafen.extendClassMax(this, editorObj);
				for(var i = 0; i < this.renderObjs.length; i++) 
					this._renderElement(this.renderObjs[i]);
				return true;
			} else 
				return false;
		}
	}, cafen.smartLoad.prototype);
}

if (typeof cafen.Attach == 'undefined') {
	cafen.Attach = function() {
		this.setParam(arguments);
	}
	cafen.Attach.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenAttach_utf.js?v090805',
		checkLoad : function() {
			if (typeof cafenAttach_HTC != 'undefined' && typeof SWFUpload != 'undefined') {
				var editorObj = new cafen.Attach(this.params[0],this.params[1]);
				cafen.extendClassMax(this, editorObj);
				return true;
			} else 
				return false;
		}
	}, cafen.smartLoad.prototype);
	
	var cafenAttach = function() {
		this.renderObjs = [];
	}
	cafenAttach.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenAttach_utf.js?v090805',
		checkLoad : function() {
			if (typeof cafenAttach_HTC != 'undefined' && typeof SWFUpload != 'undefined') {
				var editorObj = new cafenAttach();
				cafen.extendClassMax(this, editorObj);
				for(var i = 0; i < this.renderObjs.length; i++) 
					this._renderElement(this.renderObjs[i]);
				return true;
			} else 
				return false;
		}
	}, cafen.smartLoad.prototype);
}


if (typeof cafen.RMap == 'undefined') {
	cafen.RMap = function() {
		this.setParam(arguments);
	}
	cafen.RMap.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenMap_utf.js?v090805',
		checkLoad : function() {
			if (typeof cafenMap_HTC != 'undefined' && typeof csList != 'undefined') {
				var mapObj = new cafen.RMap(this.params[0],this.params[1]);
				cafen.extendClassMax(this, mapObj);
				return true;
			} else
				return false;
		}
	}, cafen.smartLoad.prototype);
	
	var cafenMap = function() {
		this.renderObjs = [];
	}
	cafenMap.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenMap_utf.js?v090805',
		checkLoad : function() {
			if (typeof cafenMap_HTC != 'undefined' && typeof csList != 'undefined') {
				var mapObj = new cafenMap();
				cafen.extendClassMax(this, mapObj);
				for(var i = 0; i < this.renderObjs.length; i++) 
					this._renderElement(this.renderObjs[i]);
				return true;
			} else 
				return false;
		}
	}, cafen.smartLoad.prototype);
}

if (typeof cafenSyntaxHighlighter == 'undefined') {
	var cafenSyntaxHighlighter = function() {
		this.renderObjs = [];
	}
	cafenSyntaxHighlighter.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenSyntaxHighlighter.js?v090805',
		checkLoad : function() {
			if (typeof cafenCode_HTC != 'undefined' && typeof dp != 'undefined') {
				var syntaxObj = new cafenSyntaxHighlighter();
				for(var i = 0; i < this.renderObjs.length; i++) 
					syntaxObj.renderElement(this.renderObjs[i]);
				cafen.extendClassMax(this, syntaxObj);
				return true;
			} else 
				return false;
		}
	}, cafen.smartLoad.prototype);
}



if (typeof cafen.graph == 'undefined') {
	cafen.graph = function() {
		var cmds = [
			'set_js_path','set_data','set_x_labels','title','set_title','line','line_dot','line_hollow','set_x_axis_steps','set_y_label_style',
			'set_x_labels','set_x_label_style','set_y_max','y_label_steps','pie','pie_values','pie_slice_colours','set_x_tick_size','set_links',
			'set_y_legend','set_x_legend','bar','hlc','set_tool_tip','set_y_min','candle','x_axis_colour','y_axis_colour','set_x_axis_3d','area_hollow',
			'set_width','set_height','set_y_format','set_num_decimals','set_is_fixed_num_decimals_forced',
			'set_is_decimal_separator_comma','set_is_thousand_separator_disabled','set_x_offset','set_bg_colour',
			'set_bg_image','attach_to_y_right_axis','set_inner_background','set_y_right_label_style','set_x_max','set_x_min',
			'set_y_min','set_y_right_max','set_y_right_min','set_y_right_legend','y_right_axis_colour','bar_filled',
			'bar_sketch','bar_3D','bar_glass','bar_fade','candle','scatter'
		];
		var t = this;
		for(var k = 0; k < cmds.length; k++) {
			var cmd = cmds[k];
			this[cmd] = this.setQueue.bind(this,cmd);
		}
		this.params = arguments;
	}
	cafen.graph.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenOFCJS.js?v090805',
		data_sets : [],
		comandQueues : [],
		checkLoad : function() {
			if (typeof cafenGraph_HTC != 'undefined' && typeof deconcept  != 'undefined') {
				var chartObj = new cafen.graph(this.params[0],this.params[1]);
				if (this.data_sets.length > 0)
					chartObj.data_sets = this.data_sets;
				for(var i = 0; i < this.comandQueues.length; i++) {
					var cmdObj = this.comandQueues[i];
					switch (cmdObj.args.length) {
						case 0 :
							chartObj[cmdObj.cmd]();
							break;
						case 1 :
							chartObj[cmdObj.cmd](cmdObj.args[0]);
							break;
						case 2 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1]);
							break;
						case 3 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1],cmdObj.args[2]);
							break;
						case 4 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1],cmdObj.args[2],cmdObj.args[3]);
							break;
						case 5 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1],cmdObj.args[2],cmdObj.args[3],cmdObj.args[4]);
							break;
						case 6 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1],cmdObj.args[2],cmdObj.args[3],cmdObj.args[4],cmdObj.args[5]);
							break;
					}
				}
				cafen.extend(this, chartObj);
				return true;
			} else 
				return false;
		},
		setQueue : function() {
			var cmd = arguments[0];
			var args = [];
		    for (var i = 0; i < arguments.length - 1; i++)
				args.push(arguments[i + 1]);
			this.comandQueues.push({cmd : cmd, args : args});
		},
		render : function() {
			this.setQueue('render', arguments[0],arguments[1]);
			this.setParam(this.params);
		},
		esc : function( text ) {
			if (typeof text == 'number')
				text = text.toString();
			var tmp = text.replace( ",", "#comma#");
			try {
				return encodeURI(tmp);
			} catch(ex) {
				return text;
			}
		}
	}, cafen.smartLoad.prototype);

	cafen.graph.bar = function( alpha, colour )	{
		this.vartype = 'bar';
		this.alpha = alpha;
		this.colour = colour;
		this.data = [];
		this.links = [];
		this.tips = [];
		this._key = false;
	}
	
	cafen.graph.bar.prototype = {
		colour:null,
		alpha:null,
		data:null,
		links:null,
		_key:null,
		_vkey:null,
		_key_size:null,
		vartype:null,
		tips:null,
		key : function( key, size ){
			this._key = true;
			this._vkey = cafen.graph.prototype.esc( key );
			this._key_size = size;
		},
		add : function( data ){
			this.data.push(data);
		},
		add_link : function( data, link ){
			this.data.push(data);
			this.Links.push(cafen.graph.prototype.esc( link ));
		},
		add_data_tip : function( data, tip ){
			this.data.push(data);
			this.tips.push(cafen.graph.prototype.esc( tip ));
		},
		_get_variable_list : function(){
			var values = [];
			values.push(this.alpha);
			values.push(this.colour);
			if( this._key )	{
				values.push(this._vkey);
				values.push(this._key_size);
			}
			return values;
		},
		_toString : function(parentNode, set_num ){
			var values = this._get_variable_list().join(',');
			var tmp = [];
			tmp.push(parentNode.format_output( this.vartype + set_num, values ));
			tmp.push(parentNode.format_output( 'values' + set_num, this.data.join(',') ));
			if( this.links.length > 0 )
				tmp.push(parentNode.format_output( 'links' + set_num, this.links.join(',') ));
			if( this.tips.length > 0 )
				tmp.push(parentNode.format_output( 'tool_tips_set' + set_num, this.tips.join(',') ));
			return tmp.join('\r\n');
		},
		toString : function(parentNode, set_num ){
			return this._toString(parentNode, set_num);
		}
	}

	cafen.graph.bar_3d = function( alpha, colour){
		cafen.extendClass(this, new cafen.graph.bar( alpha, colour));
		this.vartype = 'bar_3d';
	}
	
	cafen.graph.bar_fade = function( alpha, colour){
		cafen.extendClass(this, new cafen.graph.bar( alpha, colour));
		this.vartype = 'bar_fade';
	}

	cafen.graph.bar_outline = function( alpha, colour, outline_colour ) 	{
		cafen.extendClass(this, new cafen.graph.bar( alpha, colour));
		this.vartype = 'filled_bar';
		this.outline_colour = outline_colour;
	}
	
	cafen.graph.bar_outline.prototype = {
		outline_colour : null,
		_get_variable_list :function (){
			var values = [];
			values.push(this.alpha);
			values.push(this.colour);
			values.push(this.outline_colour);
			if( this._key )	{
				values.push(this._vkey);
				values.push(this._key_size);
			}
			return values;
		}
	}
	
	cafen.graph.bar_glass = function( alpha, colour, outline_colour ) 	{
		cafen.extendClass(this, new cafen.graph.bar_outline( alpha, colour, outline_colour));
		this.vartype = 'bar_glass';
	}
	
	cafen.graph.bar_sketch = function( alpha, offset, colour, outline_colour ){
		cafen.extendClass(this, new cafen.graph.bar_outline( alpha, colour, outline_colour));
		this.vartype = 'bar_sketch';
		this.offset = offset;
	}
	
	cafen.graph.bar_sketch.prototype = {
		offset : null,
		_get_variable_list : function(){
			var values = [];
			values.push(this.alpha);
			values.push(this.offset);
			values.push(this.colour);
			values.push(this.outline_colour);
			if( this._key ){
				values.push(this._vkey);
				values.push(this._key_size);
			}
			return values;
		}
	}

	cafen.graph.candle = function( high, open, close, low ){
		this.out = [];
		this.out.push(high);
		this.out.push(open);
		this.out.push(close);
		this.out.push(low);
	}

	cafen.graph.candle.prototype = {
		out: null,
		_toString : function() {
			return '['+ this.out.join(',')+']';
		},
		getMinMax : function() {
			var min = null;
			var max = null;
			for(var i = 0; i < this.out.length; i++) {
				if (min == null && max == null) {
					min = parseFloat(this.out[i]);
					max = parseFloat(this.out[i]);
				} else {
					min = Math.min(min, parseFloat(this.out[i]));
					max = Math.max(max, parseFloat(this.out[i]));
				}
			}
			return [min, max];
		},
		toString : function() {
			return this._toString();
		}
	}
	
	cafen.graph.hlc = function( high, low, close ){
		this.out = [];
		this.out.push(high);
		this.out.push(low);
		this.out.push(close);
	}
	
	cafen.graph.hlc.prototype = {
		out : null,
		_toString : function(){
			return '['+ this.out.join(',') +']';
		},
		toString : function(){
			return this._toString();
		}
	}

	cafen.graph.point = function( x, y, size_px ){
		this.out = [];
		this.out.push(x);
		this.out.push(y);
		this.out.push(size_px);
	}
	
	cafen.graph.point.prototype = {
		out : null,
		_toString : function() {
			return '['+ this.out.join(',') +']';
		},
		toString : function() {
			return '['+ this.out.join(',') +']';
		}
	}
	
	var cafenGraph = function() {
		this.renderObjs = [];
	}
	
	cafenGraph.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenOFCJS.js?v090805',
		checkLoad : function() {
			if (typeof cafenGraph_HTC != 'undefined' && typeof deconcept  != 'undefined') {
				var graphObj = new cafenGraph();
				cafen.extendClassMax(this, graphObj);
				for(var i = 0; i < this.renderObjs.length; i++) 
					this._renderElement(this.renderObjs[i]);
				return true;
			} else 
				return false;
		}
	}, cafen.smartLoad.prototype);
}

if (typeof cafenOFC2JS == 'undefined') {
	
	var cafenOFC2JS = function() {
		this.renderObjs = [];
	}
	
	cafenOFC2JS.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenOFC2JS.js?v090805',
		checkLoad : function() {
			if (typeof cafenOFC2JS_HTC != 'undefined') {
				var graphObj = new cafenOFC2JS();
				cafen.extendClassMax(this, graphObj);
				for(var i = 0; i < this.renderObjs.length; i++) 
					this._renderElement(this.renderObjs[i]);
				return true;
			} else 
				return false;
		}
	}, cafen.smartLoad.prototype);

	cafen.ofc2js = {};
	cafen.ofc2js.open_flash_chart = function() {
		var cmds = [
			'addObject'
		];
		var t = this;
		for(var k = 0; k < cmds.length; k++) {
			var cmd = cmds[k];
			this[cmd] = this.setQueue.bind(this,cmd);
		}
		this.params	= arguments;
	}
	cafen.ofc2js.open_flash_chart.prototype = cafen.extendClass({
		script_url : _cafen_service_url + 'cafenOFC2JS.js?v090805',
		comandQueues : [],
		checkLoad : function() {
			if (typeof cafenOFC2JS_HTC != 'undefined') {
				var chartObj = new cafen.ofc2js.open_flash_chart();
				for(var i = 0; i < this.comandQueues.length; i++) {
					var cmdObj = this.comandQueues[i];
					switch (cmdObj.args.length) {
						case 0 :
							chartObj[cmdObj.cmd]();
							break;
						case 1 :
							chartObj[cmdObj.cmd](cmdObj.args[0]);
							break;
						case 2 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1]);
							break;
						case 3 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1],cmdObj.args[2]);
							break;
						case 4 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1],cmdObj.args[2],cmdObj.args[3]);
							break;
						case 5 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1],cmdObj.args[2],cmdObj.args[3],cmdObj.args[4]);
							break;
						case 6 :
							chartObj[cmdObj.cmd](cmdObj.args[0],cmdObj.args[1],cmdObj.args[2],cmdObj.args[3],cmdObj.args[4],cmdObj.args[5]);
							break;
					}
				}
				cafen.extend(this, chartObj);
				return true;
			} else 
				return false;
		},
		render : function() {
			this.setQueue('render', arguments[0],arguments[1]);
			this.setParam(this.params);
		},
		setQueue : function() {
			var cmd = arguments[0];
			var args = [];
		    for (var i = 0; i < arguments.length - 1; i++)
				args.push(arguments[i + 1]);
			this.comandQueues.push({cmd : cmd, args : args});
		}
	}, cafen.smartLoad.prototype);
}


if (typeof $ != 'undefined' && typeof $.fn != 'undefined') {
	$.fn.ofc2js = function() {
		var renderObj = [];
		this.each(function(idx, obj) {
			renderObj.push(obj);
		});
		var ofc2jsObj = new cafenOFC2JS();
		ofc2jsObj.renderElements(renderObj);
		return this;
	}
	
	$.fn.cafenEditor = function() {
		var renderObj = [];
		this.each(function(idx, obj) {
			renderObj.push(obj);
		});
		var editorObj = new cafenEditor();
		editorObj.renderElements(renderObj);
		return this;
	}

	$.fn.cafenAttach = function() {
		var renderObj = [];
		this.each(function(idx, obj) {
			renderObj.push(obj);
		});
		var attachObj = new cafenAttach();
		attachObj.renderElements(renderObj);
		return this;
	}

	$.fn.cafenMap = function() {
		var renderObj = [];
		this.each(function(idx, obj) {
			renderObj.push(obj);
		});
		var mapObj = new cafenMap();
		mapObj.renderElements(renderObj);
		return this;
	}
	
	$.fn.cafenRender = function() {
		return this.each(function(idx, obj) {
			cafen.renderElement(obj);
		});
	}

	$.fn.syntaxHighlighter = function(options) {
		var renderObj = [];
		this.each(function(idx, obj) {
			renderObj.push(obj);
		});
		var syntaxObj = new cafenSyntaxHighlighter();
		syntaxObj.renderElements(renderObj);
		return this;

	}
	
	$.fn.cafenGraph = function() {
		var renderObj = [];
		this.each(function(idx, obj) {
			renderObj.push(obj);
		});
		var graphObj = new cafenGraph();
		graphObj.renderElements(renderObj);
		return this;
	}	

	$.fn.colorPicker = function(options) {
		options = options || {x : 'right', y : 'top'}
		return this.each(function(idx, obj) {
			obj.linkObj = obj.getAttribute('linkObj') ? cafen.$(obj.getAttribute('linkObj')) : obj;
			obj.setColor = function (val) {
				if (this.linkObj.tagName == 'INPUT')
					this.linkObj.value = val;
				else 
					this.linkObj.style.backgroundColor = val;
			}
			obj.onclick = function() {
				if (this.colorPicker == null) 
					this.colorPicker = new cafen.XColorpicker({title : 'ColorPicker', sticker : {obj : this, x : options.x, y : options.y}, onClose : this.setColor.bind(this)});
				if (this.linkObj.tagName == 'INPUT')
					this.colorPicker.setColor(this.linkObj.value);
				else 
					this.colorPicker.setColor(this.linkObj.style.backgroundColor);
				obj.colorPicker.onLoad();
			}
		});
	}	
	$.fn.datePicker = function(options) {
		options = options || {x : 'right', y : 'top'}
		return this.each(function(idx, obj) {
			obj.linkObj = obj.getAttribute('linkObj') ? cafen.$(obj.getAttribute('linkObj')) : obj;
			obj.setDate = function (val) {
				if (this.linkObj.tagName == 'INPUT')
					this.linkObj.value = val;
				else 
					this.linkObj.innerHTML = val;
			}
			obj.onclick = function() {
				if (this.calPicker == null) 
					this.calPicker = new cafen.XCalendar({title : 'Calendar', sticker : {obj : this, x : options.x, y : options.y}, onClose : this.setDate.bind(this)});
				if (this.linkObj.tagName == 'INPUT')
					this.calPicker.setDate(this.linkObj.value);
				else
					this.calPicker.setDate(this.linkObj.innerHTML);
				obj.calPicker.onLoad();
			}
		});
	}	
	$.fn.mapPicker = function(options) {
		options = options || {x : 'right', y : 'top'}
		return this.each(function(idx, obj) {
			obj.linkObj = obj.getAttribute('linkObj') ? cafen.$(obj.getAttribute('linkObj')) : obj;
			obj.setMap = function (mapObj) {
				mapObj.close();
				var val =mapObj.getMap();
				if (this.linkObj.tagName == 'IMG')
					this.linkObj.src = val;
				else if (this.linkObj.tagName == 'INPUT')
					this.linkObj.value = val;
				else 
					this.linkObj.innerHTML = val;
			}
			obj.onclick = function() {
				if (this.mapPicker == null) 
					this.mapPicker = new cafen.XMapViewer({style : {width:'600px', height : '300px'}, event :{done : this.setMap.bind(this)}, sticker : {obj : this , x : options.x, y : options.y}});
				if (this.linkObj.tagName == 'IMG') 
					this.mapPicker.setMap(this.linkObj.src);
				else if (linkObj.tagName == 'INPUT') 
					this.mapPicker.setMap(this.linkObj.value);
				else
					this.mapPicker.setMap(this.linkObj.innerHTML);
				this.mapPicker.onLoad();
			}
		});
	}
}


function cafenPreview() {}

cafenPreview.prototype = {
/**
 * 에디터 랜드링하기
 * @param {object}
 */
	render : function() {
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (element != null)
				this._renderElement(element);
		}
	},
	renderElements : function(renderObjs) {
		for(var i=0; i < renderObjs.length; i++) 
			this.renderElement(renderObjs[i]);
	},
/**
 * 에디터 랜드링하기
 * @param {object}
 */
	renderElement : function() {
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (element != null)
				this._renderElement(element);
		}
	},
/**
 * 에디터 랜드링하기
 * @param {object}
 */
	_renderElement : function(editorObj) {
		var textAttribObj = new cafen.Attribute(editorObj);
		var config = {
			width : textAttribObj.get('width',editorObj.offsetWidth),
			height : textAttribObj.get('height',editorObj.offsetHeight),
			left : textAttribObj.getInt('left',0),
			top : textAttribObj.getInt('top',0),
			right : textAttribObj.getInt('right',0),
			bottom : textAttribObj.getInt('bottom',0),
			bg : textAttribObj.get('bg',''),
			linkObj : editorObj,
			render : 'inline'
		};
		new cafen.EditorViewer(editorObj.value, config);
	},
	/**
	* render Elements by className
	* @param {string}  className The class name of the Object to do render
	*/
	renderElementsByClassName : function(className) {
		var objs = document.getElementsByTagName('textarea');
		var editorObjs = [];
		for(var i =0; i < objs.length; i++) {
			var child = objs[i];
			if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) 
				editorObjs.push(child);
		}
		this.renderElements(editorObjs);
	},
	/**
	* render Elements by id
	* @param {string}  id The id of the Object to do render
	*/
	renderElementsById : function(id) {
		if (document.getElementById(id) != null) {
			var editorObjs = [];
			var objs = document.getElementsByTagName(document.getElementById(id).tagName);
			for(var i=0;i<objs.length;i++){
				if(objs[i].id==id) 
					editorObjs.push(objs[i]);
			}
			this.renderElements(editorObjs);
		}
	},
	/**
	* render Elements by className
	* @param {string}  className The class name of the Object to do render
	*/
	renderElementsByName : function(objName) {
		var objs = document.getElementsByTagName('textarea');
		var editorObjs = [];
		for(var i =0; i < objs.length; i++) {
			var child = objs[i];
			if (child.getAttribute('name') == objName) 
				editorObjs.push(child);
		}
		this.renderElements(editorObjs);
	}
}


cafen.EditorViewer = function(contents, options) {
	options = cafen.extend({
		width : 200, 
		height : 400, 
		top : 0 ,
		right : 0, 
		bottom : 0, 
		left : 0, 
		bg : '',
		render : 'pop',
		guideline : true,
		linkObj : null
	}, options);
	var width = options.width + options.left +options.right;
	var height = options.height;
	if (height > 0)
		height = options.height +options.top +options.bottom;
	var top = options.top;
	var right = options.right;
	var bottom = options.bottom;
	var left = options.left;
	var bg = options.bg;
	var styleCss = [];
	if (options.render == 'pop') {
		styleCss.push('body {');
		styleCss.push('margin:0;font-size:10pt;font-family:"Dotum";');
		styleCss.push('padding:0;margin:0');
		styleCss.push('}');
	}
	styleCss.push('.printClass{');
	styleCss.push('text-align:left;margin:0 10px');
	styleCss.push('}');
	styleCss.push('.contents {');
	if (options.guideline)
		styleCss.push('border:1px dashed #d0d0d0;');
	if (bg != '')
		styleCss.push('background-image:url('+bg+');');
	styleCss.push('width:'+width+'px;');
	styleCss.push('border-collapse:collapse;');
	if (height > 0) {
		styleCss.push('height:'+height+'px;');
		styleCss.push('position:relative;');
	}
	styleCss.push('padding:'+top+'px 0 '+bottom+'px '+left+'px ;');
	styleCss.push('margin:0 10px;');
	styleCss.push('z-index:1;');
	styleCss.push('}');
	styleCss.push('.contents .userContents{');
	styleCss.push('border-collapse:collapse;');
	if (options.guideline) 
		styleCss.push('border:1px dotted #3363d0;');
	styleCss.push('width:'+(width - right - left)+'px;');
	styleCss.push('z-index:100;');
	if (height > 0) 
		styleCss.push('position:absolute');
	styleCss.push('}');
	styleCss.push('P,TD, BODY{text-decoration: none;line-height:180%;}');
	styleCss.push('P, H1, H2, H3, H4, H5, H6 {margin-top:2px;margin-bottom:2px;}');
	styleCss.push('@media screen {.pageBreak {');
	styleCss.push('height:12px;');
	styleCss.push('font-size:1px;');
	styleCss.push('background-image:url('+_cafen_service_url+'images/guideline.gif);');
	styleCss.push('margin:5px 5px 25px 5px;');
	styleCss.push('border:0;');
	styleCss.push('}}');
	styleCss.push('@media print {.pageBreak {');
	styleCss.push('background-image:none;');
	styleCss.push('height:0;');
	styleCss.push('font-size:1px;');
	styleCss.push('margin:0;');
	styleCss.push('border:0;');
	styleCss.push('page-break-after:always;');
	styleCss.push('}');
	styleCss.push('.printClass{');
	styleCss.push('display:none;');
	styleCss.push('}');
	styleCss.push('.contents .userContents{');
	styleCss.push('border:0;');
	styleCss.push('}');
	styleCss.push('.contents {');
	styleCss.push('border:0px;');
	styleCss.push('margin:0px;');
	styleCss.push('background-image:none;');
	styleCss.push('}');
	styleCss.push('}');
	switch(options.render) {
		case 'inline' :
			if (options.linkObj != null)
				options.linkObj.style.display = 'none';
			this.initBody(width + 30, height, options.linkObj);
			break;
		case 'pop' :
		default :
			this.initPop(width + 40, (height+20) > screen.availHeight*0.7 ? Math.round(screen.availHeight*0.7)  : (height+20));
			break;
	}
	this.setHeader(styleCss);
	this.setContents(contents, options.render);
}

cafen.EditorViewer.prototype = {
	_bodyObj : null,
	_pageBreak : '<!-- page -->',
	initPop : function(pwidth, pheight) {
		if (pheight < 100)
			pheight =  screen.availHeight*0.7;
		var htmlskin = '<html><title></title><head></head><body></body></html>';
		if (cafen.browser.isIE || navigator.userAgent.toLowerCase().indexOf("opera")!=-1) {
			var docDomain = document.domain;
			try {
				var srcCode = 'javascript:void( (function(){' +  
					'document.open() ;' +  
					'document.write( "'+htmlskin+'"  );' +
					'document.close() ;' +
					'if (document.domain != "'+docDomain+'") ' +  
					'	document.domain = "'+docDomain+'"; ' +  
					'})() )' ;
				this.popObj = window.open(srcCode, '_blank', 'width='+pwidth+', height='+pheight+', location=0, resizable=0, menubar=0, scrollbars=1');
			} catch(ex) {
				alert(ex);	
			}
		} else {
			var srcCode = 'javascript:void(0)' ;
			this.popObj = window.open(srcCode, '_blank', 'width='+pwidth+', height='+pheight+', location=0, resizable=0, menubar=0, scrollbars=1');
			try {
				var editdoc = this.getElement().document;
				editdoc.open() ;
				editdoc.write(htmlskin);
				editdoc.close() ;
			} catch(ex) {
				alert(ex);	
			}
		}
		this._bodyObj = this.getElement().document.getElementsByTagName('body')[0];
		this.getElement().onerror = function() {}
	},
	initBody : function(pwidth, pheight, linkObj) {
		this.popObj = window;
		if (this.popObj.document.getElementById('editorPreview') != null) 
			this._bodyObj = this.popObj.document.getElementById('editorPreview');
		else {
			this._bodyObj = this.popObj.document.createElement('div');
			this._bodyObj.id = 'editorPreview';
			this._bodyObj.style.width = pwidth +'px';
			if (linkObj != null)
				linkObj.parentNode.insertBefore(this._bodyObj,linkObj);
			else
				this.getElement().document.getElementsByTagName('body')[0].appendChild(this._bodyObj);
		}
	},
	setHeader : function(stylecss) {
		var headNode = this.getElement().document.getElementsByTagName('head')[0];
		if(stylecss && headNode) {
			var styleNode = this.getElement().document.createElement('style');
			styleNode.setAttribute('type', 'text/css');
			if(styleNode.styleSheet) {
				try {
					styleNode.styleSheet.cssText = stylecss.join('\r\n');
				} catch(ex) {
					styleNode.nodeText = stylecss.join('\r\n');
				}
			}	else {
				var textNode = this.getElement().document.createTextNode(stylecss.join('\r\n'));
				styleNode.appendChild(textNode);
			}
			headNode.appendChild(styleNode);
			this.getElement().headerSetted = true;
		}
	},
	setContents : function(html, render) {
		var constArr = html.split(this._pageBreak);
		var conHtml = [];
		for (var i = 0 ; i < constArr.length; i++) {
			conHtml.push('<div class="contents"><div class="userContents">'+constArr[i]+'</div></div>');
		}
		var printTag = [];
		if (render == 'pop') {
			printTag.push('<div class="printClass">')
			printTag.push('<button type=button onclick=print() style="width:100px;height:30px;margin:3px;"><u><b>P</b></u>rint</button>');
			printTag.push('<button type=button onclick=self.close() style="width:100px;height:30px;margin:3px;"><u><b>C</b></u>lose</button>');
			printTag.push('</div>');
		}
		this._bodyObj.innerHTML = printTag.join('') + conHtml.join('<div class="pageBreak"></div>');
	},
	getElement : function() {
		return this.popObj;
	},
	nullFnc : function() {}	
}


