$(function () {
  function showSplash(bool) {
    if (bool) {
      $("#splashScreen").show();
    } else {
      $("#splashScreen").hide();
    }
  }

  function showLoadingSplash(bool) {
    if (bool) {
      $("#splashScreen").show();
      $("#loader").show();
    } else {
      $("#splashScreen").hide();
      $("#loader").hide();
    }
  }

  window.addEventListener('message', function(event) {
    var item = event.data;

    // Show or hide the splash screen without loading spinner
    if (item.type === "showSplash") {
      if (item.status == true) {
        showSplash(true)
      } else {
        showSplash(false)
      }
    }

    // Show or hide the loading splash screen
    if (item.type === "showLoadingSplash") {
      if (item.status == true) {
        showLoadingSplash(true)
      } else {
        showLoadingSplash(false)
      }
    }

    if (item.type === "setIMG") {
      document.getElementById("bgIMG").src = item.value;
    }
  })

  showLoadingSplash(false)
})