function Slider(viewportId, bannerWidth, bannerHeight, animationDuration, pauseBetweenFrames, transition) {
    this._viewportId = viewportId;
    this._bannerWidth = bannerWidth;
    this._bannerHeight = bannerHeight;
    this._animationDuration = animationDuration;
    this._pauseBetweenFrames = pauseBetweenFrames;
    this._transition = transition;

    if (!transition) {
        this._transition = "slide";
    }
}

Slider.prototype.nextFrame = function() {

    var slider = this;
    var banner = $("#" + this._viewportId + " .banner-frame:first");
    var nextBanner = $("#" + this._viewportId + " .banner-frame:nth-child(2)");

    if (nextBanner) {
        var flash = $(nextBanner).find("object")[0];
        if (flash) {
            try {
                flash.Rewind();
                flash.Play();
            } catch (ex) {
                //Firefox may throw, but works anyway so ignore
            }
        }
    }

    switch (this._transition) {
        case "fade":
            //Fade transition
            var fadeDuration = this._animationDuration / 2.0;
            banner.fadeOut(fadeDuration, function() {
                $(this).remove();
                $(this).insertAfter("#" + slider._viewportId + " .banner-frame:last");

                nextBanner.fadeIn(fadeDuration);

                window.setTimeout(function() { slider.nextFrame() }, slider._pauseBetweenFrames);
            });

            break;
        default:
            //Slide transition
            banner.animate({
                marginLeft: "-" + this._bannerWidth + "px"
            }, this._animationDuration, "linear", function() {
                $(this).remove();
                $(this).css({ marginLeft: "0px" });
                $(this).insertAfter("#" + slider._viewportId + " .banner-frame:last");

                window.setTimeout(function() { slider.nextFrame() }, slider._pauseBetweenFrames);
            });

            break;
    }
}

Slider.prototype.start = function() {
    var slider = this;

    $("#" + this._viewportId + ", #" + this._viewportId + " .banner-frame").css({
        width: this._bannerWidth + "px",
        height: this._bannerHeight + "px",
        overflow: "hidden"
    });

    $("#" + this._viewportId + " .banner-frame").css({
        float: "left"
    });

    $("#" + this._viewportId + " .banner-container").css({
        width: (this._bannerWidth * $("#" + this._viewportId + " .banner-frame").length) + "px"
    });

    //If we are using the fade transition, hide all but the first frame so they fade in correctly
    if (this._transition == "fade") {
        $("#" + this._viewportId + " .banner-frame").hide();
        $("#" + this._viewportId + " .banner-frame:first").show();
    }

    window.setTimeout(function() { slider.nextFrame() }, this._pauseBetweenFrames);
}



