var transition = 700;
var duration = 5000;
function slideshow()
{
    var $active = $('#slideshow IMG.active');
    if($active.length==0)
    {
        $active = $('#slideshow IMG:last');
    }
    var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0},transition,function() {$active.removeClass('active last-active');});
}
function pausePlay()
{
    var button = document.getElementById("playpause");
    if(button.alt == "Pause")
    {
        button.src = "images/images_play.gif";
        button.alt = "Play";
        clearInterval(interval);
    }
    else
    {
        button.src = "images/images_pause.gif";
        button.alt = "Pause";
        interval = setInterval(slideshow,duration);
    }
}
function next()
{
    document.getElementById("nextbutton").onclick = function()
    {
        return false;
    }
    clearInterval(interval);
    document.getElementById("playpause").src = "images/images_play.gif";
    document.getElementById("playpause").alt = "Play";
    slideshow();
    window.setTimeout(enableNext,transition+100);
}
function enableNext()
{
    document.getElementById("nextbutton").onclick = function()
    {
        next();
        return false;
    }
}
function prev()
{
    document.getElementById("prevbutton").onclick = function()
    {
        return false;
    }
    clearInterval(interval);
    document.getElementById("playpause").src = "images/images_play.gif";
    document.getElementById("playpause").alt = "Play";
    var $active = $('#slideshow IMG.active');
    if($active.length==0)
    {
        $active = $('#slideshow IMG:last');
    }
    var $next = $active.prev().length ? $active.prev() : $('#slideshow IMG:last');
    $active.addClass('last-active');
    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0},transition,function() {$active.removeClass('active last-active');});
    window.setTimeout(enablePrev,transition+100);
}
function enablePrev()
{
    document.getElementById("prevbutton").onclick = function()
    {
        prev();
        return false;
    }
}
$(function() {
    interval = setInterval(slideshow,duration);
});