$(document).ready(function(){
        
    container_width = $("#carousel").width();
    li_width = $("#carousel li:first").width();
    center = (container_width/2) - (li_width/2);
        
    $("#carousel li").each(function(i){
        $(this).css({
            "position": "absolute",
            "left":     "-" + li_width + "px",
            "opacity" : 0
        });
    });
    
    $("#carousel li:first").addClass("active").css({
        "left": center + "px",
        "opacity" : 1
    });
    
    window.setInterval("moveItems()", 8000);
    
});

function moveItems()
    {
        var $active = $("#carousel li.active").length > 0 ? $("#carousel li.active") : $("#carousel li:first");
        var $next = $active.next().length > 0 ? $active.next() : $("#carousel li:first");

        $active.removeClass("active");
        $next.addClass("active");
        
        $next.animate({
            "left": center + "px",
            "opacity" : 1
            },
            2000
        );
        
        $active.animate({
            "left": (container_width + li_width) + "px",
            "opacity": 0
            },
            2000,
            function(){
                $(this).css("left", "-" + li_width + "px");
            }
        );
    }