﻿// JScript 파일
function ScrollLine() {
    this.objname = "Scroll";
    this.divname = "divname";
    this.item = new Array();
    this.itemcount = 0;
    this.currentspeed = 0;
    this.scrollspeed = 50;
    this.pausetime = 1000;
    this.pausemouseover = false;
    this.stop = false;
    this.height = 15;
    this.width = 100;
    this.i=0;
    this.cindex=0;
    this.refreash = 0;
    this.add = function () {
        var text = arguments[0];
        this.item[this.itemcount] = text;
        this.itemcount++;
    };
    this.linehtml = function(i) {
        var divHTML;
        divHTML = '';
        divHTML += '<div id="'+this.objname+'item'+i+'"style="left:0px; width:'+this.width+'; position:absolute; top:'+(this.height*i)+'px; ">';
        divHTML += this.item[i];
        divHTML += '</div>';
        return divHTML;
    }
    this.start = function () {
        if ( this.itemcount == 1 ) {
            this.add(this.item[0]);
        }
        this.display();
        this.currentspeed = this.scrollspeed;
        this.stop = true;
        setTimeout(this.objname+'.scroll()',this.currentspeed);
        window.setTimeout(this.objname+".stop = false", this.pausetime);
    };
    this.display = function () {
        var divHTML;
        divHTML = '<div id="'+this.objname+'" style="height:'+this.height+'; width:'+this.width+'; position:relative; overflow:hidden; " OnMouseOver="'+this.objname+'.onmouseover(); " OnMouseOut="'+this.objname+'.onmouseout(); ">';
        for(var i = 0; i < this.itemcount; i++) {
            divHTML += this.linehtml(i);
        }
        divHTML += '</div>';
        document.getElementById(this.divname).innerHTML=divHTML;
    };
    this.scroll = function () {
        if ( this.pause == true ) {
            window.setTimeout(this.objname+".scroll()",this.pausetime);
            this.pause = false;
        } else {
            this.currentspeed = this.scrollspeed;
            if ( !this.stop ) 
            {
                for (var i = 0; i < this.itemcount; i++) 
                {
                    obj = document.getElementById(this.objname+'item'+i).style;
                    obj.top = parseInt(obj.top) - 1;
                    if ( parseInt(obj.top) <= this.height * (-1) ) obj.top = this.height * (this.itemcount-1);
                    if ( parseInt(obj.top) == 0 ) 
                    {
                        this.currentspeed = this.pausetime;
                        this.i = i;
                    }
                }
            }
            if( !this.stop && i == this.itemcount && parseInt(obj.top) == 0 && this.refreash == 1 ) 
            {
                this.refreash = 0;
            } else {
                window.setTimeout(this.objname+".scroll()",this.currentspeed);
            }
        }
    };
    this.onmouseover = function () {
        if ( this.pausemouseover ) {
            this.stop = true;
        }
    };
    this.onmouseout = function () {
        if ( this.pausemouseover ) {
            this.stop = false;
        }
    };
    this.next = function() {
        height = this.height;
        for (i = 0; i < this.itemcount; i++) {
            obj = document.getElementById(this.objname+'item'+i).style;
            if ( parseInt(obj.top) < 1 ) {
                height = this.height + parseInt(obj.top);
                break;
            }
        }
        for (i = 0; i < this.itemcount; i++) {
            this.stop = true;
            obj = document.getElementById(this.objname+'item'+i).style;
            if ( parseInt(obj.top) < 1 ) {
                obj.top = this.height * (this.itemcount-1);
            } else {
                obj.top = parseInt(obj.top) - height;
            }
        }
    }
}


function back_top()
{
    x = document.body.scrollLeft;
    y = document.body.scrollTop;
    step = 2;

    while ((x != 0) || (y != 0)) 
    {
        scroll (x, y);
        step += (step * step / 100);
        x -= step;
        y -= step;

        if (x < 0) x = 0;
        if (y < 0) y = 0;
    } 
    scroll (0, 0);
}

