$(function() {
  $('.intro').parallax("60%", -0.2);
  $('.bistro').parallax("0%", 0.2);
  $('.bistro > div').parallax("2%", 1.2);
  $('a[href^="#"]').on('click',
    function() { $.scrollTo($(this).attr('href'), 1000); }
  );
  if ($('.ecrans').length > 0) {
    var $window = $(window);
    var offset = parseInt(Math.random()*2000);
    var $ecrans = $('.ecrans');
    var pos = $window.scrollTop();
    $ecrans.css('background-position', (offset + pos/2) + 'px 0px');
    $window.bind('scroll', function() {
      var pos = $window.scrollTop();
      $ecrans.css('background-position', (offset + pos/2) + 'px 0px');
    });
  }
  if ($('div[id|=chiffres]').length) {
    var $chiffres_section = $('div[id|=chiffres]');
    $chiffres_section.css('position', 'relative');
    var total = $chiffres_section.attr('id').split('-')[1];
    var $counter = $('<span id="counter"></span>').appendTo($chiffres_section.find('> div'));
    var options = {
      useEasing : true,
      useGrouping : true,
      separator : ' ',
      prefix : '',
      suffix : ' usagers'
    };
    var count = new CountUp("counter", 1234, parseInt(total), 0, 4.5, options);
    $chiffres_section.on('inview', function() { count.start(); });
  }
});
