var googletag     = googletag || {};
    googletag.cmd = googletag.cmd || [];
 
var PB        = PB || {};
    PB.gptAds = PB.gptAds || {};

var footer = null; 
 
/*
  ====================================================================================
  Init: before DOM is loaded
  ====================================================================================
*/
(function(callable) {
 
    // Load GPT library
    (function(){
        var gads = document.createElement('script');
        gads.async = true;
        gads.type = 'text/javascript';
        var useSSL = 'https:' == document.location.protocol;
        gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js';
        var node = document.getElementsByTagName('script')[0];
        node.parentNode.insertBefore(gads, node);
    })();
 
    // Disable initial load
    
    // Define Ad slots
                                                (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: home_leaderboard*/
                                        PB.gptAds['home_61'] = googletag.defineSlot('/4403/gn.kidzworld.com/home', [[970, 90],[728, 90]], 'home_61').addService(googletag.pubads()).setTargeting("sect", "home").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                                    (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: home_sidebar_atf*/
                                        PB.gptAds['home_63'] = googletag.defineSlot('/4403/gn.kidzworld.com/home', [[300, 600],[300, 250]], 'home_63').addService(googletag.pubads()).setTargeting("sect", "home").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                                    (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: home_skyscraper*/
                                        PB.gptAds['home_65'] = googletag.defineSlot('/4403/gn.kidzworld.com/home', [[160, 600]], 'home_65').addService(googletag.pubads()).setTargeting("sect", "home").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                                    (function(){
                googletag.cmd.push(function() {
                    /*Initialization for home out of page slot*/ 
                                        PB.gptAds['home_adoop'] = googletag.defineOutOfPageSlot('/4403/gn.kidzworld.com/home', 'home_adoop').addService(googletag.pubads()).setTargeting("sect", "home").setTargeting("kw", "").setTargeting("ct", "").setTargeting("ci", "");
                    googletag.pubads().setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
                });
        })();
                                                                        (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: ros_leaderboard*/
                                        PB.gptAds['ros_67'] = googletag.defineSlot('/4403/gn.kidzworld.com/ros', [[728, 90]], 'ros_67').addService(googletag.pubads()).setTargeting("sect", "ros").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                                    (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: ros_sidebar_atf*/
                                        PB.gptAds['ros_69'] = googletag.defineSlot('/4403/gn.kidzworld.com/ros', [[300, 600],[300, 250]], 'ros_69').addService(googletag.pubads()).setTargeting("sect", "ros").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                                    (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: ros_skyscraper*/
                                        PB.gptAds['ros_71'] = googletag.defineSlot('/4403/gn.kidzworld.com/ros', [[160, 600]], 'ros_71').addService(googletag.pubads()).setTargeting("sect", "ros").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                                    (function(){
                googletag.cmd.push(function() {
                    /*Initialization for ros out of page slot*/ 
                                        PB.gptAds['ros_adoop'] = googletag.defineOutOfPageSlot('/4403/gn.kidzworld.com/ros', 'ros_adoop').addService(googletag.pubads()).setTargeting("sect", "ros").setTargeting("kw", "").setTargeting("ct", "").setTargeting("ci", "");
                    googletag.pubads().setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
                });
        })();
                                                                        (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: home_sidebar_btf*/
                                        PB.gptAds['home_btf_53'] = googletag.defineSlot('/4403/gn.kidzworld.com/home_btf', [[300, 600],[300, 250]], 'home_btf_53').addService(googletag.pubads()).setTargeting("sect", "home_btf").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                                                        (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: ros_sidebar_btf*/
                                        PB.gptAds['ros_btf_55'] = googletag.defineSlot('/4403/gn.kidzworld.com/ros_btf', [[300, 600],[300, 250]], 'ros_btf_55').addService(googletag.pubads()).setTargeting("sect", "ros_btf").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                                                        (function(){
            googletag.cmd.push(function() {
                /*Initialization for slot: chat*/
                                        PB.gptAds['chat_59'] = googletag.defineSlot('/4403/gn.kidzworld.com/chat', [[300, 250]], 'chat_59').addService(googletag.pubads()).setTargeting("sect", "chat").setTargeting("dc_ref", "'+encodeURIComponent(location.href)+'");
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().disableInitialLoad();
                    googletag.pubads().collapseEmptyDivs(true);
                    googletag.enableServices();
            });
        })();
                                         
 
 
 
    // DOM preload function
    (function checkDOMStatus(callable){
        if (document.readyState=='complete')
            callable.call();
        else
            setTimeout(function(){checkDOMStatus(callable)}, 100);
    })(callable);
 
 
    /*
      ====================================================================================
      Trigger: after DOM is loaded
      ====================================================================================
    */
    })(function(){
        // Load Ad slots
        var adsPresent = [];
        for (key in PB.gptAds) {
            if (document.getElementById(key)) {
                // this line is needed for the refresh method to work correctly
                googletag.cmd.push(function() { googletag.display(key); });
                adsPresent.push(PB.gptAds[key]);
            }
        };

        // loading the ads in one single request
        googletag.pubads().refresh(adsPresent); 
        evolveFooter = document.getElementById('evolve_footer');
        if (evolveFooter) {
            evolveFooter.innerHTML = footer;
        }
    });

