function Screen(pLeft, pTop, pWidth, pHeight, pMode, pDirection, pLayer) {
    this.left = pLeft;
    this.top = pTop;
    this.width = pWidth;
    this.height = pHeight;  
    this.mode = pMode;
    this.direction = pDirection;
    this.layer = pLayer;
    this.offset = 0;

    if (this.mode == "v") {
        this.limit = this.height;
    } else if (this.mode == "h") {
        this.limit = this.width;
    }

    function reachEnd() {
        if (this.offset < this.limit) {
            return false;
        }
        if (this.mode == "v" && this.direction == "up") {
            return (this.top <= (this.height * -1));        
        } else if (this.mode == "v" && this.direction == "down") {
            return (this.top >= this.height);        
        } else if (this.mode == "h" && this.direction == "left") {
            return (this.left <= (this.width * -1));        
        } else if (this.mode == "h" && this.direction == "right") {
            return (this.left >= this.width);        
        }
    }

    function getSafeAmount(pAmount) {
        return (this.limit < this.offset + pAmount) ? (this.limit - this.offset) : pAmount;
    }

    function proceed(pAmount) {
        var safeAmount = this.getSafeAmount(pAmount);
        this.offset += safeAmount;
        
        if (this.mode == "v" ) {
            if (this.direction == "up") {
                this.top -= safeAmount;
            } else if (this.direction == "down") {
                this.top += safeAmount;
            }
            this.layer.style.pixelTop = this.top;
        } else if (this.mode == "h") {
            if (this.direction == "left") {
                this.left -= safeAmount;
            } else if (this.direction == "right") {
                this.left += safeAmount;
            }
            this.layer.style.pixelLeft = this.left;
        }
    }

    function setHtml(pHtml){
        this.layer.innerHTML = pHtml;
    } 

    function reset(){
        this.offset = 0;
    } 

    this.reachEnd = reachEnd;   
    this.getSafeAmount = getSafeAmount;   
    this.proceed = proceed;   
    this.setHtml = setHtml;   
    this.reset = reset;   
}

