/*
	ÁÖÀÇ : ObjectEx.js ÆÄÀÏ°ú °°ÀÌ »ç¿ëÇØ¾ßÇÔ

	»ý¼ºÀÚ
		name : °´Ã¼¸í
		auto : ÀÚµ¿½ºÅ©·Ñ ¿©ºÎ
		scrollSize : ½ºÅ©·Ñ °£°Ý
		interval : ½ºÅ©·Ñ ¼Óµµ
		waitTime : ÀÌ¹ÌÁö º¯°æ½Ã ±â´Ù¸®´Â ½Ã°£
		orientation : ½ºÅ©·Ñ ¹æÇâ


	º¯¼ö ¼³¸í
		orientation : ½ºÅ©·Ñ ¹æÇâ
			0 : °¡·Î ½ºÅ©·Ñ (SlideBox.SCROLL_HORIZONTAL)
			1 : ¼¼·Î ½ºÅ©·Ñ (SlideBox.SCROLL_VERTICAL)
*/

SlideBox.SCROLL_HORIZONTAL	= 0;	// °¡·Î ½ºÅ©·Ñ
SlideBox.SCROLL_VERTICAL	= 1;	// ¼¼·Î ½ºÅ©·Ñ


function SlideBox(name, auto, scrollSize, interval, waitTime, orientation)
{
	this.name = name;	// °´Ã¼ ÀÌ¸§

	this.x = 0;
	this.y = 0;
	this.width = 200;
	this.height = 200;

	// ½ºÅ©·Ñ °£°Ý
	this.scrollSize = (scrollSize == null) ? 5 : scrollSize;

	// ½ºÅ©·Ñ ÀÌµ¿ ½Ã°£ (¸îÃÊ¿¡ ÇÑ¹ø¾¿ ÀÌµ¿ÇÒ°ÍÀÎ°¡)
	this.interval = (interval == null) ? 50 : interval;	

	// ÇÑ È­¸é ½ºÅ©·ÑÈÄ ±â´Ù¸®´Â ½Ã°£
	this.waitTime = (waitTime == null) ? 1000 : waitTime;

	// ½ºÅ©·Ñ ¹æÇâ (°¡·Î, ¼¼·Î)
	this.orientation = (orientation == null) ? SlideBox.SCROLL_VERTICAL 
											 : orientation;

	// ÀÚµ¿ ½ºÅ©·Ñ ¿©ºÎ
	this.isAuto = (auto == null) ? false : auto;

	this.isStop = false;
	this.isOver = false;
	this.isChange = false;

	// ½ºÅ©·ÑÇÒ °´Ã¼µé ¹è¿­
	this.itemArry = new Array();

	// ½ºÅ©·Ñ ¹Ú½º
	this.box = null;

	// Å¸ÀÌ¸Ó ÇÚµé
	this.scrollHND = null;
}


/**
 *
 * ½ºÅ©·ÑÇÒ °´Ã¼ µî·Ï
 *
 * param	: String, Object	obj		(½ºÅ©·ÑÇÒ HTML °´Ã¼)
 * return	: ¾øÀ½
 */
SlideBox.prototype.addObject = function(obj)
{
	var objTmp = (typeof(obj) == "string") ? document.all[obj] : obj;
	this.itemArry.add(objTmp);

	var style = objTmp.style;
	style.position = "absolute";
	style.display = "block";
	style.visibility = "visible";
	style.posWidth = this.width;
	style.posHeight = this.height;

	var parent = objTmp.parentNode;
	parent.removeChild(objTmp);
	this.box.appendChild(objTmp);

	var objThis = window[this.name];
	objTmp.onmouseover = function(){objThis.pause();}
	objTmp.onmouseout = function(){objThis.resume();}

	var i = (this.itemArry.length - 1);
	switch(this.orientation)
	{
		case 0 :
		{
			style.posLeft = i*this.width;
			style.posTop = 0;
		}
		break;

		case 1:
		{
			style.posLeft = 0;
			style.posTop = i*this.height;
		}
		break;
	}
}


/**
 *
 * ½ºÅ©·Ñ ¹Ú½º »çÀÌÁî ¼³Á¤
 *
 * param	: int	width
 *			  int	height
 */
SlideBox.prototype.setSize = function(width, height)
{
	this.width = width;
	this.height = height;
}


/**
 *
 * ½ºÅ©·Ñ ÀÌµ¿ ½Ã°£ ¼³Á¤
 *
 * param	: int	interval (1/1000ÃÊ)
 *
 */
SlideBox.prototype.setInterval = function(interval)
{
	this.interval = interval;
}


/**
 *
 * ½ºÅ©·ÑÈÄ ±â´Ù¸®´Â ½Ã°£ ¼³Á¤
 *
 * param	: int	millisecond (1/1000ÃÊ)
 *
 */
SlideBox.prototype.setWaitTime = function(millisecond)
{
	this.waitTime = millisecond;
}


/**
 *
 * ÀÚµ¿ ½ºÅ©·Ñ ¼³Á¤
 *
 * param	: boolean	isAuto
 *
 */
SlideBox.prototype.setAuto = function(isAuto)
{
	this.isAuto = isAuto;
}


/**
 *
 * ½ºÅ©·Ñ ¹æÇâ ¼³Á¤
 *
 * param	: int	orientation
 *
 */
SlideBox.prototype.setOrientation = function(orientation)
{
	this.orientation = orientation;
}


/**
 *
 * ½ºÅ©·Ñ °£°Ý ¼³Á¤
 *
 * param	: int	size
 *
 */
SlideBox.prototype.setScrollSize = function(size)
{
	this.scrollSize = size;
}


/**
 *
 * ½ºÅ©·Ñ °£°Ý ¼³Á¤
 *
 * param	: ¾øÀ½
 * return	: int	(µî·ÏµÈ °´Ã¼ÀÇ °³¼ö)
 *
 */
SlideBox.prototype.getLength = function()
{
	return this.itemArry.length;
}


/**
 *
 * ÇØ´ç indexÀÇ ÀÌÀü °´Ã¼ ¹ÝÈ¯
 *
 * param	: int	index
 * return	: object
 *
 */
SlideBox.prototype.getBeforeObject = function(index)
{
	if(index == 0)
		return this.itemArry[this.getLength()-1];
	else
		return this.itemArry[index-1];
}


/**
 *
 * ½ºÅ©·Ñ ¹Ú½º¸¦ È­¸é¿¡ ±×¸°´Ù(?).
 *
 * param	: ¾øÀ½
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.paint = function()
{
	var style = "width:" + this.width + "px; height:" + this.height + "px; " +
				"left:" + this.x + "; top:" + this.y + "; overflow:hidden;" +
				"text-align:center;";
	this.content = "<div id=slidebox_" + this.name + " style='" + style + "'>" +
				   "</div>";

	document.write(this.content);
	this.box = document.all["slidebox_" + this.name];
}


/**
 *
 * ½ºÅ©·Ñ ÀÏ½Ã Á¤Áö
 *
 * param	: ¾øÀ½
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.pause = function()
{
	this.isOver = true;
}


/**
 *
 * ÀÏ½Ã Á¤ÁöµÈ ½ºÅ©·Ñ ´Ù½Ã ½ÃÀÛ
 *
 * param	: ¾øÀ½
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.resume = function()
{
	this.isOver = false;
}


/**
 *
 * ½ºÅ©·Ñ
 *
 * param	: ¾øÀ½
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.scroll = function()
{
	this.isStop = false;
	if(!this.isOver && !this.isChange)
	{
		switch(this.orientation)
		{
			case SlideBox.SCROLL_HORIZONTAL :
				this.scrollHorizontal();
			break;

			case SlideBox.SCROLL_VERTICAL :
				this.scrollVertical();
			break;
		}
	}

	if(!this.isStop) this.scrollHND = setTimeout(this.name+".scroll()", this.interval);
}


/**
 *
 * 1°³ÀÇ object½ºÅ©·ÑÈÄ ±â´Ù¸®´Â Ã³¸®
 *
 * param	: ¾øÀ½
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.wait = function()
{
	if(this.isAuto)
	{
		this.isChange = true;
		setTimeout(this.name+".isChange=false", this.waitTime);
	}
	else
	{
		this.isStop = true;
		this.stop();
	}
}


/**
 *
 * ½ºÅ©·Ñ ½ÃÀÛ
 *
 * param	: ¾øÀ½
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.start = function()
{
	this.scrollHND = setTimeout(this.name+".scroll();", this.waitTime);
}

SlideBox.prototype.stop = function()
{
	clearTimeout(this.scrollHND);
}


/**
 *
 * ½ºÅ©·Ñ ¹Ú½º³»ÀÇ °´Ã¼µé À§Ä¡ Á¶Á¤
 *
 * param	: int	diff
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.doPosition = function(diff)
{
	var len = this.itemArry.length;
	var obj;
	for(var i=0; i<len; i++)
	{
		obj = this.itemArry[i];
		if(this.orientation == SlideBox.SCROLL_HORIZONTAL)
			obj.style.posLeft -= diff;
		else
			obj.style.posTop -= diff;
	}
}


/**
 *
 * °¡·Î ½ºÅ©·Ñ Ã³¸®
 *
 * param	: ¾øÀ½
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.scrollHorizontal = function()
{
	var len = this.itemArry.length;
	var posX, obj;
	for(var i=0; i<len; i++)
	{
		posX = this.itemArry[i].style.posLeft - this.scrollSize;
		this.itemArry[i].style.posLeft = posX;
		if(posX <= (this.width * (-1)))
		{
			this.doPosition(this.width + posX);
			obj = this.getBeforeObject(i);
			posX = obj.style.posLeft + obj.style.posWidth;
			this.itemArry[i].style.posLeft = posX - (i == 0 ? this.scrollSize : 0);
			this.wait();
		}
	}

}


/**
 *
 * ¼¼·Î ½ºÅ©·Ñ Ã³¸®
 *
 * param	: ¾øÀ½
 * return	: ¾øÀ½
 *
 */
SlideBox.prototype.scrollVertical = function()
{
	var len = this.itemArry.length;
	var posY, obj;
	for(var i=0; i<len; i++)
	{
		posY = this.itemArry[i].style.posTop - this.scrollSize;
		this.itemArry[i].style.posTop = posY;
		if(posY <= (this.height * (-1)))
		{
			this.doPosition(this.height + posY);
			obj = this.getBeforeObject(i);
			posY = obj.style.posTop + obj.style.posHeight;
			this.itemArry[i].style.posTop = posY - (i == 0 ? this.scrollSize : 0);
			this.wait();
		}
	}

}