/* -*- Mode: C++ -*-

   Copyright (c) 2005 The Cupcake Fairy.  All Rights Reserved.

 */

var scrollstrip = { };

function Scrollstrip(numCells, images, target, id)
{
    this.numCells   = numCells;
    this.images     = images;
    this.target     = target;
    this.id         = id || "0";
    this.currentPos = 0;
    this.maxPos     = this.images.length - this.numCells;
}

Scrollstrip.prototype.update = function scrollstrip_update()
{
    for (var i = 0; i < this.numCells; ++i) {
        var img = document.getElementById("scrollstrip:" + this.id + ":" + i);
        var cell = this.images[this.currentPos + i];
        img.src = cell.thumb;
        img.alt = cell.alt;
    }

    document.getElementById('scrollstrip:' + this.id + ':left').src =
        (this.currentPos <= 0)
        ? "scrollstrip-left-disabled.png"
        : "scrollstrip-left.png";

    document.getElementById('scrollstrip:' + this.id + ':right').src =
        (this.currentPos >= this.maxPos)
        ? "scrollstrip-right-disabled.png"
        : "scrollstrip-right.png";
}

Scrollstrip.prototype.scroll = function scrollstrip_scroll(offset)
{
    this.currentPos += offset;
    if (this.currentPos > this.maxPos)
        this.currentPos = this.maxPos;
    if (this.currentPos < 0)
        this.currentPos = 0;
    this.update();
}

Scrollstrip.prototype.select = function scrollstrip_select(index)
{
    var cell = this.images[this.currentPos + index];
    var img = document.getElementById(this.target);
    img.src = cell.url;
    img.alt = cell.alt;
}
