	function isIE() {
		if ( navigator.userAgent.indexOf("MSIE") >= 0 ) {
			return true;
		}
		else if ( navigator.userAgent.indexOf("Opera") >= 0 ) {
			return true;
		}
		else {
			return false;
		}
	
	}
	

	var init = function() {
		var centerParagraphScroller = new CenterParagraphScroller(CenterParagraphInfo.layout.split(','));
		centerParagraphScroller.init();
	}		
	
	//Áß°£ ¿µ¿ª Æ÷Áö¼Ç
	var CenterParagraphInfo = new Object();
	CenterParagraphInfo.layout = getCookie('e_layout');
	if (!CenterParagraphInfo.layout) CenterParagraphInfo.layout = 'e_3,e_4,e_2,e_5,e_6';
	CenterParagraphInfo.heightList = {'e_3':143,'e_4':143,'e_2':143,'e_5':143,'e_6':143}
	
	if (isIE()){
		CenterParagraphInfo.top = 600;
	}
	else {
		CenterParagraphInfo.top = 600;
	}
	
	CenterParagraphInfo.space = 16;	

	function setParagraphPosition () {
		var posTop = CenterParagraphInfo.top;
		var arrLayout = CenterParagraphInfo.layout.split(',');
		var arrStyle = [];
		for (var i = 0; i < arrLayout.length; i++) {
			arrStyle[arrStyle.length] = '#' + arrLayout[i] + '{top:' + posTop + 'px;}';
			posTop += CenterParagraphInfo.heightList[arrLayout[i]] + CenterParagraphInfo.space;
		}
		document.write('<style type="text/css">'+arrStyle.join('')+'</style>');
	}
	setParagraphPosition();
	
	
	var CenterParagraphScroller = function (pIdList) {
		var ti = new RepeatTimeout(this);
		ti.inheritTo(this); 
	
		this.pIdList = pIdList;
		this.objCloneList = null;
	
		this.bWorking = false;
		this.bCloneCreated = false;
	
		this.SHOW_CLONE = true;
		this.SHOW_ORIGNAL = false;
		this.SCROLL_ENABLE = true;
		this.SCROLL_DISABLE = false;
	
		this.hSpace = 16;
		this.scrollStep = 30;
		this.scrollCount = 0;
		this.scrollInfoList = null;
		this.objRepeatTimeoutList = new Array();
	
		this.setWaitingTime(0);
	};
	
	CenterParagraphScroller.prototype.iterate = function() {
		this.scroll();
	}
	
	CenterParagraphScroller.prototype.reArrange = function () {
		var len = this.pIdList.length;
		var posTop = CenterParagraphInfo.top;
		for (var i = 0; i < len; i++) {
			var objParagraph = document.getElementById(this.pIdList[i]);
			objParagraph.style.top = posTop + 'px';
			this.pIdList[i] = objParagraph.id;
			posTop += CenterParagraphInfo.heightList[objParagraph.id] + CenterParagraphInfo.space;
		}
		setCookie('e_layout', this.pIdList.join());
		this.bWorking = false;
	}
	
	CenterParagraphScroller.prototype.scroll = function () {
		var len = this.scrollInfoList.length;
		if(this.scrollCount  >= this.scrollStep) {
			for (var i=0; i < len; i++) {
				var scrollInfo = this.scrollInfoList[i];
				scrollInfo.obj.style.top = scrollInfo.to + "px";
			}
			this.reArrange();
			this.stop();
			return;
		} else {
			for (var i=0; i < len; i++) {
				var scrollInfo = this.scrollInfoList[i];
				var displacement = Math.round(Math.sin(this.scrollCount/this.scrollStep * Math.PI / 2)  * scrollInfo.dist);
				var curPos = scrollInfo.from + displacement;
				scrollInfo.obj.style.top = curPos + "px";
			}
		}
		this.scrollCount++;
	}
	
	CenterParagraphScroller.prototype.initScroll = function () {
		this.scrollInfoList = new Array();
		var idx = 0;
		var top = CenterParagraphInfo.top;
	
		for ( var i = 0; i < this.pIdList.length; i++ ) {
			var objParagraph = document.getElementById(this.pIdList[i]);
			var to = top;
			var from = objParagraph.offsetTop-CenterParagraphInfo.space;
			
			if(this.pIdList[i]=="e_3") {from = from +4;}
			
			if (from != to) {
				var scrollInfo = new Object();
				scrollInfo.obj = objParagraph;
				scrollInfo.from = from;
				scrollInfo.to = to;
				scrollInfo.dist = to - from;
				this.scrollCount = 0;
				this.scrollInfoList[idx++] = scrollInfo;
			}
			top += CenterParagraphInfo.heightList[objParagraph.id] + CenterParagraphInfo.space;
			
		}
	}
	
	CenterParagraphScroller.prototype.move = function( bUseScroll ) {
		if ( bUseScroll ) {
			this.initScroll();
			this.start();
		} else {
			this.reArrange();
		}
	}
	
	CenterParagraphScroller.prototype.clickUp = function( id ) {
		for ( var idx = this.pIdList.length - 1; idx >= 0 && this.pIdList[idx] != id; idx-- ); //search id's index (position);
	
		if(idx == 0) {
			var first = this.pIdList[0];
			var len = this.pIdList.length - 1;
			for (var i = 0; i < len; i++) {
				this.pIdList[i] = this.pIdList[i+1];
			}
			this.pIdList[i] = first;
		} else {
			var tmp = this.pIdList[idx];
			this.pIdList[idx] = this.pIdList[idx - 1];
			this.pIdList[idx - 1] = tmp;
		}
		this.move(this.SCROLL_ENABLE);
	}
	
	CenterParagraphScroller.prototype.handlerClickUp = function() {
		var objScroller = this.pScroller;
		if( objScroller.bWorking ) return;
		objScroller.bWorking = true;
		objScroller.clickUp.call(objScroller, this.paragraphId);
		objScroller = null;
	}
	
	CenterParagraphScroller.prototype.init = function () {
		for ( var i = this.pIdList.length - 1; i >= 0; i-- ) {
			var objParagraph = document.getElementById(this.pIdList[i]);
			var objList = objParagraph.getElementsByTagName("span");
			for (var j=0; j < objList.length; j++) {
				if(objList[j].className == "cbtn_up") {
					objList[j].onclick = this.handlerClickUp;
					objList[j].pScroller = this;
					objList[j].paragraphId = this.pIdList[i];
				}
			}
			if (i == 0) {
				var objParent = objParagraph.parentNode;
				objParent.style.height = objParent.offsetHeight + 'px';
			}
		}
	}
	
	var RepeatTimeout = function (obj) {
		this.objTimeout = null;
		this.bStop = false;
		this._waitingTime = 0;
		this.id = RepeatTimeout.list.length;
		RepeatTimeout.list[this.id] = obj;
	}
	RepeatTimeout.list = new Array();
	RepeatTimeout.prototype.start = function() {
		if (this.objTimeout) clearTimeout(this.objTimeout);
		this.bStop = false;
		this.objTimeout = setTimeout('RepeatTimeout.list[' + this.id + ']._iterate();', this.getWaitingTime());
	}
	RepeatTimeout.prototype.stop = function() {
		if (this.objTimeout) clearTimeout(this.objTimeout);
		this.bStop = true;
	}
	RepeatTimeout.prototype._iterate = function() {
		this.iterate();
		if(this.bStop) return;
		this.objTimeout = setTimeout('RepeatTimeout.list[' + this.id + ']._iterate();', this.getWaitingTime());
	}
	RepeatTimeout.prototype.setWaitingTime = function(msec) {
		this._waitingTime = msec
	}
	RepeatTimeout.prototype.getWaitingTime = function() {
		return this._waitingTime;
	}
	RepeatTimeout.prototype.inheritTo = function(obj) {
		for (var p in this) {
			obj[p] = this[p];
		}
	}	
	

