function Rullator() {
    this.carlist = new Array();
    this.curindex = 0;
    this.timeoutid;
    this.intransit = false;
    this.directionoffset = 5;
    this.clipwidth = 251;
}

Rullator.prototype.addItem = function(url, imgurl, title, price, className) {
    var newdiv = document.createElement("div");
    var imglink = document.createElement("a");
    imglink.href = url;
    imglink.className = className;
    var img = document.createElement("img");
    img.src = imgurl;
    imglink.appendChild(img);

    var textlink = document.createElement("a");
    textlink.href = url;
    textlink.className = "adrollerText"
    newdiv.appendChild(imglink);
    textlink.appendChild(document.createTextNode(title));
    textlink.appendChild(document.createElement("br"));
    textlink.appendChild(document.createTextNode(price));
    newdiv.appendChild(textlink);
    this.carlist[this.carlist.length] = newdiv;
}

Rullator.prototype.stop = function() {
    if (!(undefined == this.timeoutid)) {
        clearInterval(this.timeoutid);
        this.timeoutid = void 0;
    }
}

Rullator.prototype.writeItem = function(elname, direction, plugType) {
    var srcel = document.getElementById(elname);

    // Remove existing nodes
    if (srcel.hasChildNodes()) {
        while (srcel.childNodes.length > 0) {
            srcel.removeChild(srcel.firstChild);
        }
    }
    //alert("clip is" + srcel.style.clip);
    //alert("left edge is " + srcel.style.left);

    // If curindex + direction is within array bounds, use this value, otherwise roll over
    //this.curindex = (curindex + direction) % carlist.length;
    this.curindex = (0 > this.curindex + direction ? this.carlist.length - this.curindex + direction :
        (!(this.curindex + direction < this.carlist.length) ? this.curindex + direction - this.carlist.length :
         this.curindex + direction));

    var nextindex = (this.curindex + 1 < this.carlist.length ? this.curindex + 1 : this.curindex + 1 - this.carlist.length);
    srcel.appendChild(this.carlist[this.curindex]);
    srcel.appendChild(this.carlist[nextindex]);
    srcel.style.left = "0pt";
    srcel.style.clip = "rect(0," + this.clipwidth + "px,71px, 0)";

    if (0 == direction && undefined == this.timeoutid) {
        this.timeoutid = setInterval(plugType +".slide(\"" + elname + "\", 1, \""+ plugType +"\")", 8100);
    }
}

Rullator.prototype.slide = function(elname, direction, plugType) {
    
    var srcel = document.getElementById(elname);
    if (-1 == direction) {
        this.writeItem(elname, -1, plugType);
    }
    srcel.style.left = ((0 > direction ? -this.clipwidth + 10 - direction : -direction)) + "px";
    srcel.style.clip = "rect(0," + ((0 > direction ? this.clipwidth + this.clipwidth - 10 : this.clipwidth) + direction)
            + "px,71px," + ((0 > direction ? this.clipwidth - 10 : 0) + direction) + "px)";

    if (direction > 0) {
        if (direction > 1 || !this.intransit) {
            if (direction < this.clipwidth - 10) {
                direction += this.directionoffset;
                setTimeout(plugType +".slide(\"" + elname + "\", " + direction + ", \""+ plugType +"\")", 10);
                this.intransit = true;
                return;
            }
            this.intransit = false;
            this.directionoffset = 5;
        }
        else {
            this.directionoffset += this.directionoffset; // double up
        }
    }
    else if (direction < 0) {
        if (direction < -1 || !this.intransit) {
            if (direction > -this.clipwidth + 10) {
                direction -= this.directionoffset;
                setTimeout(plugType +".slide(\"" + elname + "\", " + direction + ", \""+ plugType +"\")", 10);
                this.intransit = true;
                return;
            }
            this.intransit = false;
            this.directionoffset = 5;
        }
        else {
            this.directionoffset += this.directionoffset; // double up
        }
    }
    if (-1 < direction) {
        this.writeItem(elname, (direction > 0 ? 1 : 0), plugType);
    }
}

