<?
if (isset($_SESSION['leprchaun'])) {
    unset($_SESSION['leprchaun']);
}

$l_c = mt_rand(1, 50);
$l_f = mt_rand(1, 50);

$leprchaun = false;

if ($l_c == $l_f && $_SERVER['PHP_SELF'] != '/plugins/games/leprechaun/index.php') {
    $_SESSION['leprchaun'] = mt_rand(1, 5);
    $leprchaun = true;
}

if ($leprchaun === true) {
  
    $src_x = mt_rand(10, 80);
    $src_y = mt_rand(10, 80);
    ?>
    <style>
    .leprechaun {
      height: 70px;
      width: 70px;
      position: absolute;
      left: <?= $src_x?>%;
      z-index: 100;
      top: 0px;
      background-image: url(/plugins/games/leprechaun/res/app_g.png);
      background-repeat: no-repeat;
      background-position: center;
    }

    .leprechaun a {
      display: block;
      height: 100%;
      width: 100%;
    }
    </style>

    <audio preload="auto" src="/plugins/games/leprechaun/res/app_m.ogg" autoplay="1" />

    <script>
    $("div").first().prepend('<div class="leprechaun"><a href="/plugins/games/leprechaun/?ret=<?= text($_SERVER['REQUEST_URI'])?>"></a></div>');

    jQuery.easing['jswing'] = jQuery.easing['swing'];

    jQuery.extend(jQuery.easing, {
        easeOutBounce: function (x, t, b, c, d) {
      		if ((t/=d) < (1/2.75)) {
      			return c*(7.5625*t*t) + b;
      		} else if (t < (2/2.75)) {
      			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
      		} else if (t < (2.5/2.75)) {
      			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
      		} else {
      			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
      		}
      	},
    });

    $('.leprechaun').animate({top: '<?= $src_y?>%'}, 2000, 'easeOutBounce', function(){
      $(this).css({top: '<?= $src_y?>%'});
    });
    </script>
    <?  
}