daum.effects = {
	version : "1.0a",
	init : function() {
		var scripts = daum.$T("script");
		for (var i = 0, len = scripts.length; i < len; ++i) {
			if (scripts[i].src.indexOf("byul.js?widgets=") !== -1) {
				var src = scripts[i].src,
				path = src.replace(/byul\.js(\?.*)?$/, ""),
				widgets = src.match(/\?.*widgets=(.*)?$/)[1];
				daum.Array.each(widgets.split(","), function(widget) {
					document.write('<script type="text/javascript" src="'+ path + daum.String.trim(widget) + ".js" + '"><\/script>');
				});
				break;
			}
		}
	},
	hasClassName : function(e, cname) {
		var ret = false, arr = e.className.split(/\s+/);
		for (var i in arr) {
			if ( arr[i] === cname) { ret = true; }
		}
		return ret;
	},
	show : function(e, displayValue) {
		e.style.display = displayValue || "";
	},
	toggle : function(e, displayValue) {
		(daum.Element.getStyle(e, "display") === "none")
		? daum.Element.show(e, displayValue)
		: daum.Element.hide(e);
	},
	/************************************************************************************************************
	 * 기존 오브젝트 모델 구문(propName)과 CSS 프로퍼티 형식(prop-name)을 모두 기입해야 함. CSS 프로퍼티 형식만 기입해도 되게 변경
	 * currentStyle 문제 보완 http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 참고
	 ************************************************************************************************************/
	getStyle : function(e, p) {
		var _return,
		_p = (p !== "float")
					? p.replace(/-(.)/g, function(a, b) { return b.toUpperCase(); })
					: (daum.Browser.ie)
						? "styleFloat"
						: "cssFloat";
		if (e.style[_p]) {
			_return = e.style[_p];
		} else if (e.currentStyle) {
			if (p === "width" || p === "height") {	//IE width, height일 경우 offsetWidth, offsetHeight로 처리
				var sumPB = 0;
				if (p === "width") {
					sumPB += parseInt(e.currentStyle["paddingLeft"]) + parseInt(e.currentStyle["paddingRight"]);
					if (e.currentStyle["borderLeftWidth"].indexOf("px") > 0 || e.currentStyle["borderRightWidth"] > 0) {
						sumPB += parseInt(e.currentStyle["borderLeftWidth"]) + parseInt(e.currentStyle["borderRightWidth"]);
					}
				} else {
					sumPB += parseInt(e.currentStyle["paddingTop"]) + parseInt(e.currentStyle["paddingBottom"]);
					if (e.currentStyle["borderTopWidth"].indexOf("px") > 0 || e.currentStyle["borderBottomWidth"] > 0) {
						sumPB += parseInt(e.currentStyle["borderBottomWidth"]) + parseInt(e.currentStyle["borderBottomWidth"]);
					}
				}
				_return = daum.Number.px(e["offset" + p.replace(/\b([a-z])/g, function(a) { return a.toUpperCase(); })] - sumPB);
			} else if (p === "opacity") {
				_return = e.currentStyle["opacity"] || 1;
			} else {
				var style = e.style;
				_return = e.currentStyle[_p] || e.currentStyle[p];
				if (!/^\d+(px)?$/i.test(_return) && /^\d/.test(_return)) {
					var left = style.left, rsLeft = e.runtimeStyle.left;
					e.runtimeStyle.left = e.currentStyle.left;
					style.left = _return || 0;
					_return = style.pixelLeft + "px";
					style.left = left;
					e.runtimeStyle.left = rsLeft;
				}
			}
		} else {
			_return = document.defaultView.getComputedStyle(e, null).getPropertyValue(p);
		}
		return _return;
	},
	setStyle : function(e, p, v) {
			if (p !== "opacity") {
			daum.$(e).style[(p !== "float")
									? p.replace(/-(.)/g, function(a, b) { return b.toUpperCase(); })
									: (daum.Browser.ie)
										? "styleFloat"
										: "cssFloat"] = v;
			} else {
				daum.Element.setOpacity(e, parseFloat(v));
			}
	},
	getWidth : function(e) {
		return daum.String.toFloat($JE.getStyle(e, "width"));
	},
	getHeight : function(e) {
		return daum.String.toFloat($JE.getStyle(e, "height"));
	},
	getSize : function(e) {
		return {
			"width" : daum.String.toFloat($JE.getStyle(e, "width")),
			"height" : daum.String.toFloat($JE.getStyle(e, "height"))
		};
	},
	tween : function (obj, prop, end, opts) {
//		options : begin, duration, ease
//		prop이 opacity일 경우는 begin 없으면 디폴트 1
		var opts = opts || {}, _begin;
		if (prop !== "opacity") {
			_begin = (!opts.begin)
						? $JE.getStyle(obj, prop)
						: opts.begin;
		} else {
			if (opts.begin === undefined) {
				daum.Element.setOpacity(obj, 1);
				_begin = 1;
			} else {
				daum.Element.setOpacity(obj, opts.begin);
				_begin = opts.begin;
			}
		}

		this.obj = obj.style;
		this.prop = prop;
		this.begin = this.pos = opts.begin || (/px/.test(_begin + ""))
															? parseFloat(_begin)
															: _begin;
		this.change = (typeof end === "number")
							? end - this.begin
							: end;
		this.time = this.pastTime = 0;
		this.isPlaying = false;
		this.duration = (opts.duration > 0)
								? opts.duration
								: .7;
		this.ease = (opts.ease)
						? daum.effects.ease[opts.ease]
						: function (t, b, c, d) { 
							return c * t / d + b;
						};

		this.getPastTime = function() {
			return (new Date() - 0) - this.time;
		};
		this.setPastTime = function() {
			this.pastTime = this.getPastTime() - this.time * 1000;
		};
		this.getPosition = function(t) {
			if (typeof t !== "number") { t = this.time; }
			return (typeof this.begin === "number" && typeof this.change === "number")
						? this.ease(t, this.begin, this.change, this.duration)
						: this.change;
		};
		this.setPosition = function(p) {
			this.prevPos = this.pos;
			$JE.setStyle(obj, this.prop, (typeof p === "number" && this.prop !== "opacity")
																? daum.Number.px(Math.round(p))
																: p);
			this.pos = p;
		};
		this.changePosition = function() {
			this.setPosition(this.getPosition(this.time));
		};
		this.start = function() {
			this.isPlaying = true;
			this.setPastTime();
			this.enterTimeline();
		};
		this.stop = function() {
			this.isPlaying = false;
			this.time = this.pastTime = 0;
		};
		this.enterTimeline = function() {
			if (this.isPlaying) {
				this.checkTimeline((this.getPastTime() - this.pastTime) / 1000);
				setTimeout(daum.effects.delegate(this, this.enterTimeline), 0);
			}
		};
		this.checkTimeline = function(t) {
			if (t > this.duration) {
//				console.log("트위닝 끝");
				this.tim, delee = this.duration;
				this.changePosition();
				this.stop();
			} else {
//				console.log("트위닝 중");
				this.time = t;
				this.changePosition();
			}
		};
	},
//	toggle : function (fn) {
//		for (var i = 0, arrFn = [], args = arguments; i < args.length; ++i) {
//			arrFn.push(arguments[i]);
//		}
//	},
	delegate : function (o, fn) {
		return function() { return fn.call(o); }
//		var a = new Array();
//		var l = arguments.length ;
//		for(var i = 2 ; i < l ; i++) a[i - 2] = arguments[i] ;
//		return function() {
//			var aP = [].concat(arguments, a) ;
//			f.apply(o, aP);
//		}
	}
};
daum.effects.init();

(function() {
	if (!window.$JE) { window.$JE = daum.effects; }	
})();

Math.linearTween = function (t, b, c, d) {
	return c*t/d + b;
};
Math.easeInQuad = function (t, b, c, d) {
	return c*(t/=d)*t + b;
};
Math.easeOutQuad = function (t, b, c, d) {
	return -c *(t/=d)*(t-2) + b;
};
Math.easeInExpo = function (t, b, c, d) {
	return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
};
Math.easeInOutQuad = function (t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
};

(function(daum){
	
	var Element = {
		setStyles : function (el, styles) {
			for (var x in styles) {
				$JE.setStyle(el, x, styles[x]);
			}
		}
	};
	
	// 수정할 것
	
	var Ruler = {
		getSize : function(element){
			var s = {};
			s.width = element['width']? parseInt(element['width']) : element['offsetWidth'];
			s.height = element['height']? parseInt(element['height']) : element['offsetHeight'];
			return s;
		},
		getAbsPosition : function(element){
			var p = this.getRelPostion(element);
			while (element.offsetParent)	{
				element = element.offsetParent;
				p.x += element.offsetLeft;
				p.y += element.offsetTop;
				if (element != document.body && element != document.documentElement) {
					p.x -= element.scrollLeft;
					p.y -= element.scrollTop;
				}
			}
			return p;
		},
		getRelPostion : function(element){
			var p = { x: element.offsetLeft, y: element.offsetTop };
			return p;
		}
	};
	
	var Accordion = daum.effects.accordion = function(id,headerName,bodyName, options){
		this.element = $(id);
		this.options = options || {};
		this.headerName = headerName;
		this.bodyName = bodyName;
		this._initialize();
	};
	
	Accordion.prototype = {
		_initialize : function(){
			var eventType = this.options.eventType || 'click';
			var presentiveBody = this.expanded = this.options.presentiveBody || 0; 
			
			this.duration = this.options.duration || 750;
			this.easing = Math[this.options.easing] || Math.easeInQuad;
			this.headers = $C(this.element, this.headerName);
			this.bodies = $C(this.element, this.bodyName);
			this.tweeners = [];
			this.isTweening = false;
			this.oWidth = $JE.getWidth(this.bodies[0]);
//			console.log(this.oWidth);
			for(var i = 0; i < this.bodies.length; i++){
				if(i != presentiveBody){
					Element.setStyles(this.bodies[i], {width:0});
				}
			}
			
			for(var i = 0; i < this.headers.length; i++){
				//this.headers[i].id = this.headerName + '_' + i;
				daum.Event.addEvent(this.headers[i], eventType, daum.Function.bind(this._render, this, i));				
			}
			
		},
		_render : function(i){
			if(this.isTweening == false){
				if(this.expanded != i){
					this.contracted = this.expanded;
					this.expanded = i;
					this._begin();
				}
			}
		},
		_step : function(){
			var t = (new Date()).getTime();
			if (t >= this.duration + this.startTime){
				this._stop();
				return false;
			} else {
				var n = t - this.startTime;
				var pos = this.easing(n, 0, 1, this.duration);
				this.now = this.start + ((this.end - this.start) * pos);
				this.now = Math.round(this.now);
				this._update();
			}
			return true;
		},
		_update : function(){
			var width = this.oWidth - this.now;
			Element.setStyles(this.bodies[this.expanded], {width:this.now+'px'});
			Element.setStyles(this.bodies[this.contracted], {width:width+'px'});
		},
		_begin : function(){
			this.startTime = (new Date()).getTime();
			this.end = this.oWidth;
			this.start = 0;
			this.isTweening = true;
			this.tid = daum.Function.interval(daum.Function.bind(this._step, this), 14);
		},
		_stop : function(){
			if(this.tid){
				this.now = this.end;
				this._update();
				clearInterval(this.tid);
				this.tid = null;
				this.isTweening = false;
				return true;
			} else {
				return false;
			}
		}
	};
})(daum);

var DisplayManager = function(container,className){
	this._container = container;
	this._className = className;
	this._childs = daum.$C(this._container,className);		
	this._currentNode = this._childs[0];
};
DisplayManager.prototype = {
	show : function(idx){
		daum.Element.show(this._childs[idx]);	
	},
	hide : function(idx){
		daum.Element.hide(this._childs[idx]);
	},
	toggled : function(idx){
		daum.Element.hide(this._currentNode);
		daum.Element.show(this._childs[idx]);
		this._currentNode = this._childs[idx];		
	}	
};