function AlbumSlideshow(container, transitionTime, srcArray, serverName, padColor) {
    this.Container = container;
    this.Images = new Array();
    this.SrcArray = srcArray;
    this.ServerName = serverName;
    this.PadColor = padColor;
    this.CurrentIndex = (this.SrcArray.length > 0) ? 0 : -1;
    this.NextIndex = -1;
    this.TransitionTime = transitionTime;
    this.Timer = null;
    this.BackupTimer = null;
    this.LoadAttempts = 0;

    if (!window.AlbumSlideshows) {
        window.AlbumSlideshows = new Array();
    }

    window.AlbumSlideshows[this.Container.id] = this;

    this.Play = function() {
        this.Timer = setInterval("window.AlbumSlideshows['" + this.Container.id + "'].Next(true);", this.TransitionTime * 2000);
    };

    this.Stop = function() {
        clearInterval(this.Timer);
    };

    this.Next = function(animate) {
        if (AlbumSlideshow.GetOpacity(this.Container.firstChild) == 100 && this.SrcArray.length > 1) {
            var oldNext = this.NextIndex;
            this.NextIndex = (this.CurrentIndex >= this.SrcArray.length - 1) ? 0 : this.CurrentIndex + 1;

            if (!this.Images[this.NextIndex])
                this.Images[this.NextIndex] = new Image();

            if (this.Images[this.NextIndex].complete)
                this.Images[this.NextIndex].src = this.GetSrc(this.NextIndex);

            if (this.Images[this.NextIndex].complete || this.LoadAttempts == 5) {
                clearTimeout(this.BackupTimer);
                this.LoadAttempts = 0;
                this.Transition(this.TransitionTime, animate);
                this.CurrentIndex = this.NextIndex;
            }
            else {
                this.LoadAttempts++;
                this.BackupTimer = setTimeout("window.AlbumSlideshows['" + this.Container.id + "'].Next(" + animate + ");", 200);
                this.NextIndex = oldNext;
            }
        }
    };

    this.Previous = function(animate) {
        if (AlbumSlideshow.GetOpacity(this.Container.firstChild) == 100 && this.SrcArray.length > 1) {
            var oldNext = this.NextIndex;
            this.NextIndex = (this.CurrentIndex == 0) ? this.SrcArray.length - 1 : this.CurrentIndex - 1;

            if (!this.Images[this.NextIndex])
                this.Images[this.NextIndex] = new Image();

            if (this.Images[this.NextIndex].complete)
                this.Images[this.NextIndex].src = this.GetSrc(this.NextIndex);

            if (this.Images[this.NextIndex].complete || this.LoadAttempts == 5) {
                clearTimeout(this.BackupTimer);
                this.LoadAttempts = 0;
                this.Transition(this.TransitionTime, animate);
                this.CurrentIndex = this.NextIndex;
            }
            else {
                this.LoadAttempts++;
                this.BackupTimer = setTimeout("window.AlbumSlideshows['" + this.Container.id + "'].Previous(" + animate + ");", 200);
                this.NextIndex = oldNext;
            }
        }
    };

    this.GetSrc = function(index) {
        return "http://" + this.ServerName + "/prbin/prpv.dll?photo?i=" + this.SrcArray[index][0] + "&c=" + this.PadColor + "&p=" + this.SrcArray[index][1];
    };

    this.Transition = function(seconds, animate) {
        var img = document.getElementById(this.Container.id + "Image");

        if (img.filters && animate) {
            this.Container.style.filter = "blendTrans(duration=" + seconds + ")";
            this.Container.filters.blendTrans.Apply();
            this.Container.filters.blendTrans.Play();
            img.src = this.GetSrc(this.NextIndex);
        }
        else if (navigator.userAgent.toLowerCase().indexOf("applewebkit") == -1 && animate) // don't use fade effect for AppleWebKit browsers (it's flaky in Safari)
        {
            var delay = Math.round((seconds * 1000) / 202);

            for (var i = 0; i <= 100; i++)
                setTimeout("AlbumSlideshow.SetOpacity(document.getElementById('" + img.id + "'), " + (100 - i) + ");", delay * i);

            setTimeout("document.getElementById('" + img.id + "').src = '" + this.Images[this.NextIndex].src + "';", delay * 100);

            for (var i = 0; i <= 100; i++)
                setTimeout("AlbumSlideshow.SetOpacity(document.getElementById('" + img.id + "'), " + i + ");", delay * (i + 101));
        }
        else
            img.src = this.GetSrc(this.NextIndex);
    };

    this.AddImage = function(image) {
        this.Images.push(image);

        this.Container.style.width = (image.width > this.Container.offsetWidth) ? image.width + "px" : this.Container.offsetWidth + "px";
        this.Container.style.height = (image.height > this.Container.offsetHeight) ? image.height + "px" : this.Container.offsetHeight + "px";

        if (this.Images.length == 1) {
            this.CurrentIndex = 0;
            var img = document.createElement("img");
            img.src = image.src;
            img.setAttribute("id", this.Container.id + "Image");
            AlbumSlideshow.SetOpacity(img, 100);
            this.Container.appendChild(img);
        }
    };

    this.Init = function() {
        var img = document.createElement("img");
        img.src = this.GetSrc(0);
        img.setAttribute("id", this.Container.id + "Image");
        AlbumSlideshow.SetOpacity(img, 100);
        this.Container.appendChild(img);
    }
}

AlbumSlideshow.GetOpacity = function(node) {
    var opacity = Math.round(node.SlideshowOpacity);
    return opacity;
};

AlbumSlideshow.SetOpacity = function(node, opacity) {
    if (opacity > 99)
        opacity = 99.99;
    else if (opacity < 0)
        opacity = 0;

    node.SlideshowOpacity = opacity;
    node.style.opacity = opacity / 100;
    node.style.MozOpacity = opacity / 100;
    node.style.KhtmlOpacity = opacity / 100;
    node.style.filter = "alpha(opacity=" + opacity + ")";
};