// Copyright (C) 2002  SJS Solutions Ltd

function ProductViews(imageIds, imgTagName)
{
    var i=0;
    var imgEl;
    if (document.getElementById) {
        imgEl = document.getElementById(imgTagName);
    } else {
        imgEl = document.all[imgTagName];
    }

    var nextID = function () {
        return imageIds[modulo(++i, imageIds.length)];
    };

    var previousID = function () {
        return imageIds[modulo(--i, imageIds.length)];
    };

    var updateImgSrc = function (id) {
        mySetTimeout(function () { imgEl.src = "image.pl?id=" + id; }, 0);

        return
    };

    this.next = function () {
        updateImgSrc(nextID());

        return;
    };

    this.previous = function () {
        updateImgSrc(previousID());

        return;
    };
}

function modulo(n, d)
{
    var x = n%d;
    
    if (x>=0) {
        return x;
    } else {
        return x+d;
    }
}
