var flyerCounter = 0;

$(document).ready(function() {
    fly($('#banner .flyer:first'));
});

function fly(flyer) {
    flyer.fadeIn(1000, function() { nextFlyer(flyer); });
}

function pausecomp(millis) {
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while (curDate - date < millis);
} 

function nextFlyer(flyer) 
    {
        if (flyerCounter == 2) {
            pausecomp(2000);

            flyerCounter += 1;
            //$('.flyer').hide();
            $(function() {
                $('.flyer').css('display', 'none');
            });
            
            $('#flyers').show(); 
        }
        
        if (flyer.next().is('.flyer')) {
            flyerCounter += 1;
            fly(flyer.next());
        }
        else 
        {
            t = setTimeout(function() {
                $('#flyers').fadeOut(500, function() {

                //$('.flyer').hide();
                $(function() {
                    $('.flyer').css('display', 'none');
                });

                    $('#flyers').show();
                    fly($('#banner .flyer:first'));
                });
            }, 2000);

            flyerCounter = 0;
        }
}
