/*
 * Rich JavaScript framework, version 1.4 beta
 * Copyright (c) 2006-2008 Lee Won-Gyoon <mail.kido@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * For details, see the RichScript web site: http://www.richScript.net/
 * 
*******************************************************************************/

var richScript = {
	Version : "1.4 beta"
}

var browser = {
	isIE : (navigator.userAgent.indexOf('MSIE') > -1),
	isIE6 : (navigator.userAgent.indexOf('MSIE 6') > -1),
	isIE7 : (navigator.userAgent.indexOf('MSIE 7') > -1),
	isFF : (navigator.userAgent.indexOf('Gecko') > -1),
	getW : function() {
		return document.documentElement.clientWidth;
	},
	getH : function() {
		return document.documentElement.clientHeight;
	}
}


/**
 String
*****************************/
String.prototype.trim = function () {
	var s = (this!=null) ? this : "";
	s = s.replace(/^\s+/g,"");
	s = s.replace(/\s+$/g,"");
	return s;
};

String.prototype.replaceQuot = function() {
	var s = (this!=null) ? this : "";
	s = s.replace(/\\/g,"\\\\");
	s = s.replace(/\"/g,"\\\"");
	s = s.replace(/\'/g,"\\\'");
	return s;
};

String.prototype.escapeXml = function() {
	var s = (this!=null) ? this : "";
	s = s.replace(/&/g,"&amp;");
	s = s.replace(/\'/g,"&#039;");
	s = s.replace(/\"/g,"&#34;");
	s = s.replace(/</g,"&lt;");
	s = s.replace(/>/g,"&gt;");
	s = s.replace(/\n/g,"&#10;");
	s = s.replace(/\r/g,"&#13;");
	s = s.replace(/\t/g,"&#9;");
	return s;
};

String.prototype.escapeJavaScript = function() {
	var s = (this!=null) ? this : "";
	s = s.replace(/\\/g,"\\\\");
	s = s.replace(/\//g,"\\/");
	s = s.replace(/\n/g,"\\n");
	s = s.replace(/\r/g,"\\r");
	s = s.replace(/\t/g,"\\t");
	s = s.replace(/\"/g,"\\\"");
	s = s.replace(/\'/g,"\\'");
	return s;
};

String.prototype.removeTag = function() {
	var s = (this!=null) ? this : "";
	s = s.replace(/<\/?[^>]+>/gi,"");
	return s;
};

String.prototype.convertEnterToBr = function() {
	var s = (this!=null) ? this : "";
	s = s.replace(/\n/g,"<br>");
	return s;
};

String.prototype.getBytes = function() {
	var s = (this!=null) ? this : "";
	var bytes = 0;
	var c = "";
	var u = "";
	for (var i=0; i<s.length; i++) {
		c = s.charAt(i);
		u = escape(c);
		if (u.length < 4) { // ¹Ý°¢¹®ÀÚ : ±âº»ÀûÀÎ ¿µ¹®, ¼ýÀÚ, Æ¯¼ö±âÈ£
			bytes++; // + 1byte
		} else {
			var b = parseInt(c.charCodeAt(0));
			if (((b >= 65377)&&(b <= 65500))||((b >= 65512)&&(b <= 65518))) // ¹Ý°¢¹®ÀÚ À¯´ÏÄÚµå 10Áø¼ö ¹üÀ§ : ÇÑ±¹¾î, ÀÏº»¾î, Æ¯¼ö¹®ÀÚ
				bytes++; // + 1byte
			else // Àü°¢¹®ÀÚ : À§ Á¶°ÇÀ» Á¦¿ÜÇÑ ¸ðµç ¹®ÀÚ
				bytes += 2; // + 2byte
		}
	}
	return bytes;
};

String.prototype.encodeUnicode = function(_separator) {
	var s = (this!=null) ? this : "";
	var separator = (_separator==undefined) ? "." : _separator;
	var u = new Array;
	for (var i=0; i<s.length; i++) {
		s.charCodeAt(i);
		u.push(s.charCodeAt(i));
	}
	return u.join(separator);
};

String.prototype.decodeUnicode = function(_separator) {
	var s = (this!=null) ? this : "";
	var separator = (_separator==undefined) ? "." : _separator;
	var u = s.split(separator);
	var dec = "";
	if (u.length>0) {
		try {
			dec = eval("String.fromCharCode("+u.join(",")+")");
		} catch (e) { }
	}
	return dec;
};

String.prototype.appendParameter = function(_param) {
	var s = (this!=null) ? this : "";
	if (_param!=undefined&&_param!="") {
		if (s.indexOf("?")>-1) {
			s += "&";
		} else {
			s += "?";
		}
		s += _param;
	}
	return s;
};

String.prototype.toBold = function() {
	var s = (this!=null) ? this : "";
	return "<strong>"+s+"</strong>";
};


String.prototype.toPng24BgStyle = function() {
	var s = (this!=null) ? this : "";
	if (browser.isIE) s = ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+s+' ,sizingMethod=scale ); ';
	else s = ' background:url('+s+') transparent; ';
	return s;
}


/**
 Math
*****************************/
Math.isInt = function(_s) {
	return (_s!=undefined&&""+parseInt(_s)!="NaN");
};

Math.isFloat = function(_s) {
	return (_s!=undefined&&""+parseFloat(_s)!="NaN");
};



/**
 Document Object
*****************************/
function $() {
	var o = null;
	if (typeof arguments[0] == 'string') {
		o = document.getElementById(arguments[0]);
	} else {
		o = arguments[0];
	}
	if (o==null) {
		o = {};
		o.isNull = true;
	} else {
		if (o.isNull!=undefined) {
			return o;
		}
		o.isNull = false;
	}
	
	o.setStyle = function(_name, _value) {
		if (_name=="display") {
			_value = (""+_value).toLowerCase();
			if (_value=="false"||_value=="none") _value = "none";
			else _value = "";
		} else if (_name=="left"||_name=="top"||_name=="width"||_name=="height") {
			_value = (""+_value).toLowerCase();
			if (_value!=""&&_value.indexOf("px")<0) _value += "px";
		}
		this.style[_name] = _value;
	};
	
	o.getStyle = function(_name) {
		return this.style[_name];
	};
	
	o.getW = function() {
		return this.offsetWidth;
	};
	
	o.getH = function() {
		return this.offsetHeight;
	};
	
	o.getX = function() {
		var posX = this.style.left;
		if (posX=="") {
			posX = 0;
			var tempObj = this;
			if (tempObj.offsetParent) {
				while (tempObj.offsetParent) {
					posX += tempObj.offsetLeft;
					tempObj = tempObj.offsetParent;
				}
			}
			tempObj = null;
		} else {
			posX = parseInt(posX.toLowerCase().replace("px",""));
		}
		return posX;
	};
	
	o.getY = function() {
		var posY = this.style.top;
		if (posY=="") {
			posY = 0;
			var tempObj = this;
			if (tempObj.offsetParent) {
				while (tempObj.offsetParent) {
					posY += tempObj.offsetTop;
					tempObj = tempObj.offsetParent;
				}
			}
			tempObj = null;
		} else {
			posY = parseInt(posY.toLowerCase().replace("px",""));
		}
		return posY;
	};
	
	o.setOpacity = function(_value) {
		if (parseFloat(_value)>1) _value = parseFloat(_value)/100;
		this.setStyle("filter","alpha(opacity=" + (_value*100) + ")");
		this.setStyle("opacity",_value);
		this.setAttribute("opacity",_value);
	};
	
	o.getOpacity = function() {
		var value = this.getAttribute("opacity") || this.getStyle("opacity") || 0;
		if (value==undefined||value=="") value = 0;
		return parseFloat(value);
	};
	
	o.setFadeIn = function(_opacity, _sp, _function, _isReCall) {
		try {
			if (!this.isNull) {
				if (_isReCall!=true&&this.getAttribute("fade.status")=="ing") {
					this.setAttribute("fade.mode","in");
					this.setAttribute("fade.opacity",_opacity);
					this._fade_function = _function;
				} else {
					var mode = "in";
					if (_isReCall!=true) {
						if (!Math.isFloat(_opacity)) _opacity = 1.0;
						if (_opacity>1) _opacity = _opacity/100;
						if (!Math.isInt(_sp)) _sp = 30;
						this.setAttribute("fade.status","ing");
						this.setAttribute("fade.mode",mode);
						this.setAttribute("fade.opacity",_opacity);
						this._fade_function = _function;
					} else {
						mode = this.getAttribute("fade.mode");
						_opacity = parseFloat(this.getAttribute("fade.opacity"));
						_sp = parseInt(this.getAttribute("fade.sp"));
					}
					if (mode=="out") {
						this.setFadeOut(null, null, null, true);
					} else {
						var nowOpacity = this.getOpacity();
						var targetOpacity = nowOpacity + 0.1;
						if (targetOpacity > _opacity) targetOpacity = _opacity;
						this.setOpacity(targetOpacity);
						if (targetOpacity<_opacity) {
							var _id = this.id;
							this.fadeTimer = setTimeout( function() {
								$(_id).setFadeIn(null, null, null, true);
							}, _sp);
						} else {
							this.removeAttribute("fade.status");
							this.removeAttribute("fade.mode");
							this.removeAttribute("fade.opacity");
							_function = this._fade_function;
							this._fade_function = null;
							if (_function==undefined) _function = "";
							try {
								if (typeof(_function)=="function") {
									_function();
								} else {
									eval(_function);
								}
							} catch(e) { }
						}
					}
				}
			}
		}catch(e) {
			alert("RichScript Error Form $().setFadeIn() : " + e);
		}
	};
	
	o.setFadeOut = function(_opacity, _sp, _function, _isReCall) {
		try {
			if (!this.isNull) {
				if (_isReCall!=true&&this.getAttribute("fade.status")=="ing") {
					this.setAttribute("fade.mode","out");
					this.setAttribute("fade.opacity",_opacity);
					this._fade_function = _function;
				} else {
					var mode = "out";
					if (_isReCall!=true) {
						if (!Math.isFloat(_opacity)) _opacity = 1.0;
						if (_opacity>1) _opacity = _opacity/100;
						if (!Math.isInt(_sp)) _sp = 30;
						this.setAttribute("fade.status","ing");
						this.setAttribute("fade.mode",mode);
						this.setAttribute("fade.opacity",_opacity);
						this._fade_function = _function;
					} else {
						mode = this.getAttribute("fade.mode");
						_opacity = parseFloat(this.getAttribute("fade.opacity"));
						_sp = parseInt(this.getAttribute("fade.sp"));
					}
					if (mode=="in") {
						this.setFadeIn(null, null, null, true);
					} else {
						var nowOpacity = this.getOpacity();
						var targetOpacity = nowOpacity - 0.1;
						if (targetOpacity < _opacity) targetOpacity = _opacity;
						this.setOpacity(targetOpacity);
						if (targetOpacity>_opacity) {
							var _id = this.id;
							this.fadeTimer = setTimeout( function() {
								$(_id).setFadeOut(null, null, null, true);
							}, _sp);
						} else {
							this.removeAttribute("fade.status");
							this.removeAttribute("fade.mode");
							this.removeAttribute("fade.opacity");
							_function = this._fade_function;
							this._fade_function = null;
							if (_function==undefined) _function = "";
							try {
								if (typeof(_function)=="function") {
									_function();
								} else {
									eval(_function);
								}
							} catch(e) { }
						}
					}
				}
			}
		}catch(e) {
			alert("RichScript Error Form $().setFadeOut() : " + e);
		}
	};
	
	
	o._getNextPoint = function(_prevPont, _targetPoint, _sp) {
		var point = 0;
		var finishPointChecking = false;
		var checkMode = "";
		if (_targetPoint<0) {
			if (_prevPont<0) {
				if (Math.abs(Math.abs(_targetPoint)-Math.abs(_prevPont))<_sp) {
					point = _targetPoint;
					finishPointChecking = true;
				}
				checkMode = "A";
			} else {
				checkMode = "B";
			}
		} else {
			if (_prevPont>=0) {
				if (Math.abs(Math.abs(_targetPoint)-Math.abs(_prevPont))<_sp) {
					point = _targetPoint;
					finishPointChecking = true;
				}
				checkMode = "C";
			} else {
				checkMode = "D";
			}
		}
		
		if (!finishPointChecking) {
			var setPoint = 0;
			var gapPoint = Math.abs(_prevPont-_targetPoint);
			if (checkMode=="A"||checkMode=="C") {
				gapPoint = Math.abs(_prevPont-_targetPoint);
			} else {
				gapPoint = Math.abs(_prevPont+_targetPoint);
			}
			var minusOption = 1;
			if (_prevPont > _targetPoint) minusOption *= -1;
			if (gapPoint>_sp) setPoint = _sp*minusOption;
			else setPoint = gapPoint*minusOption;
			point = _prevPont+setPoint;
		}
		return point;
	};
	
	
	
	o.resizeToMotionA = function(_w, _h, _function, _sp, _isReCall) {
		if (!this.isNull) {
			var useMultiCommand = (this.getAttribute("resizeTo.useMultiCommand")=="true");
			if (useMultiCommand&&_isReCall!=true&&this.getAttribute("resizeTo.status")=="ing") {
				if (Math.isInt(_w)) this.setAttribute("resizeTo.w",_w);
				if (Math.isInt(_h)) this.setAttribute("resizeTo.h",_h);
				if (Math.isInt(_sp)) this.setAttribute("resizeTo.sp",_sp);
				this._resizeTo_function = _function;
			}
			if (_isReCall==true||this.getAttribute("resizeTo.status")!="ing") {
				try {
					var w = this.getW();
					var h = this.getH();
					if (_isReCall!=true) {
						if (!Math.isInt(_w)) _w = nowW;
						if (!Math.isInt(_h)) _h = nowH;
						if (!Math.isInt(_sp)) _sp = 10;
						else _sp = parseInt(_sp);
						this.setAttribute("resizeTo.status","ing");
						this.setAttribute("resizeTo.w", _w);
						this.setAttribute("resizeTo.h", _h);
						this.setAttribute("resizeTo.sp", _sp);
						this._resizeTo_function = _function;
					} else {
						_w = parseInt(this.getAttribute("resizeTo.w"));
						_h = parseInt(this.getAttribute("resizeTo.h"));
						_sp = parseInt(this.getAttribute("resizeTo.sp"));
					}
					if (_w<1) _w = 1;
					if (_h<1) _h = 1;
					var targetW = this._getNextPoint(w,_w,_sp);
					var targetH = this._getNextPoint(h,_h,_sp);
					this.setStyle("width",targetW);
					this.setStyle("height",targetH);
					
					if (w==_w&&h==_h) {
						this.removeAttribute("resizeTo.status");
						this.removeAttribute("resizeTo.w");
						this.removeAttribute("resizeTo.h");
						this.removeAttribute("resizeTo.sp");
						_function = this._resizeTo_function;
						this._resizeTo_function = null;
						if (_function==undefined) _function = "";
						try {
							if (typeof(_function)=="function") {
								_function();
							} else {
								eval(_function);
							}
						} catch(e) { }
					} else {
						var _id = this.id;
						this.resizeToTimer = setTimeout( function() {
							$(_id).resizeToMotionA(null, null, null, null, true);
						}, 10);
					}
				}catch(e) {
					alert("RichScript Error Form $().resizeToMotionA() : " + e);
				}
			}
		}
	};
	
	
	o.resizeTo = function(_w, _h, _function, _sp, _isReCall) {
		if (!this.isNull) {
			var useMultiCommand = (this.getAttribute("resizeTo.useMultiCommand")=="true");
			if (useMultiCommand&&_isReCall!=true&&this.getAttribute("resizeTo.status")=="ing") {
				if (Math.isInt(_w)) this.setAttribute("resizeTo.w",_w);
				if (Math.isInt(_h)) this.setAttribute("resizeTo.h",_h);
				if (Math.isInt(_sp)) this.setAttribute("resizeTo.sp",_sp);
				this._resizeTo_function = _function;
			}
			if (_isReCall==true||this.getAttribute("resizeTo.status")!="ing") {
				try {
					var nowW = this.getW();
					var nowH = this.getH();
					if (_isReCall!=true) {
						if (!Math.isInt(_w)) _w = nowW;
						if (!Math.isInt(_h)) _h = nowH;
						if (!Math.isInt(_sp)) _sp = 5;
						else _sp = parseInt(_sp);
						this.setAttribute("resizeTo.status","ing");
						this.setAttribute("resizeTo.w", _w);
						this.setAttribute("resizeTo.h", _h);
						this.setAttribute("resizeTo.sp", _sp);
						this._resizeTo_function = _function;
					} else {
						_w = parseInt(this.getAttribute("resizeTo.w"));
						_h = parseInt(this.getAttribute("resizeTo.h"));
						_sp = parseInt(this.getAttribute("resizeTo.sp"));
					}
					var targetW = (_w<1)?1:_w;
					var targetH = (_h<1)?1:_h;
					
					if (targetW==nowW&&targetH==nowH) {
						this.removeAttribute("resizeTo.status");
						this.removeAttribute("resizeTo.w");
						this.removeAttribute("resizeTo.h");
						this.removeAttribute("resizeTo.sp");
						_function = this._resizeTo_function;
						this._resizeTo_function = null;
						if (_function==undefined) _function = "";
						try {
							if (typeof(_function)=="function") {
								_function();
							} else {
								eval(_function);
							}
						} catch(e) { }
					} else {
						var addW = 0;
						var addH = 0;
						if (targetW > nowW) addW = Math.ceil((targetW - nowW) / _sp);
						else                addW = Math.ceil((nowW - targetW) / _sp)*-1;
						if (targetH > nowH) addH = Math.ceil((targetH - nowH) / _sp);
						else                addH = Math.ceil((nowH - targetH) / _sp)*-1;
						var finalW = nowW + addW;
						var finalH = nowH + addH;
						if (finalW<1) finalW = 1;
						if (finalH<1) finalH = 1;
						this.setStyle("width", finalW);
						this.setStyle("height", finalH);
						var _id = this.id;
						this.resizeToTimer = setTimeout( function() {
							$(_id).resizeTo(null, null, null, null, true);
						}, 10);
					}
				}catch(e) {
					alert("RichScript Error Form $().resizeTo() : " + e);
				}
			}
		}
	};
	
	o.moveTo = function(_x, _y, _function, _sp, _isReCall) {
		if (!this.isNull) {
			var useMultiCommand = (this.getAttribute("moveTo.useMultiCommand")=="true");
			if (useMultiCommand&&_isReCall!=true&&this.getAttribute("moveTo.status")=="ing") {
				if (Math.isInt(_x)) this.setAttribute("moveTo.x",_x);
				if (Math.isInt(_y)) this.setAttribute("moveTo.y",_y);
				if (Math.isInt(_sp)) this.setAttribute("moveTo.sp",_sp);
				this._moveTo_function = _function;
			}
			if (_isReCall==true||this.getAttribute("moveTo.status")!="ing") {
				try {
					var nowX = this.getX();
					var nowY = this.getY();
					if (_isReCall!=true) {
						if (!Math.isInt(_x)) _x = nowX;
						if (!Math.isInt(_y)) _y = nowY;
						if (!Math.isInt(_sp)) _sp = 5;
						else _sp = parseInt(_sp);
						this.setAttribute("moveTo.status","ing");
						this.setAttribute("moveTo.x", _x);
						this.setAttribute("moveTo.y", _y);
						this.setAttribute("moveTo.sp", _sp);
						this._moveTo_function = _function;
					} else {
						_x = parseInt(this.getAttribute("moveTo.x"));
						_y = parseInt(this.getAttribute("moveTo.y"));
						_sp = parseInt(this.getAttribute("moveTo.sp"));
					}
					var targetX = _x;
					var targetY = _y;
					
					if (targetX==nowX&&targetY==nowY) {
						this.removeAttribute("moveTo.status");
						this.removeAttribute("moveTo.x");
						this.removeAttribute("moveTo.y");
						this.removeAttribute("moveTo.sp");
						_function = this._moveTo_function;
						this._moveTo_function = null;
						if (_function==undefined) _function = "";
						try {
							if (typeof(_function)=="function") {
								_function();
							} else {
								eval(_function);
							}
						} catch(e) { }
					} else {
						var moveX = 0;
						var moveY = 0;
						if (targetX > nowX) moveX = Math.ceil((targetX - nowX) / _sp);
						else                moveX = Math.ceil((nowX - targetX) / _sp)*-1;
						if (targetY > nowY) moveY = Math.ceil((targetY - nowY) / _sp);
						else                moveY = Math.ceil((nowY - targetY) / _sp)*-1;
						this.setStyle("left", nowX + moveX);
						this.setStyle("top", nowY + moveY);
						var _id = this.id;
						this.moveToTimer = setTimeout( function() {
							$(_id).moveTo(null, null, null, null, true);
						}, 10);
					}
				}catch(e) {
					alert("RichScript Error Form $().moveTo() : " + e);
				}
			}
		}
	};
	
	o.moveToMotionA = function(_x, _y, _function, _sp, _isReCall) {
		if (!this.isNull) {
			var useMultiCommand = (this.getAttribute("moveTo.useMultiCommand")=="true");
			if (useMultiCommand&&_isReCall!=true&&this.getAttribute("moveTo.status")=="ing") {
				if (Math.isInt(_x)) this.setAttribute("moveTo.x",_x);
				if (Math.isInt(_y)) this.setAttribute("moveTo.y",_y);
				if (Math.isInt(_sp)) this.setAttribute("moveTo.sp",_sp);
				this._moveTo_function = _function;
			}
			if (_isReCall==true||this.getAttribute("moveTo.status")!="ing") {
				try {
					var x = this.getX();
					var y = this.getY();
					if (_isReCall!=true) {
						if (!Math.isInt(_x)) _x = x;
						if (!Math.isInt(_y)) _y = y;
						if (!Math.isInt(_sp)) _sp = 10;
						else _sp = parseInt(_sp);
						this.setAttribute("moveTo.status","ing");
						this.setAttribute("moveTo.x", _x);
						this.setAttribute("moveTo.y", _y);
						this.setAttribute("moveTo.sp", _sp);
						this._moveTo_function = _function;
					} else {
						_x = parseInt(this.getAttribute("moveTo.x"));
						_y = parseInt(this.getAttribute("moveTo.y"));
						_sp = parseInt(this.getAttribute("moveTo.sp"));
					}
					
					if (x==_x&&x==_x) {
						this.removeAttribute("moveTo.status");
						this.removeAttribute("moveTo.x");
						this.removeAttribute("moveTo.y");
						this.removeAttribute("moveTo.sp");
						_function = this._moveTo_function;
						this._moveTo_function = null;
						if (_function==undefined) _function = "";
						try {
							if (typeof(_function)=="function") {
								_function();
							} else {
								eval(_function);
							}
						} catch(e) { }
					} else {
						var targetX = this._getNextPoint(x,_x,_sp);
						var targetY = this._getNextPoint(y,_y,_sp);
						this.setStyle("left",targetX);
						this.setStyle("top",targetY);
						var _id = this.id;
						this.moveToTimer = setTimeout( function() {
							$(_id).moveToMotionA(null, null, null, null, true);
						}, 10);
					}
				}catch(e) {
					alert("RichScript Error Form $().moveToMotionA() : " + e);
				}
			}
		}
	};
	
	o.moveToTarget = function(_targetId, _function, _sp, _isReCall) {
		if (!this.isNull) {
			var useMultiCommand = (this.getAttribute("moveTo.useMultiCommand")=="true");
			if (useMultiCommand&&_isReCall!=true&&this.getAttribute("moveTo.status")=="ing") {
				if (!$(_targetId).isNull) this.setAttribute("moveTo.targetId",_targetId);
				if (Math.isInt(_sp)) this.setAttribute("moveTo.sp",_sp);
				this._moveTo_function = _function;
			}
			if (_isReCall==true||this.getAttribute("moveTo.status")!="ing") {
				try {
					if (_isReCall!=true) {
						if (!Math.isInt(_sp)) _sp = 5;
						this.setAttribute("moveTo.status","ing");
						this.setAttribute("moveTo.targetId",_targetId);
						this.setAttribute("moveTo.sp",_sp);
						this._moveTo_function = _function;
					} else {
						_targetId = this.getAttribute("moveTo.targetId");
						_sp = this.getAttribute("moveTo.sp");
					}
					if (!$(_targetId).isNull) {
						var targetX = $(_targetId).getX();
						var targetY = $(_targetId).getY();
						var nowX = this.getX();
						var nowY = this.getY();
						
						if (targetX==nowX&&targetY==nowY) {
							this.removeAttribute("moveTo.status");
							this.removeAttribute("moveTo.targetId");
							this.removeAttribute("moveTo.sp");
							_function = this._moveTo_function;
							this._moveTo_function = null;
							if (_function==undefined) _function = "";
							try {
								if (typeof(_function)=="function") {
									_function();
								} else {
									eval(_function);
								}
							} catch(e) { }
						} else {
							var moveX = 0;
							var moveY = 0;
							if (targetX > nowX) moveX = Math.ceil((targetX - nowX) / _sp);
							else                moveX = Math.ceil((nowX - targetX) / _sp)*-1;
							if (targetY > nowY) moveY = Math.ceil((targetY - nowY) / _sp);
							else                moveY = Math.ceil((nowY - targetY) / _sp)*-1;
							this.setStyle("left", nowX + moveX);
							this.setStyle("top", nowY + moveY);
							var _id = this.id;
							this.moveToTimer = setTimeout( function() {
								$(_id).moveToTarget(null, null, null, true);
							}, 10);
						}
					} else {
						this.removeAttribute("moveTo.status");
						this.removeAttribute("moveTo.targetId");
						this.removeAttribute("moveTo.sp");
					}
				}catch(e) {
					alert("RichScript Error Form $().moveToTarget() : " + e);
				}
			}
		}
	};
	
	o.insertAfter = function(_newNode, _beforeNode) {
		if (_beforeNode.parentNode.lastChild==_beforeNode) {
			_beforeNode.parentNode.appendChild(_newNode);
		} else {
			_beforeNode.parentNode.insertBefore(_newNode, _beforeNode.nextSibling);
		}
	};
	
	return o;
}








/**
 Event
*****************************/
var $E = {
	vars : {},
	event : null,
	eventActions : [],
	
	getElement : function() {
		return this.event.target || this.event.srcElement;
	},
	
	getValidElement : function(_attributeName,_attributeValue) {
		var element = this.getElement();
		while(element) {
			if (element.getAttribute(_attributeName)==_attributeValue) {
				break;
			}
			element = element.parentNode;
		}
		return element;
	},
	
	pointerX : function() {
		var x = 0;
		if (this.event!=null) {
			x = this.event.pageX || (this.event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
			//alert("this.event.pageX : " + this.event.pageX + "\n other : " + x);
			//x = (document.documentElement.scrollLeft) ? this.event.clientX : this.event.clientX + document.body.scrollLeft;
		}
		return x;
	},
	
	pointerY : function() {
		var y = 0;
		if (this.event!=null) {
			y = this.event.pageY || (this.event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
			//y = (document.documentElement.scrollTop) ? this.event.clientY : this.event.clientY + document.body.scrollTop;
		}
		return y;
	},
	
	
	addAction : function(_eventType, _eventGroup, _eventAction) {
		this.eventActions.push(
			{
				  type		: _eventType.trim().toLowerCase()
				, group		: _eventGroup.trim().toLowerCase()
				, action	: _eventAction
			}
		);
	},
	
	removeAction : function(_eventGroup) {
		for (var i=0; i<this.eventActions.length; i++) {
			var eAction = this.eventActions[i];
			if (eAction.group==_eventGroup.trim().toLowerCase()) {
				this.eventActions[i] = null;
			}
		}
		this.eventActions = this.eventActions.compact();
	},
	
	stop : function() {
		if (this.event.preventDefault!=undefined) {
			this.event.preventDefault();
			this.event.stopPropagation();
		} else {
			this.event.returnValue = false;
			this.event.cancelBubble = true;
		}
	},
	
	onEvent : function(_eventType) {
		for (var i=0; i<this.eventActions.length; i++) {
			var eAction = this.eventActions[i];
			if (eAction.type==_eventType.trim().toLowerCase()) {
				try {
					if (typeof(eAction.action)=="function") {
						eAction.action();
					} else {
						eval(eAction.action);
					}
				} catch(e) { }
			}
		}
	}
};

function _EventListener(_event) {
	_event = window.event ? window.event : _event;
	$E.event = _event;
	$E.onEvent("on"+_event.type);
}


/**
 Use BackgroundImageCache For IE
*****************************/
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}
