let _today = new Date().toISOString().slice(0, 10).replace(/-/g, "") * 1;
let devHost = location.hostname.includes('demolx2.com');
let isTestingDomain = !![].find(f => location.hostname.replace(/^www./g, '').includes(f));
let devGameList = ['fs','sp','ams','mgp2','sg','hb2','rlx','ns','ss'];
let testingGameList = [];

$(document).ready(function() {
    if ($('.g8sggl-ps').length) {

        $('head').append('<style type="text/css">.g8sggl-ps *{box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}.g8sggl-ps{padding:10px 0px 15px}.g8sggl-ps .g8sggl-ps-t{position:relative;margin:5px}.g8sggl-ps .g8sggl-ps-t .tt{color:#ffffff;font-weight:700;font-size:18px}.g8sggl-ps .g8sggl-ps-t .rr{position:absolute;right:0;top:5px}.g8sggl-ps .g8sggl-ps-t .rr a{background-color:#d9b300;color:#352c02;text-transform:uppercase;font-size:12px;font-weight:700;padding:5px 10px;border-radius:20px}.g8sggl-ps .g8sggl-ps-t .rr a:hover{background-color:#222;color:#fff}.g8sggl-ps .glbox{font-size:0;position:relative;z-index:0}.g8sggl-ps .glbox .gl{display:none;width:14.28%;font-size:12px;padding:5px}.g8sggl-ps .glbox .gl:nth-child(-n+7){display:inline-block}.g8sggl-ps .glbox .gl .glimg{position:relative;width:100%;padding-top:100%;background-color:#050505;cursor:pointer;overflow:hidden}.g8sggl-ps .glbox .gl .gltext{background-color:#d9b300;color:#352c02;padding:6px 10px;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.g8sggl-ps .glbox .gl .glimg:hover .hwrap{opacity:1}.g8sggl-ps .glbox .gl .glpic{position:absolute;width:100%;top:50%;transform:translateY(-50%);z-index:1}.g8sggl-ps .glbox .gl .glpic img{width:100%}.g8sggl-ps .glbox .gl .hwrap{position:absolute;top:0;left:0;width:100%;height:100%;z-index:3;background:rgba(0,0,0,0.8);opacity:0}.g8sggl-ps .glbox .gl .hwrap .hbox{position:absolute;width:80%;left:50%;top:50%;transform:translate(-50%,-50%)}.g8sggl-ps .glbox .gl .hwrap .hbox .main{color:#352c02;background-color:#d9b300;text-align:center;width:100%;display:block;text-transform:uppercase;padding:8px;border-radius:20px}@media only screen and (max-width:1000px){.g8sggl-ps .glbox .gl{display:none!important;width:16.66%}.g8sggl-ps .glbox .gl:nth-child(-n+6){display:inline-block!important}}@media only screen and (max-width:768px){.g8sggl-ps .glbox{white-space:nowrap;overflow-x:auto}.g8sggl-ps .glbox .gl{display:inline-block!important;width:120px}}\
        \
        .g8sggl-ps.ss1 .g8sggl-ps-t .tt{color:#212121}\
        \
        </style>')

        $('.g8sggl-ps').append('\
        <div class="g8sggl-ps-t"><div class="tt">Slots Populer</div><div class="rr"><a href="slots.html">more</a></div></div>\
        <div class="g8sggl-ps-b"><div class="glbox"></div></div>\
        ')

        getG8sgPS()
    }

    if ($('.g8sggl').length) {
        $('head').append('<style type="text/css">.g8sggl *{box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}.g8sggl .g8sggl-t{background-color:#383637;font-size:0;padding:3px 2px;margin-bottom:15px;position:relative}.g8sggl .g8sggl-t .ii{background-color:#0f0f0f;display:inline-block;width:130px;text-align:center;font-size:14px;margin:0 2px;background-repeat:no-repeat;background-position:top 5px center;background-size:80%;background-blend-mode:luminosity;position:relative;vertical-align:top}.g8sggl .g8sggl-t .ii .ii-tt{padding:60px 0 5px}.g8sggl .g8sggl-t .ii .ii-info{position:absolute;top:2px;right:2px;width:16px;height:16px;border-radius:50%;text-align:center;background-color:#666;color:#fff}.g8sggl .g8sggl-t .ii .ii-info .fa{font-size:10px;line-height:16px}.g8sggl .g8sggl-t .ii.aaa{background-color:#000;background-blend-mode:inherit}.g8sggl .g8sggl-t .ii:hover{background-color:#222;background-blend-mode:inherit}.g8sggl .g8sggl-c{background-color:#050505;font-size:0}.g8sggl .g8sggl-c .ll{display:inline-block;width:80%;white-space:nowrap;overflow-x:auto;position:relative}.g8sggl .g8sggl-c .ll .ii{font-size:14px;display:inline-block;padding:0 20px;line-height:40px;text-transform:uppercase}.g8sggl .g8sggl-c .rr{display:inline-block;width:20%;vertical-align:top}.g8sggl .g8sggl-c .ll .ii.aaa,.g8sggl .g8sggl-c .ll .ii:hover{background-color:#d9b300;color:#352c02}.g8sggl .g8sggl-b{background-color:#0f0f0f;padding:10px}.g8sggl .glmsg{font-size:14px;color:#fff;text-align:center;padding:10px 0}.g8sggl .glmsg .g8sgpopa{background-color:#d9b300; color:#352c02; display:inline-block; font-weight:bold; text-transform:uppercase; padding:8px 15px;}.g8sggl .glmsg .g8sgpopa:hover {background-color:#333333; color:#ffffff}.g8sggl .glbox{font-size:0;position:relative;z-index:0}.g8sggl .glbox .gl{display:inline-block;width:20%;font-size:14px;padding:8px}.g8sggl .glbox .gl.hh{display:none}.g8sggl .glbox .gl.ss-yes{display:inline-block!important}.g8sggl .glbox .gl.ss-no{display:none!important}.g8sggl .glbox .gl .glimg{position:relative;width:100%;padding-top:100%;background-size:100%;background-position:center;background-repeat:no-repeat;background-color:#050505;cursor:pointer;overflow:hidden}.g8sggl .glbox .gl .gltext{background-color:#d9b300;color:#352c02;padding:6px 10px;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.g8sggl .glbox .gl .glp{background-color:#222;text-align:center;background-size:auto 86%;background-repeat:no-repeat;min-height:26px;background-position:center}.g8sggl .glbox .gl .glimg:hover .hwrap{opacity:1}.g8sggl .glbox .gl .glbadge {width: 35%; position: absolute; left: 0px; top: 0px; z-index:2}.g8sggl .glbox .gl .glbadge img {max-width:100%; height:auto;}.g8sggl .glbox .gl .glpic {position:absolute; width:100%; heigth:100%; top:50%; transform:translateY(-50%); z-index:1}.g8sggl .glbox .gl .glpic img {width:100%}.g8sggl .glbox .gl .hwrap{position:absolute;top:0;left:0;width:100%;height:100%;z-index:3;background:rgba(0,0,0,0.8);opacity:0}.g8sggl .glbox .gl .hwrap .hbox{position:absolute;width:80%;left:50%;top:50%;transform:translate(-50%,-50%)}.g8sggl .glbox .gl .hwrap .hbox .main{color:#352c02;background-color:#d9b300;text-align:center;width:100%;display:block;text-transform:uppercase;padding:8px;border-radius:20px}.g8sggl .glpagi{text-align:center;font-size:0;margin-top:15px;display:none}.g8sggl .glpagi .pagi{display:inline-block;font-size:10px;font-weight:bold;margin:2px;background-color:#000;width:20px;line-height:20px;text-align:center}.g8sggl .glpagi .pagi.aaa,.g8sggl .glpagi .pagi:hover{background-color:#d9b300;color:#352c02}.g8sggl .searchbar{font-size:12px}.g8sggl .searchbar input{background-color:#333;border:0;display:inline-block;width:100%;line-height:40px;padding:0 10px;outline:0;border-radius:0px;color:#ffffff}.g8sggl .searchbar input::placeholder{color:#ffffff}.g8sggl .searchbar button{background-color:#858585;border:0;display:inline-block;width:40px;height:40px;font-size:16px}.g8sggl .g8sggl-tarr{position:absolute;top:0;color:#352c02;height:100%;padding:0 8px;background-color:#d9b300;width:22px;font-size:16px;display:none}.g8sggl .g8sggl-tarr.l{left:0}.g8sggl .g8sggl-tarr.r{right:0}.g8sggl .g8sggl-tarr i{position:absolute;top:50%;left:50%;text-align:center;transform:translate(-50%,-50%)}.g8sggl .g8sggl-t .ii,.g8sggl .g8sggl-c .ll .ii,.g8sggl .glpagi .pagi{transition:.5s ease;cursor:pointer}.g8sggl .g8sggl-t .ww::-webkit-scrollbar,.g8sggl .g8sggl-c .ll .ww::-webkit-scrollbar{display:none}.g8sggl .g8sggl-t .ww,.g8sggl .g8sggl-c .ll .ww{-ms-overflow-style:none;scrollbar-width:none;white-space:nowrap;overflow-x:auto;text-align:left}.pvd.all{background-image:url(/common/images/slots/all.png)}.pvd.lv2{background-image:url(/common/images/slots/live22.png)}.pvd.pm{background-image:url(/common/images/slots/pm.png)}.pvd.vp{background-image:url(/common/images/slots/vp.png)}.pvd.s88{background-image:url(/common/images/slots/s88.png)}.pvd.jk{background-image:url(/common/images/slots/jk.png)}.pvd.pg{background-image:url(/common/images/slots/pg.png)}.pvd.hb{background-image:url(/common/images/slots/hb.png)}.pvd.sg{background-image:url(/common/images/slots/sg.png)}.pvd.cq9{background-image:url(/common/images/slots/cq9.png)}.pvd.ka{background-image:url(/common/images/slots/ka.png)}.pvd.gp{background-image:url(/common/images/slots/gp.png)}.pvd.pt{background-image:url(/common/images/slots/pt.png)}.pvd.mgp{background-image:url(/common/images/slots/mg.png)}.pvd.ps{background-image:url(/common/images/slots/ps.png)}.pvd.tsg{background-image:url(/common/images/slots/tsg.png)}.pvd.sa{background-image:url(/common/images/slots/sa.png)}.pvd.nt{background-image:url(/common/images/slots/nt.png)}@media only screen and (max-width:768px){.g8sggl .g8sggl-t .ii{width:110px;font-size:12px}.g8sggl .g8sggl-t .ii .ii-tt{padding-top:50px}.g8sggl .g8sggl-c .ll{width:70%}.g8sggl .g8sggl-c .ll .ii{font-size:12px;padding:0 15px;line-height:34px}.g8sggl .g8sggl-c .rr{width:30%}.g8sggl .searchbar input{line-height:34px}.g8sggl .glbox .gl{font-size:12px}.g8sggl .glbox .gl .hwrap{display:none}}@media only screen and (max-width:479px){.g8sggl .g8sggl-t .ii{width:90px}.g8sggl .g8sggl-t .ii .ii-tt{padding-top:44px}.g8sggl .g8sggl-c .ll{width:100%}.g8sggl .g8sggl-c .rr{width:100%}.g8sggl .searchbar input{text-align:center}.g8sggl .glbox .gl{width:33.33%; padding:5px;}.g8sggl .glbox .gl .gltext{padding:4px 10px}}\
        \
        .pvd.pmc {background-image: url(/common/images/slots/pragmatic-classic.png);}\
        .pvd.rk {background-image: url(/common/images/slots/rk.png);}\
        .pvd.jl {background-image: url(/common/images/slots/jili.png);}\
        .pvd.nc {background-image: url(/common/images/slots/nc.png);}\
        .pvd.rt {background-image: url(/common/images/slots/rt.png);}\
        .pvd.fs {background-image: url(/common/images/slots/fastspin.png);}\
        .pvd.jb {background-image: url(/common/images/slots/jdb.png);}\
        .pvd.fc {background-image: url(/common/images/slots/facai.png);}\
        .pvd.sp {background-image: url(/common/images/slots/spinix.png);}\
        .pvd.ap {background-image: url(/common/images/slots/advantplay.png);}\
        .pvd.hs {background-image: url(/common/images/slots/hacksaw.png);}\
        .pvd.bng {background-image: url(/common/images/slots/bng.png);}\
        .pvd.png {background-image: url(/common/images/slots/playngo.png);}\
        .pvd.ams {background-image: url(/common/images/slots/askmeslot.png);}\
        .pvd.mgp2 {background-image: url(/common/images/slots/mg.png);}\
        .pvd.sg2 {background-image: url(/common/images/slots/sg.png);}\
        .pvd.hb2 {background-image: url(/common/images/slots/hb.png);}\
        .pvd.alz {background-image: url(/common/images/slots/alz.png);}\
        .pvd.ep {background-image: url(/common/images/slots/ep.png);}\
        .pvd.ebtg {background-image: url(/common/images/slots/ebtg.png);}\
        .pvd.ibx {background-image: url(/common/images/slots/ibx.png);}\
        .pvd.rlx {background-image: url(/common/images/slots/rlx.png);}\
        .pvd.emp {background-image: url(/common/images/slots/emp.png);}\
        .pvd.ns {background-image: url(/common/images/slots/nextspin.png);}\
        .pvd.ss {background-image: url(/common/images/slots/smartsoft.png);}\
        .g8sggl.ss1 .g8sggl-t {background-color:#171342}.g8sggl.ss1 .g8sggl-t .ii {background-color:#301d6e}.g8sggl.ss1 .g8sggl-t .ii.aaa, .g8sggl.ss1 .g8sggl-t .ii:hover {background-color:#110e35}.g8sggl.ss1 .g8sggl-tarr {background-color:#e3a43b}.g8sggl.ss1 .g8sggl-c {background-color:#301d6e}.g8sggl.ss1 .g8sggl-c .ll .ii.aaa, .g8sggl.ss1 .g8sggl-c .ll .ii:hover {background-color:#e3a43b}.g8sggl.ss1 .searchbar input {background-color:#110e35}.g8sggl.ss1 .g8sggl-b {background-color:#171342}.g8sggl.ss1 .glbox .gl .glp {background-color:#110e35}.g8sggl.ss1 .glbox .gl .gltext, .g8sggl .glbox .gl .hwrap .hbox .main {background-color:#e3a43b}\
        \
        .g8sggl .g8sggl-t .ii .badge {position:absolute; width:34%; left:0px; top:0px;} .g8sggl .g8sggl-t .ii .badge img {max-width:100%;filter: grayscale(0.8);}.g8sggl .g8sggl-t .ii.aaa .badge img,.g8sggl .g8sggl-t .ii:hover .badge img {filter: none;}\
        .g8sggl .glbox .gl .glbadge.joker-hot {right: 0;left: auto;top: 0;}\
        </style>');

        $('.g8sggl').append(`
            <div class="g8sggl-t">
                <div class="ww">
                    <div class="ii glpvd pvd all aaa" dd="all">
                        <div class="ii-tt">All games</div>
                    </div>
                    <div class="ii glpvd pvd pm" dd="pm">
                        <div class="badge" style="left: -7px;">
                            <img src="/common/imgs/pp/pp-title-no-1.png" style="width: 29px;">
                        </div>
                        <div class="ii-tt">Pragmatic Play</div>
                    </div>
                    <!--<div class="ii glpvd pvd pmc" dd="pmc"><div class="ii-tt">PP Classic</div></div>-->
                    <!--<div class="ii glpvd pvd rk" dd="rk"><div class="ii-tt">Reel Kingdom</div></div>-->
                    <div class="ii glpvd pvd mgp" dd="mgp"><div class="ii-tt">Microgaming</div></div>
                    <div class="ii glpvd pvd s88" dd="s88"><div class="ii-tt">Slot88</div></div>
                    <div class="ii glpvd pvd pg" dd="pg"><div class="ii-tt">Pgsoft</div></div>
                    <div class="ii glpvd pvd jl" dd="jl"><div class="ii-tt">Jili</div></div>
                    <div class="ii glpvd pvd lv2" dd="lv2"><div class="ii-tt">Live22</div></div>
                    <div class="ii glpvd pvd vp" dd="vp"><div class="ii-tt">Vpower</div></div>
                    <div class="ii glpvd pvd jk" dd="jk"><div class="ii-tt">Joker</div></div>
                    <div class="ii glpvd pvd hb" dd="hb"><div class="ii-tt">Habanero</div></div>
                    <div class="ii glpvd pvd sg ${globalObj.login ? 'j-winopen' : 's-check'}" action="spadegaming" dd="sg">
                        <div class="ii-tt">Spadegaming</div>
                        <div class="ii-info"><i class="fa fa-external-link fa-external-link-alt"></i></div>
                    </div>
                    <div class="ii glpvd pvd cq9 ${globalObj.login ? 'j-winopen' : 's-check'}" action="cq-slot" dd="cq9">
                        <div class="ii-tt">CQ9</div>
                        <div class="ii-info"><i class="fa fa-external-link fa-external-link-alt"></i></div>
                    </div>
                    <div class="ii glpvd pvd ka" dd="ka"><div class="ii-tt">KA Gaming</div></div>
                    <div class="ii glpvd pvd gp" dd="gp"><div class="ii-tt">Gameplay</div></div>
                    <div class="ii glpvd pvd pt" dd="pt"><div class="ii-tt">Playtech</div></div>
                    <div class="ii glpvd pvd ps" dd="ps"><div class="ii-tt">Playstar</div></div>
                    <div class="ii glpvd pvd nt" dd="nt"><div class="ii-tt">Netent</div></div>
                    <div class="ii glpvd pvd nc" dd="nc"><div class="ii-tt">NoLimit City</div></div>
                    <div class="ii glpvd pvd rt" dd="rt"><div class="ii-tt">Red Tiger</div></div>
                    <div class="ii glpvd pvd fs" dd="fs" style="display:none;"><div class="ii-tt">FastSpin</div></div>
                    <div class="ii glpvd pvd jb" dd="jb"><div class="ii-tt">JDB</div></div>
                    <div class="ii glpvd pvd fc" dd="fc"><div class="ii-tt">Fa Chai</div></div>
                    <div class="ii glpvd pvd sp" dd="sp" style="display:none;"><div class="ii-tt">Spinix</div></div>
                    <div class="ii glpvd pvd ap" dd="ap"><div class="ii-tt">AdvantPlay</div></div>
                    <div class="ii glpvd pvd hs" dd="hs"><div class="ii-tt">Hacksaw</div></div>
                    <div class="ii glpvd pvd bng" dd="bng"><div class="ii-tt">BNG</div></div>
                    <div class="ii glpvd pvd png" dd="png"><div class="ii-tt">PlaynGo</div></div>
                    <div class="ii glpvd pvd ams" dd="ams" style="display:none;"><div class="ii-tt">Askmeslot</div></div>
                    <div class="ii glpvd pvd mgp2" dd="mgp2" style="display:none;"><div class="ii-tt">Microgaming</div></div>
                    <div class="ii glpvd pvd sg2" dd="sg" style="display:none;"><div class="ii-tt">Spadegaming</div></div>
                    <div class="ii glpvd pvd alz" dd="alz"><div class="ii-tt">Alize</div></div>
                    <div class="ii glpvd pvd hb2" dd="hb2" style="display:none;"><div class="ii-tt">Habanero</div></div>
                    <div class="ii glpvd pvd ep" dd="ep"><div class="ii-tt">Evoplay</div></div>
                    <div class="ii glpvd pvd ebtg" dd="ebtg"><div class="ii-tt">Big Time Game</div></div>
                    <div class="ii glpvd pvd ibx" dd="ibx"><div class="ii-tt">Ibex</div></div>
                    <div class="ii glpvd pvd rlx" dd="rlx" style="display:none;"><div class="ii-tt">Relax Gaming</div></div>
                    <div class="ii glpvd pvd emp" dd="emp"><div class="ii-tt">Imperium Games</div></div>
                    <div class="ii glpvd pvd ns" dd="ns" style="display:none;"><div class="ii-tt">Nextspin</div></div>
                    <div class="ii glpvd pvd ss" dd="ss" style="display:none;"><div class="ii-tt">Smartsoft</div></div>
                </div>
                <a href="javascript:void(0)" class="g8sggl-tarr l" me="l"><i class="fa fa-chevron-left"></i></a>
                <a href="javascript:void(0)" class="g8sggl-tarr r" style="display: block;" me="r"><i class="fa fa-chevron-right"></i></a>
            </div>
            <div class="g8sggl-c">
                <div class="ll glcat">
                    <div class="ww"></div>
                    <a href="javascript:void(0)" class="g8sggl-tarr l" me="l"><i class="fa fa-chevron-left"></i></a>
                    <a href="javascript:void(0)" class="g8sggl-tarr r" style="display: block;" me="r"><i class="fa fa-chevron-right"></i></a>
                </div>
                <div class="rr">
                    <div class="searchbar"><input type="text" class="glsearch" placeholder="Cari Permainan"></div>
                </div>
            </div>
            <div class="g8sggl-b">
                <div class="glmsg">Loading ...</div>
                <div class="glbox"></div>
                <div class="glpagi"></div>
            </div>
        `);

        if (devHost) {
            $('.ii.glpvd.pvd').show();
        }

        testingGameList.forEach((t) => isTestingDomain && $(`div[dd="${t}"]`).show()); // Show on testing domain

        // Click sub category
        $(document).on('click', '.gocat', function() {
            $('.gocat').removeClass('aaa');
            $(this).addClass('aaa');

            getG8sg($('.glpvd.aaa').attr('dd'), $(this).attr('dd'));
        });

        // Click provider
        $(document).on('click', '.glpvd', function() {
            $('.glpvd').removeClass('aaa');
            $(this).addClass('aaa');

            // Let handle by other script
            if ($(this).hasClass('s-check') || $(this).hasClass('j-winopen')) {
                return false;
            }

            var dd = $(this).attr('dd');

            getG8sg(dd, dd === 'pm' ? 'hot' : 'all'); // For PM set to hot subcategory
        });

        let sg = new URLSearchParams(window.location.search).get('sg'),
            sqElem = $(`.glpvd.${sg}`);

        if (sg && sqElem.length) {
            window.history.replaceState(null, null, window.location.pathname);

            sqElem.trigger('click');

            // Trick for element not shown immediately
            setTimeout(function() {
                $(`.glpvd.${sg}:visible`).addClass('aaa');
                $('.g8sggl .g8sggl-t .ww').animate({
                    scrollLeft: $(`.glpvd.${sg}:visible`).position().left - 20
                }, 400);
            }, 300);

            if (sqElem.attr('action') !== undefined) {
                $('.g8sggl .glmsg').show().html(`<a href="#" class="${globalObj.login ? 'j-winopen' : 's-check'} g8sgpopa" action="${sqElem.attr('action')}">klik di sini untuk bermain sekarang</a>`);
            }
        } else {
            $('.g8sggl .g8sggl-t .ww').scrollLeft(0);
            getG8sg('all', 'new'); // default sub category is "new"
        }

        $(window).resize(function() {
            checkLRarrow();
        });

        $(document).on('click', '.g8sggl-tarr', function() {
            $(this).parent().find('.ww').animate({
                scrollLeft: ($(this).attr('me') == 'l' ? "-" : "+") + "=300px"
            }, 600);

            return false;
        });

        // Provider slots
        $('.g8sggl .g8sggl-t .ww').scroll(function() {
            var $width = $(this).outerWidth()
            var $scrollWidth = $(this)[0].scrollWidth;
            var $scrollLeft = $(this).scrollLeft();

            $(this).parent().find('.g8sggl-tarr').show();

            if ($scrollWidth - $width - 5 <= $scrollLeft) {
                $(this).parent().find('.g8sggl-tarr.r').hide()
            }

            if ($scrollLeft === 0) {
                $(this).parent().find('.g8sggl-tarr.l').hide()
            }
        });

        // Sub category
        $('.g8sggl .g8sggl-c .ll .ww').scroll(function() {
            var $width = $(this).outerWidth()
            var $scrollWidth = $(this)[0].scrollWidth;
            var $scrollLeft = $(this).scrollLeft();

            $(this).parent().find('.g8sggl-tarr').show();

            if ($scrollWidth - $width - 5 <= $scrollLeft) {
                $(this).parent().find('.g8sggl-tarr.r').hide()
            }

            if ($scrollLeft === 0) {
                $(this).parent().find('.g8sggl-tarr.l').hide()
            }
        });

        // Paging
        $(document).on('click', '.goppp', function() {
            var page = $(this).attr('dd');
            $('.goppp.aaa').removeClass('aaa');
            $(this).addClass('aaa');
            $('.gl.ppp').addClass('hh');
            $('.gl.ppp-' + page).removeClass('hh');
            $('html, body').animate({
                scrollTop: $(".g8sggl").offset().top
            }, 400);
        });

        $('.glsearch').val('');

        // Handle search
        $(document).on('keyup', '.glsearch', function(e) {
            var value = $(this).val().toLowerCase();

            $('.g8sggl .glmsg').empty().hide();
            $('.g8sggl .glbox .gl').removeClass('ss-yes ss-no');
            $('.g8sggl .glpagi').hide();

            $('.g8sggl .glbox .gl').each(function() {
                var nn = $(this).find('.gltext').text().toLowerCase().search(value);

                $(this).addClass(nn > -1 ? 'ss-yes' : 'ss-no');
            });

            if (!$('.g8sggl .glbox .gl.ss-yes').length) {
                $('.g8sggl .glmsg').show().text('Could not find the game you were looking for, please try search others game.');
            }
        });
    }
});

function getG8sg(provider, category) {
    let pars = {
        providerName: provider !== 'all' ? provider : '',
        categoryName: category !== 'all' ? category : '',
        group: 1,
    };

    $.each(pars, function(key, value) {
        if (value === "" || value === null) {
            delete pars[key];
        }
    });

    $('.glsearch').val('');
    $('.g8sggl .glmsg').show().text('Loading ...');
    $('.g8sggl .glpagi').empty().hide();
    $('.g8sggl .glbox').empty();
    $('.g8sggl .glcat .ww').empty();

    $.ajax({
        type: "GET",
        url: `/${globalObj.login ? 'ajax' : 'func'}/stl/getSlotGameList`,
        data: pars,
        dataType: 'json',
        async: false,
        success: function(res) {
            // Exclude dev games
            var gameList = devHost ? res["slotGameList"] : res["slotGameList"].filter(f => isTestingDomain ? !devGameList.filter(f => !testingGameList.includes(f)).includes(f.providerName) : !devGameList.includes(f.providerName)),
                gameCategory = res["categoryList"],
                pageLimit = 30;

            if (gameCategory.length) {
                $('.g8sggl .glcat .ww').append('<div class="ii gocat" dd="all" ss="0">all</div>');

                if (provider == 'pm') {
                    var catSortList = ['hot', 'new', 'classic', 'buy bonus', 'reel kingdom', 'megaways', 'crash games', 'table'];
                    $.each(catSortList, function(i, item) {
                        $('.g8sggl .glcat .ww').append('<div class="ii gocat" dd="' + item + '" ss="' + (i + 1) + '">' + item + '</div>');
                    });
                } else {
                    var catSortList = ['all', 'new', 'hot'];

                    $.each(gameCategory, function(i, item) {
                        var gameCat = item['gameCategory'],
                            appendData = '<div class="ii gocat" dd="' + gameCat + '" ss="' + (i + 1) + '">' + gameCat + '</div>';

                        if (catSortList.indexOf(gameCat) != -1) {
                            appendData = '<div class="ii gocat" dd="' + gameCat + '" ss="0.' + catSortList.indexOf(gameCat) + '">' + gameCat + '</div>';
                        }

                        $('.g8sggl .glcat .ww').append(appendData);
                    });
                }

                $(`.gocat[dd="${category}"]`).addClass('aaa');

                sortCatList();
            }

            if (gameList.length) {
                $('.g8sggl .glmsg').hide();
                $('.g8sggl .glpagi').toggle(gameList.length > pageLimit && provider === 'all');

                let modifiedGames = [{
                        rtp: 89,
                        providerName: "pm",
                        slotGameName: "LUXE Gates of Olympus",
                        slotGameImg: "/common/imgs/pragmatic/vs20luxegates.png",
                        slotGameLink: "vs20luxegates"
                    },
                    {
                        rtp: 93,
                        providerName: "pm",
                        slotGameName: "Gates of Olympus",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20olympgate.png",
                        slotGameLink: "vs20olympgate"
                    },
                    {
                        rtp: 95,
                        providerName: "pm",
                        slotGameName: "Gates of Olympus 1000",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20olympx.png",
                        slotGameLink: "vs20olympx"
                    },
                    {
                        rtp: 85,
                        providerName: "pm",
                        slotGameName: "Starlight Princess",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20starlight.png",
                        slotGameLink: "vs20starlight"
                    },
                    {
                        rtp: 82,
                        providerName: "pm",
                        slotGameName: "Sweet Bonanza",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20fruitsw.png",
                        slotGameLink: "vs20fruitsw"
                    },
                    {
                        rtp: 90,
                        providerName: "pm",
                        slotGameName: "Starlight Princess 1000",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20starlightx.png",
                        slotGameLink: "vs20starlightx"
                    },
                    {
                        rtp: 98,
                        providerName: "pm",
                        slotGameName: "Candy Jar Clusters",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20cjcluster.png",
                        slotGameLink: "vs20cjcluster"
                    },
                    {
                        rtp: 82,
                        providerName: "pm",
                        slotGameName: "The Wild Gang",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vswayswildgang.png",
                        slotGameLink: "vswayswildgang"
                    },
                    {
                        rtp: 84,
                        providerName: "pm",
                        slotGameName: "Sea Fantasy",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vswaysseastory.png",
                        slotGameLink: "vswaysseastory"
                    },
                    {
                        rtp: 85,
                        providerName: "pm",
                        slotGameName: "Fire Stampede",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vswaysstampede.png",
                        slotGameLink: "vswaysstampede"
                    },
                    {
                        rtp: 83,
                        providerName: "pm",
                        slotGameName: "The Dog House Dice Show",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20dhdice.png",
                        slotGameLink: "vs20dhdice"
                    },
                    {
                        rtp: 86,
                        providerName: "pm",
                        slotGameName: "Candy Blitz Bombs",
                        slotGameImg: "/common/imgs/pragmatic/vs20candybltz2.png",
                        slotGameLink: "vs20candybltz2"
                    },
                    {
                        rtp: 88,
                        providerName: "pm",
                        slotGameName: "Spaceman",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/1301.png",
                        slotGameLink: "1301"
                    },
                    {
                        rtp: 78,
                        providerName: "pm",
                        slotGameName: "Gates of Gatot Kaca 1000",
                        slotGameImg: "/common/imgs/pragmatic/vs20gatotx.png",
                        slotGameLink: "vs20gatotx"
                    },
                    {
                        rtp: 85,
                        providerName: "pm",
                        slotGameName: "Sweet Bonanza Xmas",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20sbxmas.png",
                        slotGameLink: "vs20sbxmas"
                    },
                    {
                        rtp: 87,
                        providerName: "pm",
                        slotGameName: "Gears of Horus",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20clustext.png",
                        slotGameLink: "vs20clustext"
                    },
                    {
                        rtp: 77,
                        providerName: "pm",
                        slotGameName: "Power of Ninja",
                        slotGameImg: "/common/imgs/pragmatic/vs20ninjapower.png",
                        slotGameLink: "vs20ninjapower"
                    },
                    {
                        rtp: 75,
                        providerName: "pm",
                        slotGameName: "Gates of Olympus Dice",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20olympdice.png",
                        slotGameLink: "vs20olympdice"
                    },
                    {
                        rtp: 80,
                        providerName: "s88",
                        slotGameName: "Tiger New Year",
                        slotGameImg: "https://y.fa8y3.xyz/st/public/icon/tiger.png",
                        slotGameLink: "66"
                    },
                    {
                        rtp: 87,
                        providerName: "s88",
                        slotGameName: "NatureSpirit",
                        slotGameImg: "https://y.fa8y3.xyz/st/public/icon/naturespirit.png",
                        slotGameLink: "69"
                    },
                    {
                        rtp: 87,
                        providerName: "mgp",
                        slotGameName: "Almighty Zeus Empire",
                        slotGameImg: "/common/imgs/mgp/SMG_almightyZeusEmpire.png",
                        slotGameLink: "SMG_almightyZeusEmpire"
                    },
                    {
                        rtp: 85,
                        providerName: "mgp",
                        slotGameName: "Lucky Twins Wilds",
                        slotGameImg: "/common/imgs/mgp/SMG_luckyTwinsWilds.png",
                        slotGameLink: "SMG_luckyTwinsWilds"
                    },
                    {
                        rtp: 89,
                        providerName: "mgp",
                        slotGameName: "Candy Rush Wilds",
                        slotGameImg: "/common/imgs/mgp/SMG_candyRushWilds.png",
                        slotGameLink: "SMG_candyRushWilds"
                    },
                    {
                        rtp: 97,
                        providerName: "mgp",
                        slotGameName: "4 Masks of Inca",
                        slotGameImg: "/common/imgs/mgp/SMG_4MasksOfInca.png",
                        slotGameLink: "SMG_4MasksOfInca"
                    },
                    {
                        rtp: 93,
                        providerName: "mgp",
                        slotGameName: "Masters of Olympus",
                        slotGameImg: "/common/imgs/mgp/SMG_mastersOfOlympus.png",
                        slotGameLink: "SMG_mastersOfOlympus"
                    },
                    {
                        rtp: 95,
                        providerName: "pm",
                        slotGameName: "Sweet Bonanza 1000",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vs20fruitswx.png",
                        slotGameLink: "vs20fruitswx"
                    },
                    {
                        rtp: 93,
                        providerName: "pm",
                        slotGameName: "Mahjong Wins 2",
                        slotGameImg: "https://zp77h9lsxh.tlqkltxtqi.net/game_pic/square/200/vswaysmahwin2.png",
                        slotGameLink: "vswaysmahwin2"
                    },
                ];

                // Sort sequence request
                if (provider === 'all' && ['all', 'new', 'hot', 'classic', 'megaways', 'buy bonus', 'reel kingdom'].includes(category)) {
                    let firstLayerList = [],
                        secondLayerList = [],
                        gameOrders = {
                            all: ['vs20olympx', 'vswaysmahwblck', 'vs20starlightx', 'vs20olympgate', 'vs20fruitswx', 'vswaysmahwin2', '66', '69', 'vs20luxegates', 'vs5joker', 'SMG_almightyZeusEmpire', 'SMG_luckyTwinsWilds', '1301', 'SMG_candyRushWilds', 'SMG_4MasksOfInca', 'SMG_mastersOfOlympus'],
                            new: ['vs20fourmc', 'vswaysmahwblck', 'vswayssevenc', 'vs10fangfree', 'vswayswbounty', ],
                            hot: ['vs20olympgate', 'vswaysmahwblck', 'vs20starlight', 'vs5joker', 'vs20olympx', 'vs20starlightx', '66', '69', 'vs20luxegates', 'vs5aztecgems', 'SMG_almightyZeusEmpire', 'SMG_luckyTwinsWilds', 'vs20fruitswx', 'SMG_candyRushWilds', 'SMG_4MasksOfInca', 'SMG_mastersOfOlympus'],
                            classic: ['vs5aztecgems', 'vs5joker', 'vs9aztecgemsdx', 'vs10firestrike', 'vs5jjwild', 'vs1dragon8', 'vs25mustang', 'vs15diamond', 'vs25chilli', 'vs20rhino', 'vs1masterjoker', 'vs25dragonkingdom', 'vs5hotburn', 'vs5super7', 'vs25wolfgold', ],
                            megaways: ['vswayslions', 'vswaysrhino', 'vswayshammthor', 'vswaysbufking', 'vswaysrabbits', 'vswaysmadame', 'vswaysdogs', 'vs20xmascarol', 'vswayswildwest', 'vswaysxjuicy', 'vs20muertos', 'vswaysmegareel', 'vswaysbkingasc', 'vswayselements', 'vswaysmegahays', 'vswaysaztecking', 'vswaysloki', 'vswayswwriches', 'vswayspowzeus', 'vswayssamurai', 'vswaysfuryodin', 'vs20mammoth', 'vswayscryscav', 'vswaysfirewmw', 'vswaysrockblst', 'vswaysbewaretd', 'vswaysoldminer', 'vswaysluckyfish', 'vswaysbbb', 'vswayschilheat', 'vswaysrsm', 'vswaysmoneyman', 'vswaysbbhas', 'vswaystut', 'vswaysfrywld', 'vswaysfltdrgny', 'vswayslofhero', 'vswayscharms', 'vs117649starz ', 'vswaysfltdrg', 'vswayswerewolf', 'vswaysmegwghts', ],
                            'buy bonus': ['vs20olympx', 'vs20starlightx', 'vs20olympgate', 'vs20fruitswx', 'vswaysmahwin2', 'vs20starlight', 'vs20procountx', 'vs20gatotx', 'vs20fruitsw', 'vs20sugarrushx', 'vs20pbonanza', 'vs1024mjwinbns', 'vs20luxegates', 'vs20sbxmas', 'vs20mkrush', 'vs20bonzgold', 'vs20rujakbnz', 'vs20gatotgates', 'vs20sugarrush', 'vs20procount', 'vswayslions', 'vs20olympdice', 'vs40wildwest', 'vswaysrhino', 'vs20candvil', 'vs20bnnzdice', 'vs20schristmas', 'vs20aztecgates', 'vs20ninjapower', 'vs15godsofwar', 'vs20fruitparty ', 'vs20forge', 'vswayshammthor', 'vs20porbs', 'vs10dgold88', 'vs20candyblitz', 'vswaysbufking', 'vs20sugrux', 'vs20sugarnudge', 'vswaysdogs', 'vs25checaishen', 'vs20goldfever', 'vswaysmadame', 'vs20olympgrace', 'vswaysrabbits', 'vs20xmascarol', 'vs20gembondx', 'vswayslight', 'vs20dhcluster', 'vswaysstampede', 'vs20portals', 'vs20bblitz', 'vswaysxjuicy', 'vswaysmegwghts', 'vswayswildwest', 'vs20goldclust', 'vs15fghtmultlv', 'vs20cjcluster', 'vs20cbrhst', 'vswayscashconv', 'vs20fortbon', 'vs20mochimon', 'vswaysgoldcol', 'vswaysmegareel', 'vs20trswild3', 'vs20heartcleo', 'vs20elevclust', 'vs20muertos', 'vs20doghouse2', 'vs25hotfiesta', 'vs20sugarcoins', 'vs20santawonder', 'vs25goldparty', 'vs20midas2', 'vswaysaztecking', 'vswaysjapan', 'vswayskrakenmw', 'vs20dhcluster2', 'vs10txbigbass', 'vswayswwriches', 'vs20doghousemh', 'vs20clustcol', 'vswayssamurai', 'vs20fourmc', 'vs25badge', 'vs20swordofares', 'vs20midas', 'vs10bbfloats', 'vs10bxmasbnza', 'vswaysanime', 'vs10bbdoubled', 'vs20powerwild', 'vs20fparty2', 'vs4096bufking', 'vswaysstrlght', 'vs20dugems', 'vs20stickywild', 'vs20trsbox', 'vs20mesmult', 'vswaysrockblst', 'vs20mammoth', 'vs20pistols', 'vs20superlanche', 'vs20framazon', 'vs12bbbxmas', 'vs12scode', 'vs10bblotgl', 'vs10bbhas', 'vs20sbpnudge', 'vswayswildgang', 'vs20cleocatra', 'vs10gizagods', 'vs15samurai4', 'vs20jewelparty', 'vswaysfltdrgny', 'vswayscryscav', 'vs20devilic', 'vs20farmfest', 'vs20clspwrndg', 'vs10hottb7fs', 'vs20drgbless', 'vs20jhunter', 'vswaysfuryodin', 'vs50juicyfr', 'vs20forgewilds', 'vs40wildrun', 'vswaysoldminer', 'vs25rlbank', 'vs15seoultrain', 'vs10bbfmission', 'vs10bhallbnza', 'vswayspizza', 'vs20clustwild', 'vs1600drago', 'vs20bigdawgs', 'vs12tropicana', 'vs4096magician', 'vswaysyumyum', 'vs10bbextreme', 'vs1024temuj', 'vswayslofhero', 'vs10dyndigd', 'vs25wildies', 'vs20stickypos', 'vs10fdrasbf', 'vs10bbsplxmas', 'vswayshexhaus', 'vs40cosmiccash', 'vs10coffee', 'vswaysjkrdrop', 'vs10fangfree', 'vs10bbbrlact', 'vs20wildman', 'vswaysultrcoin', 'vs20kraken', 'vs10fisheye', 'vs10bbkir', 'vs10nudgeit', 'vswayscongcash', 'vswaysmegahays', 'vs20bermuda', 'vs10trail', 'vs20kraken2', 'vs20octobeer', 'vs20multiup', 'vs20bchprty', 'vs20crankit', 'vswaysluckyfish', 'vs10bookfallen', 'vswaystut', 'vswaysmonkey', 'vs50jucier', 'vs20chickdrop', 'vs20medusast', 'vswayschilheat', 'vs20maskgame', 'vs40samurai3', 'vswayszombcarn', 'vs40stckwldlvl', 'vs20beefed', 'vs40bigjuan', 'vs20wildparty', 'vswaysmoneyman', 'vswaysconcoll', 'vs20gravity', 'vswayswbounty', 'vs25kfruit', 'vswayswerewolf', 'vs20mparty', 'vs243queenie', 'vs10noodles', 'vs20bison', 'vs20mergedwndw', 'vs10powerlines', 'vs50dmdcascade', 'vs20shootstars', 'vswaysstrwild', 'vs50jfmulthold', 'vswaysfltdrg', 'vs20cashmachine', 'vs1024gmayhem', 'vs10bhallbnza2', 'vs20trswild2', 'vswayscharms', 'vs10gdchalleng', 'vswaysbewaretd', 'vs20earthquake', 'vswaysbbhas', 'vs10strawberry', 'vs20wildboost', 'vs10mmm', 'vs25holiday', 'vs20yotdk', 'vs20lvlup', 'vswaysmorient', 'vs10tictac', 'vs10runes', 'vs20nilefort', 'vswaysrsm', 'vs40infwild', 'vswaysfrbugs', 'vs10frontrun', 'vs20stckwldsc', 'vswayshive', 'vs20emptybank', 'vs10jnmntzma', 'vs20daydead', 'vs25archer', 'vswaysspltsym', 'vswaysfrywld', 'vs20underground', 'vs20rainbowg', 'vs20clustext', 'vs20lampinf', 'vs4096robber', 'vswaysalterego', 'vswaysexpandng', 'vs10bburger', 'vs20hstgldngt', 'vs20ltng', 'vs10bookoftut', 'vs10tut', 'vs20loksriches', 'vs1024moonsh', 'vs20piggybank', 'vs40pirgold', 'vs20gobnudge', 'vs50northgard', 'vs20splmystery', 'vs40demonpots', 'vs40voodoo', 'vs20sknights', 'vs20wolfie', 'vs10luckfort', 'vswayscfglory', 'vs243nudge4gold', 'vs10wildtut', 'vswaysftropics', 'vs20mmmelon', 'vswaystimber', 'vs40hotburnx', 'vs20lobseafd', 'vs10spiritadv', 'vs20lobcrab', 'vs20hotzone', 'vs10ddcbells', 'vs25spgldways', 'vs10kingofdth', 'vswaysincwnd', 'vswaysbook', 'vswayssevenc', 'vs20excalibur', 'vs40rainbowr', 'vswaysbkingasc', 'vs9outlaw', 'vs10bbbnz', 'vswayspowzeus', 'vs20gatotfury', 'vswayscheist', 'vs20laughluck', ],
                            'reel kingdom': ['vs10txbigbass', 'vs10bbbonanza', 'vs12bbb', 'vs10bbfloats', 'vs10bbextreme', 'vs10bbhas', 'vs25goldparty', 'vs10bxmasbnza', 'vs10bhallbnza', 'vs12bbbxmas', 'vs10bbkir', 'vs10bbbnz', 'vs10bbsplxmas', 'vswaysstampede', 'vs10bblotgl', 'vs10floatdrg', 'vs12tropicana', 'vs432congocash', 'vswaysbbb', 'vswaysbbhas',],
                        };

                    // Find game base on list gameOrders
                    gameOrders[category].forEach(g => {
                        let modGame = modifiedGames.find(f => f.slotGameLink === g),
                            theGame = modGame || gameList.find(f => f.slotGameLink === g);

                        if (theGame) {
                            if (!modGame && res["rtpEnable"]) {
                                localStorage.setItem(g, theGame.rtp);
                            }

                            theGame.rtp = localStorage.getItem(g) || theGame.rtp; // Update rtp
                            firstLayerList.push(theGame);
                        }
                    });

                    secondLayerList = gameList.filter(item => !firstLayerList.find(f => f.slotGameLink === item.slotGameLink));

                    gameList = [].concat(firstLayerList, secondLayerList);
                }

                if (provider === 'pm' && ['all', 'hot', 'classic', 'buy bonus', 'reel kingdom', 'megaways', 'new'].includes(category)) {
                    let firstLayerList = [],
                        secondLayerList = [],
                        gameOrders = {
                            all: ['vs20olympx', 'vswaysmahwblck', 'vs20starlightx', 'vs20olympgate', 'vs20fruitswx', 'vswayswbounty', 'vswaysmahwin2', 'vs20starlight', 'vs20procountx', 'vs20gatotx', 'vs5joker', 'vs5aztecgems', 'vs20luxegates', 'vs5triple8gold', '1301', 'vs20fruitsw', 'vs20sugarrushx', 'vs20pbonanza', 'vs1024mjwinbns', 'vs20sbxmas', '2201', 'vs20mkrush', 'vs20bonzgold', 'vs20rujakbnz', 'vs20gatotgates', 'vs20sugarrush', 'vs20procount', 'vs1024mahjwins', 'vswayslions', 'vs20olympdice', 'vs40wildwest', 'vswaysrhino', 'vs20candvil', 'vs20bnnzdice', 'vs20schristmas', 'vs9aztecgemsdx', 'vs20aztecgates', 'vs20ninjapower', 'vs15godsofwar', 'vs20fruitparty ', 'vs20forge', 'vs20candybltz2', 'vs7776aztec', 'vswayshammthor', 'vs20porbs', 'vs10dgold88', 'vs20candyblitz', 'vswaysbufking', 'vs20sugrux', 'vs20sugarnudge', 'vswaysdogs', 'vs25checaishen', 'vs20goldfever', 'vswaysmadame', 'vs10firestrike', 'vs20olympgrace', 'vs25scarabqueen', 'vs5magicdoor', ],
                            hot: ['vs20olympgate', 'vswaysmahwblck', 'vs20starlight', 'vs5joker', 'vs20olympx', 'vs20starlightx', 'vs5aztecgems', 'vs20fruitswx', 'vswaysmahwin2', 'vs20procountx', 'vs5triple8gold', 'vs20gatotx', 'vs20luxegates', 'vs20sugarrushx', 'vs1024mjwinbns', 'vs20fruitsw', 'vs20pbonanza', 'vs20rujakbnz', 'vs20mkrush', 'vs20bonzgold', 'vs20sbxmas', ],
                            classic: ['vs5aztecgems', 'vs5joker', 'vs9aztecgemsdx', 'vs10firestrike', 'vs5jjwild', 'vs1dragon8', 'vs25mustang', 'vs15diamond', 'vs25chilli', 'vs20rhino', 'vs1masterjoker', 'vs25dragonkingdom', 'vs5hotburn', 'vs5super7', 'vs25wolfgold', ],
                            'buy bonus': ['vs20olympx', 'vs20starlightx', 'vs20olympgate', 'vs20fruitswx', 'vswaysmahwin2', 'vs20starlight', 'vs20procountx', 'vs20gatotx', 'vs20fruitsw', 'vs20sugarrushx', 'vs20pbonanza', 'vs1024mjwinbns', 'vs20luxegates', 'vs20sbxmas', 'vs20mkrush', 'vs20bonzgold', 'vs20rujakbnz', 'vs20gatotgates', 'vs20sugarrush', 'vs20procount', 'vswayslions', 'vs20olympdice', 'vs40wildwest', 'vswaysrhino', 'vs20candvil', 'vs20bnnzdice', 'vs20schristmas', 'vs20aztecgates', 'vs20ninjapower', 'vs15godsofwar', 'vs20fruitparty ', 'vs20forge', 'vswayshammthor', 'vs20porbs', 'vs10dgold88', 'vs20candyblitz', 'vswaysbufking', 'vs20sugrux', 'vs20sugarnudge', 'vswaysdogs', 'vs25checaishen', 'vs20goldfever', 'vswaysmadame', 'vs20olympgrace', 'vswaysrabbits', 'vs20xmascarol', 'vs20gembondx', 'vswayslight', 'vs20dhcluster', 'vswaysstampede', 'vs20portals', 'vs20bblitz', 'vswaysxjuicy', 'vswaysmegwghts', 'vswayswildwest', 'vs20goldclust', 'vs15fghtmultlv', 'vs20cjcluster', 'vs20cbrhst', 'vswayscashconv', 'vs20fortbon', 'vs20mochimon', 'vswaysgoldcol', 'vswaysmegareel', 'vs20trswild3', 'vs20heartcleo', 'vs20elevclust', 'vs20muertos', 'vs20doghouse2', 'vs25hotfiesta', 'vs20sugarcoins', 'vs20santawonder', 'vs25goldparty', 'vs20midas2', 'vswaysaztecking', 'vswaysjapan', 'vswayskrakenmw', 'vs20dhcluster2', 'vs10txbigbass', 'vswayswwriches', 'vs20doghousemh', 'vs20clustcol', 'vswayssamurai', 'vs20fourmc', 'vs25badge', 'vs20swordofares', 'vs20midas', 'vs10bbfloats', 'vs10bxmasbnza', 'vswaysanime', 'vs10bbdoubled', 'vs20powerwild', 'vs20fparty2', 'vs4096bufking', 'vswaysstrlght', 'vs20dugems', 'vs20stickywild', 'vs20trsbox', 'vs20mesmult', 'vswaysrockblst', 'vs20mammoth', 'vs20pistols', 'vs20superlanche', 'vs20framazon', 'vs12bbbxmas', 'vs12scode', 'vs10bblotgl', 'vs10bbhas', 'vs20sbpnudge', 'vswayswildgang', 'vs20cleocatra', 'vs10gizagods', 'vs15samurai4', 'vs20jewelparty', 'vswaysfltdrgny', 'vswayscryscav', 'vs20devilic', 'vs20farmfest', 'vs20clspwrndg', 'vs10hottb7fs', 'vs20drgbless', 'vs20jhunter', 'vswaysfuryodin', 'vs50juicyfr', 'vs20forgewilds', 'vs40wildrun', 'vswaysoldminer', 'vs25rlbank', 'vs15seoultrain', 'vs10bbfmission', 'vs10bhallbnza', 'vswayspizza', 'vs20clustwild', 'vs1600drago', 'vs20bigdawgs', 'vs12tropicana', 'vs4096magician', 'vswaysyumyum', 'vs10bbextreme', 'vs1024temuj', 'vswayslofhero', 'vs10dyndigd', 'vs25wildies', 'vs20stickypos', 'vs10fdrasbf', 'vs10bbsplxmas', 'vswayshexhaus', 'vs40cosmiccash', 'vs10coffee', 'vswaysjkrdrop', 'vs10fangfree', 'vs10bbbrlact', 'vs20wildman', 'vswaysultrcoin', 'vs20kraken', 'vs10fisheye', 'vs10bbkir', 'vs10nudgeit', 'vswayscongcash', 'vswaysmegahays', 'vs20bermuda', 'vs10trail', 'vs20kraken2', 'vs20octobeer', 'vs20multiup', 'vs20bchprty', 'vs20crankit', 'vswaysluckyfish', 'vs10bookfallen', 'vswaystut', 'vswaysmonkey', 'vs50jucier', 'vs20chickdrop', 'vs20medusast', 'vswayschilheat', 'vs20maskgame', 'vs40samurai3', 'vswayszombcarn', 'vs40stckwldlvl', 'vs20beefed', 'vs40bigjuan', 'vs20wildparty', 'vswaysmoneyman', 'vswaysconcoll', 'vs20gravity', 'vswayswbounty', 'vs25kfruit', 'vswayswerewolf', 'vs20mparty', 'vs243queenie', 'vs10noodles', 'vs20bison', 'vs20mergedwndw', 'vs10powerlines', 'vs50dmdcascade', 'vs20shootstars', 'vswaysstrwild', 'vs50jfmulthold', 'vswaysfltdrg', 'vs20cashmachine', 'vs1024gmayhem', 'vs10bhallbnza2', 'vs20trswild2', 'vswayscharms', 'vs10gdchalleng', 'vswaysbewaretd', 'vs20earthquake', 'vswaysbbhas', 'vs10strawberry', 'vs20wildboost', 'vs10mmm', 'vs25holiday', 'vs20yotdk', 'vs20lvlup', 'vswaysmorient', 'vs10tictac', 'vs10runes', 'vs20nilefort', 'vswaysrsm', 'vs40infwild', 'vswaysfrbugs', 'vs10frontrun', 'vs20stckwldsc', 'vswayshive', 'vs20emptybank', 'vs10jnmntzma', 'vs20daydead', 'vs25archer', 'vswaysspltsym', 'vswaysfrywld', 'vs20underground', 'vs20rainbowg', 'vs20clustext', 'vs20lampinf', 'vs4096robber', 'vswaysalterego', 'vswaysexpandng', 'vs10bburger', 'vs20hstgldngt', 'vs20ltng', 'vs10bookoftut', 'vs10tut', 'vs20loksriches', 'vs1024moonsh', 'vs20piggybank', 'vs40pirgold', 'vs20gobnudge', 'vs50northgard', 'vs20splmystery', 'vs40demonpots', 'vs40voodoo', 'vs20sknights', 'vs20wolfie', 'vs10luckfort', 'vswayscfglory', 'vs243nudge4gold', 'vs10wildtut', 'vswaysftropics', 'vs20mmmelon', 'vswaystimber', 'vs40hotburnx', 'vs20lobseafd', 'vs10spiritadv', 'vs20lobcrab', 'vs20hotzone', 'vs10ddcbells', 'vs25spgldways', 'vs10kingofdth', 'vswaysincwnd', 'vswaysbook', 'vswayssevenc', 'vs20excalibur', 'vs40rainbowr', 'vswaysbkingasc', 'vs9outlaw', 'vs10bbbnz', 'vswayspowzeus', 'vs20gatotfury', 'vswayscheist', 'vs20laughluck', ],
                            'reel kingdom': ['vs10txbigbass', 'vs10bbbonanza', 'vs12bbb', 'vs10bbfloats', 'vs10bbextreme', 'vs10bbhas', 'vs25goldparty', 'vs10bxmasbnza', 'vs10bhallbnza', 'vs12bbbxmas', 'vs10bbkir', 'vs10bbbnz', 'vs10bbsplxmas', 'vswaysstampede', 'vs10bblotgl', 'vs10floatdrg', 'vs12tropicana', 'vs432congocash', 'vswaysbbb', 'vswaysbbhas',],
                            megaways: ['vswayslions', 'vswaysrhino', 'vswayshammthor', 'vswaysbufking', 'vswaysrabbits', 'vswaysmadame', 'vswaysdogs', 'vs20xmascarol', 'vswayswildwest', 'vswaysxjuicy', 'vs20muertos', 'vswaysmegareel', 'vswaysbkingasc', 'vswayselements', 'vswaysmegahays', 'vswaysaztecking', 'vswaysloki', 'vswayswwriches', 'vswayspowzeus', 'vswayssamurai', 'vswaysfuryodin', 'vs20mammoth', 'vswayscryscav', 'vswaysfirewmw', 'vswaysrockblst', 'vswaysbewaretd', 'vswaysoldminer', 'vswaysluckyfish', 'vswaysbbb', 'vswayschilheat', 'vswaysrsm', 'vswaysmoneyman', 'vswaysbbhas', 'vswaystut', 'vswaysfrywld', 'vswaysfltdrgny', 'vswayslofhero', 'vswayscharms', 'vs117649starz ', 'vswaysfltdrg', 'vswayswerewolf', 'vswaysmegwghts', ],
                        };

                    if (gameOrders[category] !== undefined) {
                        $.each(gameList, function(i, item) {
                            if (gameOrders[category].indexOf(item.slotGameLink) != -1) {
                                firstLayerList.push(item);
                            } else {
                                secondLayerList.push(item);
                            }
                        });

                        gameList = [].concat(
                            firstLayerList.sort(function(a, b) {
                                return gameOrders[category].indexOf(a.slotGameLink) - gameOrders[category].indexOf(b.slotGameLink)
                            }),
                            secondLayerList
                        );
                    }
                }

                if (provider === 'pg') {
                    let gameOrders = ['65', '74'];

                    gameList = gameList.sort((a, b) => {
                        let ia = gameOrders.indexOf(a.slotGameLink);
                        let ib = gameOrders.indexOf(b.slotGameLink);

                        if (ia === -1) ia = gameOrders.length;
                        if (ib === -1) ib = gameOrders.length;

                        return ia - ib;
                    });
                }

                // // Push PM "Club Tropicana" game in No.1 in All / Hot / Buy Bonus games (For all providers & PP Slots games)
                // let listCat = ['', 'undefined', 'hot', 'buy bonus'];
                // let vs12tropicana = gameList.filter(f => f.slotGameLink === 'vs12tropicana');

                // if (((listCat.indexOf(String(provider)) > -1 && listCat.indexOf(String(category)) > -1) || (String(provider) == 'pm' && listCat.indexOf(String(category)) > -1)) && vs12tropicana.length == 1) {
                //     var links = ['vs12tropicana'], arrSelected = [], arrNormal = []
                //     $.each(gameList, function(i, item) {
                //         if(links.indexOf(item['slotGameLink']) > -1){
                //         arrSelected.push(item);
                //         } else {
                //         arrNormal.push(item);
                //         }
                //     });

                //     gameList = [].concat(arrSelected, arrNormal);
                // }

                if (_today >= 20230725 && _today <= 20230830 && (provider === 'pm' || provider === 'all')) {
                    var games = gameList.filter(f => f["slotGameLink"] === 'vs50dmdcascade');

                    // if game not found
                    if (games.length === 0) {
                        gameList.push({
                            "rtp": localStorage.getItem('rtp_vs50dmdcascade') || 90,
                            "providerName": "pm",
                            "slotGameName": "Diamond Cascade",
                            "slotGameImg": "/common/imgs/pragmatic/vs50dmdcascade.png",
                            "slotGameLink": "vs50dmdcascade"
                        });
                    } else if (localStorage.getItem('rtp_vs50dmdcascade') == null) {
                        localStorage.setItem('rtp_vs50dmdcascade', games[0].rtp != undefined ? games[0].rtp : 90); // Old browser not support games[0]?.rtp || 90
                    }

                    // Push PM "Diamond Cascade" game No.1 in All / Hot / Buy Bonus games (For all providers & PP Slots games)
                    var listCatDiamondCascade = ['all', 'hot', 'buy bonus'];

                    if (listCatDiamondCascade.includes(category)) {
                        var arrSelected = [],
                            arrNormal = []
                        $.each(gameList, function(i, item) {
                            if (item['slotGameLink'] === 'vs50dmdcascade') {
                                arrSelected.push(item);
                            } else {
                                arrNormal.push(item);
                            }
                        });

                        gameList = [].concat(arrSelected, arrNormal);
                    }
                }

                $.each(gameList, function(i, item) {
                    var gameName = item['slotGameName'],
                        gameIMG = item['slotGameImg'],
                        gameCode = item['slotGameLink'],
                        gameProvider = item['providerName'],
                        pvdDIV = '',
                        pageForROW = Math.ceil((i + 1) / pageLimit),
                        pageC = '',
                        badge = '';

                    if (provider === 'all') {
                        if (pageForROW <= 1) {
                            pageC = 'ppp ppp-' + pageForROW
                        } else {
                            pageC = 'hh ppp ppp-' + pageForROW
                        }
                        pvdDIV = '<div class="glp pvd ' + gameProvider + '"></div>'
                    }

                    if (provider == 'pm') {
                        if (category == 'hot') {
                            badge = '<div class="glbadge"><img src="/common/imgs/pp/daily-wins-en.png"></div>'
                            if (gameCode == '0000') {
                                badge = ''
                            }
                        } else if (category == 'new') {
                            badge = '<div class="glbadge"><img src="/common/imgs/pp/new-en.png"></div>'
                            if (gameCode == '0000') {
                                badge = ''
                            }
                        } else if (category == 'buy bonus') {
                            badge = '<div class="glbadge"><img src="/common/imgs/pp/bonus-en.png"></div>'
                            if (gameCode == '0000') {
                                badge = ''
                            }
                        }
                    } else if (provider == 'jk' && category == 'hot') {
                        badge = '<div class="glbadge joker-hot"><img src="/common/imgs/joker/hot.png"></div>'
                    }

                    // PM request: Mahjong Wins 3 - Black Scatter
                    if (gameCode == 'vswaysmahwblck') {
                        badge = '<div class="glbadge"><img src="/common/imgs/pp/viral.png"></div>'
                    }

                    var rtp = '';

                    if (item.rtp != undefined && res["rtpEnable"]) {
                        var class_color = item.rtp <= 30 ? 'red' : (item.rtp >= 31 && item.rtp <= 74 ? 'yellow' : (item.rtp > 74 ? 'green' : ''));
                        rtp = `<div class="rtp-container"><div class="${class_color}" style="width: ${item.rtp}%">&nbsp;</div><span>${item.rtp}%</span></div>`; // RTP
                    }

                    $('.g8sggl .glbox').append(`
                        <div class="gl ${pageC}">
                            <div class="glimg ${globalObj.login ? 'j-winopen' : 's-check'}" action="slot-${gameProvider}" gc="${gameCode}">
                                ${badge}
                                <div class="glpic">
                                    <img src="${gameIMG}" alt="${gameName}" loading="lazy">
                                </div>
                                <div class="hwrap">
                                    <div class="hbox">
                                        <a href="javascript:void(0)" class="main">Main</a>
                                    </div>
                                </div>
                            </div>
                            ${rtp}
                            <div class="gltext">${gameName}</div>
                            ${pvdDIV}
                        </div>
                    `);

                    if (provider === 'all') {
                        if (!$('.goppp[dd=' + pageForROW + ']').length) {
                            var pagiActive = ''
                            if (pageForROW <= 1) {
                                pagiActive = 'aaa'
                            }
                            $('.g8sggl .glpagi').append('<div class="pagi ' + pagiActive + ' goppp" dd="' + pageForROW + '">' + pageForROW + '</div>');
                        }
                    }
                });
            } else {
                $('.g8sggl .glmsg').show().text('Could not find the game you were looking for, please try search others game.');
            }

            checkLRarrow()
        }
    });
}

function getG8sgPS() {

    $('.g8sggl-ps .glbox').empty();

    var ddddd = 'categoryName=hot&group=1';

    if (!globalObj.login) {
        ajaxURL = '/func/stl/getSlotGameList'
    } else {
        ajaxURL = '/ajax/stl/getSlotGameList'
    }

    $.ajax({
        type: "GET",
        url: ajaxURL,
        data: ddddd,
        dataType: 'json',
        async: false,
        success: function(res) {

            var gameList = res["slotGameList"];

            if (gameList.length) {

                var arrObjGLSpecial = [],
                    arrObjGLfirst = [],
                    arrObjGLsecond = [],
                    arrObjGLfinal;

                $.each(gameList, function(i, item) {
                    if (item['providerName'] == 'pm' && item['slotGameLink'] == 'vs20olympgate') {
                        arrObjGLSpecial.push(item);
                    } else if (item['providerName'] == 's88') {
                        arrObjGLfirst.push(item);
                    } else {
                        arrObjGLsecond.push(item);
                    }
                })

                arrObjGLfinal = [].concat(arrObjGLSpecial, arrObjGLfirst, arrObjGLsecond);

                gameList = arrObjGLfinal;

                $.each(gameList, function(i, item) {

                    if (i > 19) {
                        return false
                    }

                    var gameName = item['slotGameName'],
                        gameIMG = item['slotGameImg'],
                        gameCode = item['slotGameLink'],
                        gameProvider = item['providerName'];

                    if (!globalObj.login) {
                        $('.g8sggl-ps .glbox').append('\
                        <div class="gl">\
                            <div class="glimg s-check"><div class="glpic"><img src="' + gameIMG + '" alt="' + gameName + '" loading="lazy"></div><div class="hwrap"><div class="hbox"><a href="javascript:void(0)" class="main">Main</a></div></div></div>\
                            <div class="gltext">' + gameName + '</div>\
                        </div>\
                        ')
                    } else {
                        $('.g8sggl-ps .glbox').append('\
                        <div class="gl">\
                            <div class="glimg j-winopen" action="slot-' + gameProvider + '" gc="' + gameCode + '"><div class="glpic"><img src="' + gameIMG + '" alt="' + gameName + '" loading="lazy"></div><div class="hwrap"><div class="hbox"><a href="javascript:void(0)" class="main">Main</a></div></div></div>\
                            <div class="gltext">' + gameName + '</div>\
                        </div>\
                        ')
                    }

                });
            }

        }
    });

}

function checkLRarrow() {
    $('.g8sggl .g8sggl-c .ll').each(function() {
        if ($(this).find('.ww')[0].scrollWidth - $(this).find('.ww').outerWidth() - 10 <= $(this).find('.ww').scrollLeft()) {
            $(this).find('.g8sggl-tarr.r').hide();
        } else {
            $(this).find('.g8sggl-tarr.r').show();
        }
    })
}

function sortCatList() {
    var items = $('.g8sggl .glcat .ww');
    items.each(function() {
        $(this).find('.gocat').sort(function(a, b) {
            return +$(a).attr('ss') - +$(b).attr('ss');
        }).appendTo($(this));
    });
}