var p_ga_pl_1_f = true;
var p_ga_pl_1_rc = 15;
var p_ga_pl_1_pn;
var p_ga_pl_1_r = 1; /* Image random */

function p_ga_pl_1_load() {
    try {
        $(function () {
            $('.p_ga_pl_1_m .loading').show();
            $('.p_ga_pl_1_m .main').hide();
            setTimeout(function () {
                p_ga_pl_1_init();
            }, p_h_lo_ti);
        });
    } catch (e) {
        p_h_log(e);
    }
}

function p_ga_pl_1_init() {
    try {
        $(window).on('scroll', function () {
            if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
                p_ga_pl_1_list();
            }
        });

        p_ga_pl_1_initList();
    } catch (e) {
        p_h_log(e);
    }
}

function p_ga_pl_1_initList() {
    try {
        $('.p_ga_pl_1_m .main').html('');
        p_ga_pl_1_pn = 1;
        p_ga_pl_1_list();
    } catch (e) {
        p_h_log(e);
    }
}

function p_ga_pl_1_list() {
    try {
        if (!p_ga_pl_1_f && p_ga_pl_1_pn != null)
            return;
        p_ga_pl_1_f = false;
        $.ajax({
            url: "/user16/user/game/plinko/ajax.jsp",
            type: "post",
            data: {on: 1, rc: p_ga_pl_1_rc, pn: p_ga_pl_1_pn},
            success: function (response) {
                response = $.trim(response);
                switch (response) {
                    case '':
                    case '0':
                        setTimeout(function () {
                            p_ga_pl_1_list();
                        }, 5000);
                        p_ga_pl_1_f = true;
                        break;
                    default:
                        var ja = eval('(' + response + ')');
                        $('.p_ga_pl_1_m .loading').hide();
                        var m = $('.p_ga_pl_1_m .main');
                        m.show();
                        if (ja.length > 0) {
                            for (var i = 0; i < ja.length; i++) {
                                var e = $($('.p_ga_pl_1_t').html()).appendTo(m);
                                if (ja[i]['im'] != null)
                                    e.css('background-image', 'url(\'' + $('#p_ga_pl_1_gamePath').html() + ja[i]['gid'] + '/' + ja[i]['im'] + '?r=' + p_ga_pl_1_r + '\')');
                                e.find('.co').html('#' + ja[i]['gc']);
                                e.find('.na').html(ja[i]['na']).attr('tr-ht', '0');
                                e.wrap('<a class="buttonWithPageLoading" href="/game/plinko/?gid=' + ja[i]['gid'] + (new URLSearchParams(window.location.search).has('demo') ? '&demo=1' : '') + '"></a>');
                            }
                            p_ga_pl_1_pn++;
                            if (ja.length == p_ga_pl_1_rc)
                                p_ga_pl_1_f = true;
                            else
                                $(window).off('scroll');
                            translate_updateLanguage(3);
                        } else if (m.find('.t').length == 0) {
                            m.html('<div class="noCase">' + $('#p_ga_pl_1_noCase').html() + '</div>');
                            $(window).off('scroll');
                        }
                        break;
                }
            }, error: function () {
                setTimeout(function () {
                    p_ga_pl_1_list();
                }, 5000);
                p_ga_pl_1_f = true;
            }, failure: function () {
                setTimeout(function () {
                    p_ga_pl_1_list();
                }, 5000);
                p_ga_pl_1_f = true;
            }
        });
    } catch (e) {
        p_h_log(e);
    }
}