var obj = 0;
var interval = 50, stopInterval = 2000, step = -1;

var out, box1, box2;
var width = 0, height = 0;
var top1, top2;

function moveBanner()
{
	top1 += step;
	top2 += step;

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

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

	box1.style.top = top1;
	box2.style.top = top2;

	if ((top1 <= 0 && top1 % 20 == 0) || (top2 <= 0 && top2 % 20 == 0))
	{
		clearTimeout(obj);
		obj = setTimeout("moveBanner()", stopInterval);
		return;
	}

	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 (height < 0)
	{
		height = 0;
	}
	else if (height < outHeight)
	{
		height = outHeight;
	}

	this.out = out;
	this.box1 = box1;
	this.box2 = box2;
	this.width = width;
	this.height = height + space;
	top1 = 0;
	top2 = this.height;

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

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

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

	startBanner(stopInterval);
}

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

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

function setBackward()
{
//	interval = 30;
	step = 1;
	clearTimeout(obj);
	moveBanner();
}

function setForward()
{
//	interval = 30;
	step = -1;
	clearTimeout(obj);
	moveBanner();
}

function setSlow()
{
	if (step == -1)
	{
		interval = 80;
	}
	else
	{
		interval = 30;
	}
}

function setNormal()
{
	interval = 50;
}

function setFast()
{
	if (step == -1)
	{
		interval = 30;
	}
	else
	{
		interval = 80;
	}
}
