slideshowDuration = 4000; // in Milliseconds

$(document).ready(function() {
    window.setInterval("slideshowEmeidi()", slideshowDuration);
});

function slideshowEmeidi() {
    if($('#slideshow img.front').length == 0) {
        $('#slideshow img:first').addClass('front');
    }
    current = $('#slideshow img.front');
    
    if($(current).next().length == 0) {
        // Restart
        next = $('#slideshow img:first');
    }
    else {
        next = $('#slideshow img.front').next();
    }
    
    $(current).css({zIndex: 100}).css({opacity: 1}).show();
    $(next).css({zIndex: 99}).css({opacity: 1}).show();
    
    //$(next).animate({opacity: 1}, slideshowDuration, function() {
    $(current).animate({opacity: 0}, slideshowDuration/2, function() {
        $(current).hide().removeClass('front');
        $(next).addClass('front').css({opacity: 1});
    });
}

function debugImg(identifier,descr) {
    obj = $(identifier);
    
    msg = '[' + descr + '] ';
    msg += ' src: ' + $(obj).attr('src');
    msg += ' zIndex: ' + $(obj).css('zIndex');
    msg += ' opacity: ' + $(obj).css('opacity');
    
    if($(obj).is(':visible')) {
        vis = 'true';
    }
    else {
        vis = 'false';
    }
    msg += ' visibility: ' + vis;
    
    console.log(msg);
}
