function fullScreenAds(link, img_L, bg, opacity){
	if(isEmpty(img_L)){
		return;
	}
	if(isEmpty(bg)){
		bg = '#cecece';
	}
	if(isEmpty(opacity)){
		opacity = '0.8';
	}
	var	img = img_L;

	var popupelement = '<div id="full_screen_div">';
	popupelement += '<div id="full_screen_overlay" style="background-color: '+bg+'; width: 100%; height: 100%; margin: 0px; padding: 0px; position: fixed; top: 0px; left: 0px; right: 0px; border: 0px; filter: alpha(opacity = '+(opacity*100)+'); opacity: '+ opacity +'; z-index: 21474836400;"  onclick="closeFullSceenAds()">';
	popupelement += '</div>';
	popupelement += '<div id="full_screen_ads" style="transition: all 0.5s ease-in-out 0s; margin: 0px; padding: 0px; position: fixed; width: 100%; height: 100%; top: 0px; right: 0px; z-index: 21474836470; background: transparent; opacity: 1;" onclick="closeFullSceenAds()">';
	popupelement += '<div style="display: table; height: 100%; width: 100%; min-height: 100%; z-index: 21474836470; background: transparent;">';
	popupelement += '<div style="display: table-cell; vertical-align: middle; text-align: center; background: transparent;">';
	popupelement += '<a href="'+link+'" target="_blank">';
	popupelement += '<img class="desktop-full-screen-img" src="'+img+'"/>';
	popupelement += '</a>';
	popupelement +=  '</div>';
	popupelement +=  '</div>';
	popupelement += '<div style="width: 50px; height: 50px; position: absolute; top: 10px; right: 15px; z-index: 21474836470; background: rgba(0, 0, 0, 0) url(\'/public/images/full-ads-close_v2.png\') repeat scroll 0 0; cursor: pointer;"id="full_screen_btn_close" onclick="closeFullSceenAds()"></div>';
	popupelement +=  '</div>';
	popupelement +=  '</div>';
	
	jQuery("body").append(popupelement);
}

// disable full screen for google compliance
// function fullScreenMobileAds(link, img_L, bg, opacity, closeHPos="right: 10px;", closeVPos="top: 10px;"){
// 	if(isEmpty(img_L)){
// 		return;
// 	}
// 	if(isEmpty(bg)){
// 		bg = '#cecece';
// 	}
// 	if(isEmpty(opacity)){
// 		opacity = '0.8';
// 	}
// 	var	img = img_L;

// 	var popupelement = '<style>.mobile-full-screen-img{max-height: calc(100vh - 50px) !important; }</style><div id="full_screen_div">';
// 	popupelement += '<div id="full_screen_overlay" style="background-color: '+bg+'; width: 100%; height: 100%; margin: 0px; padding: 0px; position: fixed; top: 0px; left: 0px; right: 0px; border: 0px; filter: alpha(opacity = '+(opacity*100)+'); opacity: '+ opacity +'; z-index: 21474836400;"  onclick="closeFullSceenAds()">';
// 	popupelement += '</div>';
// 	popupelement += '<div id="full_screen_ads" style="transition: all 0.5s ease-in-out 0s; margin: 0px; padding: 0px; position: fixed; width: 100%; height: 100%; top: 0px; right: 0px; z-index: 21474836470; background: transparent; opacity: 1;" onclick="closeFullSceenAds()">';
// 	popupelement += '<div style="display: table; height: 100%; width: 100%; min-height: 100%; z-index: 21474836470; background: transparent;">';
// 	popupelement += '<div style="display: table-cell; vertical-align: middle; text-align: center; background: transparent;">';
// 	popupelement += '<a style="display:block" href="'+link+'" target="_blank">';
// 	popupelement += '<img class="mobile-full-screen-img" style="max-height: calc(100vh - 50px);" src="'+img+'"/>';
// 	popupelement += '</a>';
// 	popupelement +=  '</div>';
// 	popupelement +=  '</div>';
// 	popupelement += '<div style="width: 45px; height: 45px; position: absolute; '+ closeHPos +' '+ closeVPos+' z-index: 21474836470; background: rgba(0, 0, 0, 0) url(\'/public/images/btn_close_brown.png\') repeat scroll 0 0; cursor: pointer;"id="full_screen_btn_close" onclick="closeFullSceenAds()"></div>';
// 	popupelement +=  '</div>';
// 	popupelement +=  '</div>';
	
// 	jQuery("body").append(popupelement);
// }
function closeFullSceenAds(){
	jQuery('#full_screen_div').css('display', 'none');
	jQuery('#full_screen_div').remove();
}
function isEmpty(value) {
    return typeof value == 'string' && !value.trim() || typeof value == 'undefined' || value === null;
}
function  bottomCarwlerAds(link, img){
	if(isEmpty(img)){
		return;
	} 
	var the_html = '<div id="bottom-crawler-wrapper" class="bottom-crawler-wrapper"><div style="display:block; margin-left:auto; margin-right:auto; width:970px; position:relative">\
						<a style="display:block; width:100%"  href="'+link+'" target="_blank">\
							<span class="bottom-crawler-close" onclick="window.parent.closeBottomCrawler();">×</span>\
							<img  src="'+img+'" style="width:100%"/>\
						</a>\
					</div></div>';

	jQuery("body").append(the_html);
}
function closeBottomCrawler(){
	var sty_div = document.getElementById("bottom-crawler-wrapper");
	sty_div.parentNode.removeChild(sty_div);
}


function load_floating_slide_in(){

    let ajx_url = "/ajx-api/floating-slide-in-ads/";

    $.getJSON(ajx_url, function (data) {
        if(typeof data.icon !== "undefined"){
            let extra_style = "";
            if(typeof data.icon_desktop_width  !== "undefined" && data.icon_desktop_width !== "" && $("body").width() > 600){
                extra_style = ' style ="width:'+data.icon_desktop_width+'px" ';
            }
            $("body").append(`<div onclick="floating_slide_in_click()" id="floating_slide_in_icon" class="floating_slide_in_icon"  ${extra_style}>
                                <img alt="" src="${data.icon}" />
                                 <div class="floating_slide_in_icon_x" style="display:none"><span>x</span></div>
                              </div>`);
            append_define_otp_ads("/2365395/Icon_OTP_Web", "SLIDE_IN_ADS_UNIT");
        }
    });

}

var floating_slide_inW = 0;
function floating_slide_in_cb(clickurl,banner, bannerwithmacro){
    if($("#float_slide_banner").length) return;
    $("#floating_slide_in_icon").addClass("show");
    $("body").append(`
        <div class="float_slide_banner" id="float_slide_banner" data-status="hide">
            <a href="${clickurl}" target="_blank">
                <img alt="" src="${banner}" data-src="${bannerwithmacro}" />
            </a>
        </div>
        `);
    gtag('event','Premium Slider');
    floating_slide_in_effect();
}

var scrollTimer = null;
var scrollProcessing = false;
function floating_slide_in_effect(){
    floating_slide_inW  = $("#float_slide_banner").width()+"px";
    $(".floating_slide_in_icon").css("top",parseInt($(window).height() / 2 - ($(".floating_slide_in_icon").height()/2)) + "px");

    if(isMobile.any()){
        document.addEventListener('scroll', function(e) {
            if(typeof scrollTimer !== "undefined" && scrollTimer != null)
                clearTimeout(scrollTimer);
            if(scrollProcessing == false){
                scrollProcessing = true;
                if($("#float_slide_banner").attr("data-status") == "hide"){
                    $("#floating_slide_in_icon").css("right", "0");
                    $("#floating_slide_in_icon").animate({right: '-45px'});
                }
                else{
                    floating_slide_inW  = $("#float_slide_banner").width()+"px";
                    $("#float_slide_banner").attr("data-status", "hide");
                    $("#floating_slide_in_icon").css("right", floating_slide_inW);
                    $("#floating_slide_in_icon").animate({right: '-45px'});
                    $("#float_slide_banner").css("right", "0");
                    $("#float_slide_banner").animate({right: "-"+floating_slide_inW},400, function() {
                        $("#float_slide_banner").css("right", "-1000%");
                        $(".float_slide_banner_global_bg").remove();
                        $(".floating_slide_in_icon_x").css("display", "none");
                      });
                } 
            
            }
            scrollTimer=setTimeout(function(){
                scrollProcessing = false;
                $("#floating_slide_in_icon").css("right", "-45px");
                $("#floating_slide_in_icon").animate({right: '0px'});
                $("#float_slide_banner").css("right", "-1000%");
                $(".floating_slide_in_icon_x").css("display", "none");
            },800);
          });
    }
    else{
        loadJS("/public/js/mousewheel/mousewheel.min.js?v=1", true, function(){
            $(window).mousewheel(function(event) {
                if(typeof scrollTimer !== "undefined" && scrollTimer != null)
                    clearTimeout(scrollTimer);
                if(scrollProcessing == false){
                    scrollProcessing = true;
                    if($("#float_slide_banner").attr("data-status") == "hide"){
                        $("#floating_slide_in_icon").css("right", "0");
                        $("#floating_slide_in_icon").animate({right: '-45px'});
                    }
                    else{
                        floating_slide_inW  = $("#float_slide_banner").width()+"px";
                        $("#float_slide_banner").attr("data-status", "hide");
                        $("#floating_slide_in_icon").css("right", floating_slide_inW);
                        $("#floating_slide_in_icon").animate({right: '-45px'});
                        $("#float_slide_banner").css("right", "0");
                        $("#float_slide_banner").animate({right: "-"+ floating_slide_inW},400,function(){
                            $("#float_slide_banner").css("right", "-1000%");
                            $(".float_slide_banner_global_bg").remove();
                            $(".floating_slide_in_icon_x").css("display", "none");
                        });
                    } 
                
                }
                scrollTimer=setTimeout(function(){
                    scrollProcessing = false;
                    $("#floating_slide_in_icon").css("right", "-45px");
                    $("#floating_slide_in_icon").animate({right: '0px'});
                    $("#float_slide_banner").css("right", "-1000%");
                    $(".floating_slide_in_icon_x").css("display", "none");
                },200);
            });
        });
    }
   
}


function floating_slide_in_click(){
    floating_slide_inW  = $("#float_slide_banner").width()+"px";
    if($("#float_slide_banner").attr("data-status") == "hide"){
        $("#float_slide_banner").attr("data-status", "out");
        if( $("#float_slide_banner img").attr("src") != $("#float_slide_banner img").attr("data-src")){
            $("#float_slide_banner img").attr("src", $("#float_slide_banner img").attr("data-src"));
        }
        $("body").append(
            `<div class="float_slide_banner_global_bg" onclick="floating_slide_in_click()"></div>`
        );
        
        
        $("#floating_slide_in_icon").css("right", "0");
        $("#floating_slide_in_icon").animate({right: floating_slide_inW});
        $("#float_slide_banner").css("right", "-"+floating_slide_inW);
        $("#float_slide_banner").animate({right: '0px'});
        $(".floating_slide_in_icon_x").css("display", "flex");
    }
    else{
        $("#float_slide_banner").attr("data-status", "hide");
        $("#floating_slide_in_icon").css("right", floating_slide_inW);
        $("#floating_slide_in_icon").animate({right: "0"});
        $("#float_slide_banner").css("right", "0");
        $("#float_slide_banner").animate({right: "-"+floating_slide_inW},400,function(){
            $("#float_slide_banner").css("right", "-1000%");
            $(".float_slide_banner_global_bg").remove();
        });
        $(".floating_slide_in_icon_x").css("display", "none");
    } 
}

function append_define_otp_ads(adsunitpath, containerid){
    if(typeof googletag == "undefined") return;
    if(typeof googletag.cmd == "undefined") return;
    if(typeof googletag.cmd.push == "undefined") return;

    googletag.cmd.push(function() { 
        let ADSSLOT_TEMP = googletag.defineOutOfPageSlot(adsunitpath,containerid).addService(googletag.pubads());

        //adsSlots.push(ADSSLOT_TEMP);
        adsSlotsWithElementId[containerid] = ADSSLOT_TEMP;
    });

    append_display_ads($("body"), containerid, "", "ads-frame otp");      
}


function append_define_ads(adunit, containerid){
    if(typeof googletag == "undefined") return;
    if(typeof googletag.cmd == "undefined") return;
    if(typeof googletag.cmd.push == "undefined") return;

    if(typeof adsSlotsWithElementId[containerid] !== "undefined") return;
    
    if(typeof adsSlotsWithElementId[adunit] == "undefined") return;

    let adsunitpath = adsSlotsWithElementId[adunit].getAdUnitPath();
	let adUnitsizes = convertAdSlotSize(adsSlotsWithElementId[adunit].getSizes());
    googletag.cmd.push(function() { 
        let ADSSLOT_TEMP =  googletag.defineSlot(adsunitpath,adUnitsizes, containerid).addService(googletag.pubads());

        adsSlots.push(ADSSLOT_TEMP);

        if(adunit != containerid){
            adsSlotsWithElementId[containerid] = ADSSLOT_TEMP;
        }
        else{
            adsSlotsWithElementId[adunit] = ADSSLOT_TEMP;
        }
    });
}

function append_display_ads(wrapper, adunit, style="text-align:center;", container_class="ads-frame"){
    if(typeof googletag == "undefined") return;
    if(typeof googletag.cmd == "undefined") return;
    if(typeof googletag.cmd.push == "undefined") return;
    
    var content = `<div id="${adunit}" style="${style}" class="${container_class}"></div>`;    
    wrapper.append(content);
      if(typeof adsSlotsWithElementId[adunit] !== "undefined"){
        googletag.cmd.push(function() { 
                googletag.display(adunit); 
                    if(typeof membershipInitAds != "undefined" && membershipInitAds == true){
                        googletag.pubads().refresh([adsSlotsWithElementId[adunit]]);
                    }
        });
    }
}

function loadJS(FILE_URL, async = true, callbackFn = null) {
	let scriptEle = document.createElement("script");
  
	scriptEle.setAttribute("src", FILE_URL);
	scriptEle.setAttribute("type", "text/javascript");
	scriptEle.setAttribute("async", async);
  
	document.body.appendChild(scriptEle);
  
	// success event 
	scriptEle.addEventListener("load", () => {
		if(callbackFn != null){
			callbackFn();
		}
	  console.log("File loaded")
	});
	 // error event
	scriptEle.addEventListener("error", (ev) => {
	  console.log("Error on loading file", ev);
	});
  }