var obj = 0;
var interval = 30, step = 1;

var out, box1, box2;
var width = 0, height = 0;
var left1, left2;

function moveBanner()
{
	left1 += step;
	left2 += step;

	if (left1 >= width && step > 0)
	{
		left1 = width * -1;
	}
	else if (left1 <= -1 * width && step < 0)
	{
		left1 = width * 1;
	}

	if (left2 >= width && step > 0)
	{
		left2 = width * -1;
	}
	else if (left2 <= -1 * width && step < 0)
	{
		left2 = width * 1;
	}

	box1.style.left = left1;
	box2.style.left = left2;

	obj = setTimeout("moveBanner()", interval);
}

/*
 * out : 가장 바깥쪽 테두리 레이어
 * box1 : 첫번째 안쪽 레이어
 * box2 : 두번째 안쪽 레이어
 * width : 레이어의 넓이
 * height : 레이어의 높이
 * space : 첫번째 레이어와 두번째 레이어 사이의 넓이
 */

function initBanner(out, outWidth, outHeight, box1, box2, width, height, space)
{
	if (out == null || box1 == null || box2 == null)
	{
		alert("초기화 실패");
		return;
	}

	if (width < 0)
	{
		width = 0;
	}
	else if (width < outWidth)
	{
		width = outWidth;
	}

	this.out = out;
	this.box1 = box1;
	this.box2 = box2;
	this.width = width + space;
	this.height = height;
	left1 = 0;
	left2 = -this.width;

	out.style.width = outWidth;
	out.style.height = outHeight;
	out.style.overflow = "hidden";

	box1.style.position = "absolute";
	box1.style.left = left1;
	box1.style.top = 0;
	box1.style.width = width;

	box2.style.position = "absolute";
	box2.style.left = left2;
	box2.style.top = 0;
	box2.style.width = width;
	box2.innerHTML = box1.innerHTML;

	startBanner();
}

function startBanner()
{
	if (obj == 0)
	{
		obj = setTimeout("moveBanner()", interval);
	}
}

function stopBanner()
{
	clearTimeout(obj);
	obj = 0;
}

function setBackward()
{
	interval = 10;
	step = -1;
}

function setForward()
{
	interval = 10;
	step = 1;
}

function setSlow()
{
	if (step == 1)
	{
		interval = 50;
	}
	else
	{
		interval = 10;
	}
}

function setNormal()
{
	interval = 30;
}

function setFast()
{
	if (step == 1)
	{
		interval = 10;
	}
	else
	{
		interval = 50;
	}
}
