$(document).ready(function() {
    var timeOut     = 5000;
    var current     = null;
    var timeOutFn   = null;
    var items       = $(".featuredImg");

    var startSlider = function() {
        if(items.length > 0) {
            timeOutFn = setTimeout(makeSlider, timeOut);
        } else {
            console.log("Poof..");
        }
    }

    var makeSlider = function() {
        if(current != null) {
            var currNo = jQuery.inArray(current, items) + 1;
            
            if(currNo == items.length) {
                var currNo = 0;
                var duration = 1800;
            } else {
                var duration = 900;
            }
            var newMargin   = ($(current).width() * currNo) + (4 * currNo);
            $("#featured a").animate({ 
                left: -newMargin + "px"
            }, { 
                queue:true, 
                duration: duration
            });
            current = items[currNo];
            startSlider();
        } else {
            var newMargin   = $(items[0]).width() * 1;
            $("#featured a").animate({
                left: -newMargin + "px"
            }, { 
                queue:true,
                duration: 900
            });
            current = items[1];
            startSlider();
        }
    }
    startSlider();
});