<!--
/**
 '==============================================================================
 '#	INFORMATION
 '------------------------------------------------------------------------------
 '#	@Author 				: JJang. Jang,Seon-Joo (jeuse7@hanmail.net)
 '# @Reference 			: N/A
 '#	@FileName 			: Scrolling.js
 '#	@Description 		: Scrolling 관련 클래스
 '#	@Version 				: 1.0.0
 '#	@CreateDate 		: 2003.12.22
 '#	@UpdateDate 		: N/A
 '#	@Requirement		: N/A
 '#	@Function List	:
 '#		N/A
 '#
 '==============================================================================
*/


/**
 * Scrolling Banner
 * @param _wrapperName		(Wrapper 객체명)
 * @param _wrapperWidth		(배너영역 가로크기)
 * @param _wrapperHeight	(배너영역 세로크기)
 * @param _scrollPixel		(이동 Pixel - 작을수록느림)
 * @param _setTime				(시간설정 빠르기 - 작을수록부드러움)
 */
var ScrollingBanner = function() { this.initialize.apply(this, arguments); }
ScrollingBanner.prototype = {
	initialize: function(_wrapperName, _wrapperWidth, _wrapperHeight, _scrollPixel, _setTime) {
		//Defined Configuration
		this.OBJ_WRAPPER = document.getElementById(_wrapperName) || document.getElementById("Banner-Wrapper");
		this.WRAPPER_WIDTH = _wrapperWidth || this.OBJ_WRAPPER.offsetWidth;
		this.WRAPPER_HEIGHT = _wrapperHeight || this.OBJ_WRAPPER.offsetHeight;
		if (_wrapperWidth) this.OBJ_WRAPPER.style.width = this.WRAPPER_WIDTH + "px";
		if (_wrapperHeight) this.OBJ_WRAPPER.style.height = this.WRAPPER_HEIGHT + "px";
		this.OBJ_WRAPPER.style.overflow = "hidden";
		this.OBJ_TARGET = this.OBJ_WRAPPER.getElementsByTagName("ul")[0];
		this.OBJ_TARGET.style.position = "absolute";
		this.SCROLL_PIXEL = _scrollPixel || 1;
		this.SET_TIME = _setTime || 20;
		this.BANNER_GAP = 5;
		this.OBJ_PREV = document.getElementById("Banner-Prev");
		this.OBJ_NEXT = document.getElementById("Banner-Next");
		//Defined Member Variables
		this.BANNER_LIST = new Array();
		this.TARGET_WIDTH = 0;
		this.TARGET_LEFT = 0;
		this.SCROLL_DIRECTION = "Left";
		this.SCROLL_INTERVAL = null;
		this.prepare();
		this.start();
	},
	
	prepare: function() {
		var index = 0;
		var targetSubNodes = this.OBJ_TARGET.childNodes;
		for (var i = 0; i < targetSubNodes.length; i++) {
			if (targetSubNodes[i].nodeType == 3 || targetSubNodes[i].tagName != "LI") continue;
			this.BANNER_LIST[index] = targetSubNodes[i];
			this.TARGET_WIDTH += parseInt(targetSubNodes[i].offsetWidth) + this.BANNER_GAP;
			++index;
		}
		if (this.TARGET_WIDTH > this.BANNER_GAP && (this.TARGET_WIDTH - this.BANNER_GAP) > this.WRAPPER_WIDTH) {
			this.OBJ_TARGET.style.width = this.TARGET_WIDTH + "px";
			this.setOverEvent(this.OBJ_WRAPPER);
			this.setOutEvent(this.OBJ_WRAPPER);
			for(var i = 0; i < this.BANNER_LIST.length; i++) {
				var targetAnchor = this.BANNER_LIST[i].getElementsByTagName("a")[0];
				if (targetAnchor) {
					this.setOverEvent(targetAnchor);
					this.setOutEvent(targetAnchor);
				}
			}
			if (this.OBJ_PREV) this.setDirectionEvent(this.OBJ_PREV, "Left");
			if (this.OBJ_NEXT) this.setDirectionEvent(this.OBJ_NEXT, "Right");
		}
	},
	
	setOverEvent: function(_target) {
		var __this = this;
		_target.onmouseover = _target.onfocus = function() {
			__this.stop.call(__this);
		}
	},
	
	setOutEvent: function(_target) {
		var __this = this;
		_target.onmouseout = _target.onblur = function() {
			__this.start.call(__this);
		}	
	},
	
	setDirectionEvent: function(_target, _direction) {
		var __this = this;
		_target.onclick = function() {
			__this.doChangeDirection.call(__this, _direction);
			return false;
		}
	},
	
	doChangeDirection: function(_direction) {
		this.SCROLL_DIRECTION = _direction;
		this.start();
	},
	
	start: function() {
		var __this = this;
		this.stop();
		this.SCROLL_INTERVAL = setInterval(function() { eval("__this.scroll"+__this.SCROLL_DIRECTION+"()"); }, this.SET_TIME);
	},
	
	stop: function() {
		if (this.SCROLL_INTERVAL) clearInterval(this.SCROLL_INTERVAL);
	},
		
	scrollLeft: function() {
		this.OBJ_TARGET.style.left = (this.TARGET_LEFT - this.SCROLL_PIXEL) + "px";
		this.TARGET_LEFT -= this.SCROLL_PIXEL;
		if (this.TARGET_LEFT <= (parseInt(this.BANNER_LIST[0].offsetWidth) + this.BANNER_GAP) * -1) {
				//this.BANNER_LIST[0].remove();
				this.OBJ_TARGET.removeChild(this.BANNER_LIST[0]);
				this.OBJ_TARGET.appendChild(this.BANNER_LIST[0]);
				this.BANNER_LIST.push(this.BANNER_LIST[0]);
				this.BANNER_LIST.shift();
				this.TARGET_LEFT = (this.BANNER_GAP * -1);
				this.OBJ_TARGET.style.left = this.TARGET_LEFT + "px";
		}
	},
	
	scrollRight: function() {
		this.OBJ_TARGET.style.left = (this.TARGET_LEFT + this.SCROLL_PIXEL) + "px";
		this.TARGET_LEFT += this.SCROLL_PIXEL;
		if (this.TARGET_LEFT >= 0) {
			var bannerCount = this.BANNER_LIST.length;
			//this.BANNER_LIST[bannerCount - 1].remove();
			this.OBJ_TARGET.removeChild(this.BANNER_LIST[bannerCount - 1]);
			this.OBJ_TARGET.insertBefore(this.BANNER_LIST[bannerCount - 1], this.BANNER_LIST[0]);
			this.BANNER_LIST.unshift(this.BANNER_LIST[bannerCount - 1]);
			this.BANNER_LIST.pop();
			//alert(parseInt(this.BANNER_LIST[0].offsetWidth))
			//this.TARGET_LEFT = ((parseInt(this.BANNER_LIST[0].offsetWidth) + this.BANNER_GAP) * -1);
			this.TARGET_LEFT = ((parseInt(this.BANNER_LIST[0].offsetWidth)) * -1);
			this.OBJ_TARGET.style.left = this.TARGET_LEFT + "px";
		}
	}
}
//-->