﻿
//滚动插件
function PARoll(a) {
    this.TheA = a;
    this.TheA.IsPlay = 1;
    this.$(a.box).style.overflow = "hidden";
    if (a.width != "")
    { this.$(a.box).style.width = a.width; }
    if (a.height != "")
    { this.$(a.box).style.height = a.height; }
    this.$(a.box2).innerHTML = this.$(a.box1).innerHTML;
    this.$(a.box).scrollTop = this.$(a.box).scrollHeight;
    this.$(this.TheA.box).scrollTop = 0;
    this.Marquee();
    this.$(a.box).onmouseover = function () { eval(a.objname + ".clearIntervalRoll();"); }
    this.$(a.box).onmouseout = function () { eval(a.objname + ".setTimeoutRoll();") }
}
PARoll.prototype.$ = function (Id) {
    return document.getElementById(Id);
}
PARoll.prototype.getV = function () {
    alert(this.$(this.TheA.box2).offsetWidth - this.$(this.TheA.box).scrollLeft);
    alert(this.$(this.TheA.box2).offsetWidth);
    alert(this.$(this.TheA.box).scrollLeft);
}
PARoll.prototype.Marquee = function () {
    this.MyMar = setTimeout(this.TheA.objname + ".Marquee();", this.TheA.speed);
    if (this.TheA.IsPlay == 1) {
        if (this.TheA.direction == "top") {
            if (this.$(this.TheA.box).scrollTop >= this.$(this.TheA.box2).offsetHeight)
                this.$(this.TheA.box).scrollTop -= this.$(this.TheA.box2).offsetHeight;
            else {
                this.$(this.TheA.box).scrollTop++;
            }
        }

        if (this.TheA.direction == "down") {
            if (this.$(this.TheA.box1).offsetTop - this.$(this.TheA.box).scrollTop >= 0)
                this.$(this.TheA.box).scrollTop += this.$(this.TheA.box2).offsetHeight;
            else {
                this.$(this.TheA.box).scrollTop--;
            }
        }
        if (this.TheA.direction == "left") {
            if (this.$(this.TheA.box2).offsetWidth - this.$(this.TheA.box).scrollLeft <= 0)
                this.$(this.TheA.box).scrollLeft -= this.$(this.TheA.box1).offsetWidth;
            else {
                this.$(this.TheA.box).scrollLeft++;
            }
        }

        if (this.TheA.direction == "right") {
            if (this.$(this.TheA.box).scrollLeft <= 0)
                this.$(this.TheA.box).scrollLeft += this.$(this.TheA.box2).offsetWidth;
            else {
                this.$(this.TheA.box).scrollLeft--;
            }
        }

    }
}
PARoll.prototype.clearIntervalRoll = function () {
    this.TheA.IsPlay = 0;
}
PARoll.prototype.setTimeoutRoll = function () {
    this.TheA.IsPlay = 1;
}


function replaceAll(str, str1, str2) {
    str = str.toLowerCase();
    while (str.indexOf(str1) >= 0) {
        str = str.replace(str1, str2);
    }
    return str;
}

