$(document).on('turbolinks:load', function() {

var action_alert = $('.action-alert');
var action_alert_count = action_alert.length;

setTimeout(function() {
  if (action_alert_count !== 0) {
    var temp_height = 0;
    for (var i = 1; i <= action_alert_count; i ++) {
      var alert = $('.action-alert:nth-of-type(' + i + ')');
      alert.animate({bottom: i + temp_height + 'rem'});
      temp_height += parseFloat(alert.css('height')) / 10;
    }

    // $("#action_alert_audio")[0].play();
  }
}, 200);

});

$(document).on('click', '.action-alert-close', function() {

var alert = $(this).parent('.action-alert');
var select_bottom = parseFloat(alert.css('bottom')) / 10;
var select_height = parseFloat(alert.css('height')) / 10;
alert.animate({bottom: -1 * select_height - 5 + 'rem'});

var action_alert = $('.action-alert');
$.each(action_alert, function() {
  var bottom = parseFloat($(this).css('bottom')) / 10;
  if (bottom > select_bottom ) {
    $(this).animate({bottom: bottom - select_height - 1 + 'rem'});
  }
});

});