var currentSlide = 1;
var previousSlide = 1;
var numSlides = 3;
var showInt = null;
function switchSlide(slide)
{
    var nextSlide = slide;
    if (!slide) {
        nextSlide = currentSlide + 1;
    }

    if (nextSlide > numSlides) {
        nextSlide = 1;
    }

    var newLeft = (nextSlide - 1) * 599;
    $("#showstage").animate({
        left: '-' + newLeft + 'px'
    }, 1000, 'swing', function() {
        for (var i = 1; i <= numSlides; i++) {
            $('#show_button_' + i).attr('src', '/images/showbutton.png');
        }

        $('#show_button_' + currentSlide).attr('src', '/images/greendot.png');
    });

    previousSlide = currentSlide;
    currentSlide = nextSlide;
}

function stopAuto()
{
    if (showInt != null) {
        clearInterval(showInt);
    }
}

$(document).ready(function() {
    for (var i = 1; i <= numSlides; i++) {
        $('#show_button_' + i).bind('click', function(e) {
            stopAuto();
            var targetSlide = parseInt(e.currentTarget.id.replace('show_button_', ''));
            switchSlide(targetSlide);
        });
    }

    showInt = setInterval('switchSlide();', 10000);
})
