var ola_a_todos = document.getElementById("ola_a_todos");
var os_q_vivem = document.getElementById("os_q_vivem");
var disc = document.getElementById("disc");
var legal = document.getElementById("legal");
var menina_chateada = document.getElementById("menina_chateada");
var menina_feliz = document.getElementById("menina_feliz");

var countRepeat = 0;
function animation() {

  TweenLite.delayedCall(1.5, function () {
    const duration = 0.7;
    const duration2 = 1.5;
    TweenLite.to(ola_a_todos, duration, { scale: 1, ease: Bounce.easeOut });
    TweenLite.to(ola_a_todos, duration, { opacity: 1, ease: Power2.easeOut });
    TweenLite.to(os_q_vivem, duration, { top: 25, ease: Bounce.easeOut }).delay(0.7);
    TweenLite.to(menina_chateada, duration2, { opacity: 0, ease: Power0.easeNone });

  });
  TweenLite.delayedCall(4, function () {
    const duration = 0.5;
    TweenLite.to(menina_feliz, duration, { opacity: 1, ease: Power0.easeNone });
    TweenLite.to(ola_a_todos, duration, { left: '100%', ease: Power0.easeNone });
    TweenLite.to(os_q_vivem, duration, { left: '100%', ease: Power0.easeNone });
  });
  TweenLite.delayedCall(6, function () {
    const duration = 0.5;
    TweenLite.to(menina_feliz, duration, { opacity: 0, ease: Power0.easeNone });
    TweenLite.to(disc, 0, { opacity: 1, ease: Power0.easeNone });
    TweenLite.to(disc, duration, { left: 95, ease: Power0.easeNone });
    TweenLite.to(legal, duration, {  right: 2, ease: Power0.easeNone });
    });

  TweenLite.delayedCall(10, function () {
    restartAnim();
  });
}

TweenLite.delayedCall(1, function () {
  animation();
});

function restartAnim() {

  if (countRepeat < 2) {
    const duration = 0.5;
    countRepeat++;
    TweenLite.to(disc, duration, { left: 300, ease: Power0.easeNone });
    TweenLite.to(disc, duration, { opacity: 0, ease: Power0.easeNone }).delay(1);
    TweenLite.to(legal, duration, { right: '-100%', ease: Power0.easeNone });
    TweenLite.to(ola_a_todos, 0, { left: '35%' });
    TweenLite.to(os_q_vivem, 0, { left: '30%' });
    TweenLite.to(os_q_vivem, 0, { top: '100%' });
    TweenLite.to(ola_a_todos, 0, { scale: 3 });
    TweenLite.to(ola_a_todos, 0, { opacity: 0 });
    TweenLite.to(menina_chateada, duration, { opacity: 1, onComplete: animation });
  }
}