﻿// JScript 파일
// 전광판
function VerticalScroll() {
    this.name = "VerticalScroll";
    this.item = new Array();
    this.itemcount = 0;
    this.currentspeed = 0;
    this.scrollspeed = 50;
    this.pausedelay = 1000;
    this.pause = false;
    this.stop = false;
    this.height = 100;
    this.width = 100;
    this.rowCount = 2;
    this.targetDiv = null;

    this.addItem = function() {
        this.item[this.itemcount] = arguments[0];
        this.itemcount++;
    }

    this.start = function() {
        document.getElementById(this.targetDiv).innerHTML = this.display();
        document.getElementById(this.layerDiv).innerHTML = this.str_layer();

        this.currentspeed = this.scrollspeed;

        this.stop = true;
        setTimeout(this.name + '.scroll()', this.currentspeed);
        window.setTimeout(this.name + ".stop = false", this.pausedelay);

    };

    this.str_layer = function() {
        var strTemp = '';
        strTemp = '<table width="100%" border="0" cellspacing="0" cellpadding="0" id="header_layer_hot3">'
        for (var i = 0; i < this.itemcount; i++) {
            strTemp += '<tr><td>* '
            strTemp += this.item[i] + '</td></tr>'
        }
        strTemp += '</table>'
        return strTemp;
    }
    this.display = function() {
        var strTemp = '';
        strTemp = '<div id="' + this.name + '" style="height:' + this.height + 'px; width:' + this.width + 'px; position:relative; overflow:hidden; " OnMouseOver="' + this.name + '.onmouseover(); " OnMouseOut="' + this.name + '.onmouseout(); ">'
        for (var i = 0; i < this.itemcount; i++) {
            strTemp += '<div id="' + this.name + 'item' + i + '"style="left:0px; width:' + this.width + 'px; position:absolute; top:' + ((this.height / this.rowCount) * i) + 'px; ">'
            strTemp += '<div id="list' + i + '">' + this.item[i] + '</div>'
            strTemp += '</div>'
        }
        strTemp += '</div>'
        return strTemp;

    }

    this.scroll = function() {
        if (this.pause == true) {
            this.timerid = window.setTimeout(this.name + ".scroll()", this.pausedelay);
            this.pause = false;
        }
        else {
            this.currentspeed = this.scrollspeed;
            if (!this.stop) {
                for (i = 0; i < this.itemcount; i++) {
                    obj = document.getElementById(this.name + 'item' + i).style;
                    obj.top = (parseInt(obj.top) - 1) + 'px';
                    if (parseInt(obj.top) <= this.height / this.rowCount * (-1)) obj.top = (this.height / this.rowCount * (this.itemcount - 1)) + 'px';
                    if (parseInt(obj.top) == 0) this.currentspeed = this.pausedelay;
                }
            }
            this.timerid = window.setTimeout(this.name + ".scroll()", this.currentspeed);
        }
    };
    this.onmouseover = function() {
        if (this.pause) this.stop = true;
        this.pause = true;
    };

    this.onmouseout = function() {
        if (this.pause) this.stop = false;
        this.pause = false;
    };
}
