$(function (event) {
    var x = document.getElementById("mediaId");
    var x2 = document.getElementById("mediaShow");

    function play() {
        x.play();
        x.muted = false
    }

    x2.pause();
    x2.muted = true

    function playShow() {
        x.pause();
        x.muted = true
        x2.play();
        x2.muted = false
    }
    var stopStep = 1;
    var runT = null;
    var step = -1;
    var during = 2;
    $("#choujiang").click(function (event) {
        play()
        stopStep = 5
        runT = setTimeout(runF, 100);
    });

    function choice(number) {
        if (number == 1) {
            alert("香水");
        }
        if (number == 2) {
            alert("帽子");
        }
        if (number == 3) {
            alert("再接再厉哟");
        }
        if (number == 4) {
            alert("华为p20");
        }
        if (number == 5) {
            $('#photoBody').hide()
            $('#hongbao').show()
            playShow()
            // alert("5元话费");
        }
        if (number == 6) {
            alert("剃须刀");
        }
        if (number == 7) {
            alert("明日再战");
        }
        if (number == 8) {
            alert("短柄伞");
        }
    }

    function runF() {
        if (step >= (32 + stopStep)) {
            $(".gift" + (step % 8)).addClass("back");
            step = stopStep;
            choice(step);
            clearTimeout(runT);
            
            return;
        }
        if (step >= (24 + stopStep)) {
            during += 1;
        } else {
            if (during <= 2) {
                during = 2;
            }
            during--;
        }
        step++;
        $(".gift").each(function (index, element) {
            $(this).removeClass("back");
        });
        $(".gift" + (step % 8)).addClass("back");
        runT = setTimeout(runF, during * 50);
    }
});