
var rollingDelay = 1400;
var increment = 130; 
var spaceDelay = 700;
$(document).ready(function() {
  
  if ($.cookie("homePageAnimation") == null || $.cookie("homePageAnimation") == "") {
    splashScreenAnimation();
  } else {
    $('#splashScreenWrapper').css('display', 'none');
  }
  $.cookie("homePageAnimation", "alreadyDisplayed");
  
});

function changeSizeWithTimeout($typeScreen, size, timeMs) {
  rollingDelay = rollingDelay + timeMs;
  setTimeout(function() {
    $typeScreen.css('width', size);
  }, rollingDelay);
}

function skipThisPage() {
  $('#splashScreenWrapper').css('display', 'none');
}

function splashScreenAnimation() {
var $typeScreen = $('#theHeartCanDoAnything');
  changeSizeWithTimeout($typeScreen, '91px', increment);  //T
  changeSizeWithTimeout($typeScreen, '121px', increment - 50); //h
  changeSizeWithTimeout($typeScreen, '149px', increment - 50); //e
  changeSizeWithTimeout($typeScreen, '149px', spaceDelay); //
  changeSizeWithTimeout($typeScreen, '203px', increment); //h
  changeSizeWithTimeout($typeScreen, '231px', increment); //e
  changeSizeWithTimeout($typeScreen, '261px', increment); //a
  changeSizeWithTimeout($typeScreen, '302px', increment); //r
  changeSizeWithTimeout($typeScreen, '321px', increment); //t
  changeSizeWithTimeout($typeScreen, '321px', spaceDelay); // 
  changeSizeWithTimeout($typeScreen, '364px', increment); //c
  changeSizeWithTimeout($typeScreen, '395px', increment); //a
  changeSizeWithTimeout($typeScreen, '423px', increment); //n
  changeSizeWithTimeout($typeScreen, '423px', spaceDelay); // 
  changeSizeWithTimeout($typeScreen, '471px', increment); //d
  changeSizeWithTimeout($typeScreen, '502px', increment); //o
  changeSizeWithTimeout($typeScreen, '502px', spaceDelay + 400); //
  changeSizeWithTimeout($typeScreen, '549px', increment); //a
  changeSizeWithTimeout($typeScreen, '577px', increment); //n
  changeSizeWithTimeout($typeScreen, '608px', increment); //y
  changeSizeWithTimeout($typeScreen, '637px', increment); //t
  changeSizeWithTimeout($typeScreen, '669px', increment); //h
  changeSizeWithTimeout($typeScreen, '697px', increment); //i
  changeSizeWithTimeout($typeScreen, '727px', increment); //n
  changeSizeWithTimeout($typeScreen, '757px', increment); //g
  var cursorDuration = 500;
  for (var i = 0; i < (rollingDelay); i = i + (cursorDuration * 2)) {
    setTimeout(function() {
      $('#cursor').addClass('cursorOn');
    },i);
    setTimeout(function() {
      $('#cursor').removeClass('cursorOn');
    },i + cursorDuration);
  }
  setTimeout(function() {
      $('#cursor').css('display', 'none');
  },rollingDelay);
  changeSizeWithTimeout($typeScreen, '860px', increment); //g
//  rollingDelay = rollingDelay + 1000;
  
  setTimeout(function() {
    $('#moliere').fadeIn(1200);
  },(rollingDelay - 1100)); 
  
  rollingDelay = rollingDelay + 700;
  setTimeout(function() {
    $('#splashScreenWrapper').fadeOut(1000);
  },rollingDelay); 
}
