﻿
var ScrollNews = function(frameId, contentId, direction, speed, step, w, h) {
    var thisObj = this;
    this.active = 1;
    this.nXlocation = 0;
    this.nYlocation = 0;
    this.nFrameHeight = h;
    this.nFrameWidth = w;
    this.nSpeed = speed;
    this.nStep = step;
    this.strDirection = direction;
    this.scrollerStat = true;
    this.objFrame = document.getElementById(contentId);

    f = document.getElementById(frameId);
    f.style.height = h + 'px';
    f.style.width = w + 'px';

    this.MoveScroller = function() {
        switch (this.strDirection) {
            case 'Up':
                this.nXlocation -= this.active * this.nStep;
                this.objFrame.style.top = this.nXlocation + "px";
                break;
            case 'Down':
                this.nXlocation += this.active * this.nStep;
                this.objFrame.style.top = this.nXlocation + "px";
                break;
            case 'Right':
                this.nYlocation += this.active * this.nStep;
                this.objFrame.style.left = this.nYlocation + "px";
                break;
            case 'Left':
                this.nYlocation -= this.active * this.nStep;
                this.objFrame.style.left = this.nYlocation + "px";
                break;
        }
    }

    this.CheckScroller = function() {
        switch (this.strDirection) {
            case 'Up':
                if ((0 - this.nXlocation) > this.objFrame.offsetHeight)
                    this.nXlocation = this.nFrameHeight;
                break;
            case 'Down':
                if (this.nXlocation > this.nFrameHeight)
                    this.nXlocation = -this.objFrame.offsetHeight;
                break;
            case 'Right':
                if (this.nYlocation > this.nFrameWidth)
                    this.nYlocation = -this.objFrame.offsetWidth;
                break;
            case 'Left':
                if ((0 - this.nYlocation) > this.objFrame.offsetWidth)
                    this.nYlocation = this.nFrameWidth;
                break;
        }
    }

    this.RunScroll = function() {
        if (this.scrollerStat) {
            this.MoveScroller();
            this.CheckScroller();
        }
    }

    this.StartScroll = function() {

        setInterval(function() { thisObj.RunScroll(); }, thisObj.nSpeed);
    }
}


