$(document).ready(function() {
  // Set the current teaser as the front one
  $('div.home-content-block').addClass('front');

  // Reorder the teasers randomly
  teaserFiles.sort(function(a, b) {
    return Math.random() - 0.5;
  });
  var whichFile = 0;

  var prepareNextTeaser = function() {
    $.get(teaserFiles[whichFile], function(data) {
      $(data).addClass('behind').appendTo('#home-content-block-bg');
      window.setTimeout(function() {
        $('div.home-content-block.front').fadeOut('slow', function() {
          $('div.home-content-block.front').hide().remove();
          $('div.home-content-block.behind').removeClass('behind').addClass('front');
          prepareNextTeaser();
        });
      }, 10000);
      whichFile = (whichFile + 1) % teaserFiles.length;
    });
  }
  
  prepareNextTeaser();
});
