﻿
var scrollerwidth=456; // 스크롤러의 가로
var scrollerheight=405;   // 스크롤러의 세로
var scrollerbgcolor='#ffffff';  // 스크롤러 배경색
var scrollerbackground='';  // 스크롤러 배경이미지

var speed = 5;
var num = speed;
var itemCount = 0;

var scrollspeed='5000';
var waitingtime='2';

var i=0;
var messages=new Array();

var timermove1;
var timermove2;
var bStop = false;
var bScrolling = false;

function setButton(index)
{
    bScrolling = false;
    return;
    
    var idx = ( (index+1>=messages.length)?0:index+1 );

    for(k=0;k<itemCount;k++)
    {
        if(k==idx)
            document.getElementById("itembtn"+k).src = "/images/main/i_on.gif";
        else
            document.getElementById("itembtn"+k).src = "/images/main/i.gif";
    }
    
    if(bStop)
        num = 0;
}

function move1(whichdiv)
{
    if(bStop && !bScrolling)
        return;

    tdiv=eval(whichdiv)

    if (tdiv.style.pixelTop>0&&tdiv.style.pixelTop<=num)
    {
        tdiv.style.pixelTop=0;
        timermove1 = setTimeout("move1(tdiv)",scrollspeed);
        timermove2 = setTimeout("move2(second)",scrollspeed);
        return;
    }
    
    if (tdiv.style.pixelTop>=tdiv.offsetHeight*-1)
    {
        bScrolling = true;
        tdiv.style.pixelTop-=num;
        timermove11 = setTimeout("move1(tdiv)",waitingtime);
    }
    else
    {
        setButton(i);
        tdiv.style.pixelTop=scrollerheight;
        tdiv.innerHTML=messages[i];
        if (i>=messages.length-1)
            i=0;
        else
            i++;
    }
}

function move2(whichdiv)
{
    if(bStop && !bScrolling)
        return;

    tdiv2=eval(whichdiv)

    if (tdiv2.style.pixelTop>0&&tdiv2.style.pixelTop<=num)
    {
        tdiv2.style.pixelTop=0;
        timermove2 = setTimeout("move2(tdiv2)",scrollspeed);
        timermove1 = setTimeout("move1(first)",scrollspeed);
        return;
    }
    
    if (tdiv2.style.pixelTop>=tdiv2.offsetHeight*-1)
    {
        bScrolling = true;
        tdiv2.style.pixelTop-=num;
        timermove21 = setTimeout("move2(second)",waitingtime);
    }
    else
    {
        setButton(i);
        tdiv2.style.pixelTop=scrollerheight;
        tdiv2.innerHTML=messages[i];
        if (i>=messages.length-1)
            i=0;
        else
            i++;
    }
}

function startscroll()
{
    for(j=1; j<=itemCount; j++)
    {
        if(document.getElementById("divBestClassic"+j))
            messages[j-1]=document.getElementById("divBestClassic"+j).innerHTML;
    }
    
    if(messages.length >= 1)
    {
        first.innerHTML=messages[0];
        if (i>=messages.length-1)
            i=0;
        else
            i++;
    }
        
    if(messages.length >= 2)
    {
        second.innerHTML=messages[1];
        if (i>=messages.length-1)
            i=0;
        else
            i++;
    }
    
    setButton(itemCount-1);

    if(itemCount>1)
    {
        bScrolling = false;
        move1(first);
    
        second.style.top=scrollerheight;
        second.style.visibility='visible';
    }
}

function scrollnext()
{
    if(bScrolling)
        return;
    second.innerHtml = messages[parseInt(i)];
//    if (i>=messages.length-1)
//            i=0;
//        else
//            i++;
    first.innerHtml = messages[parseInt(i)+1>=itemCount?0:parseInt(i)+1];
//    if (i>=messages.length-1)
//            i=0;
//        else
//            i++;
    clearTimeout(timermove1);
    clearTimeout(timermove2);      

    bStop = false;
    if(itemCount > 1)
    {
        move1(first);
        move2(second);
    }
}

function scrollstart()
{
    bStop = false;
    num = speed;
    //bScrolling = false;

    if (!bScrolling)
    {
        clearTimeout(timermove1);
        clearTimeout(timermove2);
       
        timermove1 = setTimeout("move1(first)",scrollspeed);
        timermove2 = setTimeout("move2(second)",scrollspeed);
    }
}

function scrollstop()
{
    bStop = true;
   
    if(bScrolling)
    {
        num = speed;
        setTimeout("scrollstop",waitingtime);
    }
    else
    {
        num = 0;
        clearTimeout(timermove1);
        clearTimeout(timermove2);
    }
}

document.writeln('<span id="main" style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hiden;background-color:'+scrollerbgcolor+' ;background-image:url('+scrollerbackground+')">');
document.writeln('<div style="position:absolute;width:'+scrollerwidth+';height:'+scrollerheight+';clip:rect(0 '+scrollerwidth+' '+scrollerheight+' 0);left:0;top:0">');
document.writeln('<div id="first" style="position:absolute;width:'+scrollerwidth+';left:0;top:1;">');
document.write(messages[0]);
document.writeln('</div>');
document.writeln('<div id="second" style="position:absolute;width:'+scrollerwidth+';left:0;top:0;visibility:hidden">');
document.write(messages[1]);
document.writeln('</div>');

document.writeln('</div>');
document.writeln('</span>');




