








	
	


	
	


  

 














var ebzDomain = "http://as.ebz.io";


if (window.beeadLocalstorage) {
    window.ebzOnLocalStorageRefreshed.push(function() {
        beead_loadScript("http://as.ebz.io/api/choixPubJS.htm?pid=725988&mode=NONE&sec=0&referer=http%3A%2F%2Fwww.slate.com%2Farticles%2Fnews_and_politics%2Fjurisprudence%2F2015%2F02%2Fcampus_rape_investigations_state_legislatures_debate_laws_to_bring_in_criminal.html&home=http%3A%2F%2Fwww.slate.com&screenLayer=1" + "&localstorage=" + encodeURIComponent(beeadLocalstorage) + "&localstorageEscript=" + beead_value_escript);
    });
    ebz_refreshLocalStorage();
} else {
    window.beead_currentUrl = "http://as.ebz.io/api/choixPubJS.htm?pid=725988&mode=NONE&sec=0&referer=http%3A%2F%2Fwww.slate.com%2Farticles%2Fnews_and_politics%2Fjurisprudence%2F2015%2F02%2Fcampus_rape_investigations_state_legislatures_debate_laws_to_bring_in_criminal.html&home=http%3A%2F%2Fwww.slate.com&screenLayer=1";
    window.beead_baseUrl = "http://as.ebz.io";
    window.beead_value;
    window.beead_value_escript;
    
        
        
    window.beeadLocalstorage = "none";
        
    
    window.beead_name = 'storagebeead';
    window.beead_iframe = null;
    window.beead_value_escript = null;
    window.ebzOnLocalStorageRefreshed = [];
    // To prevent multiple call of beeadStart
    window.ebzIsAlreadyStarted = false;
    // To prevent multiple call of refreshLocalStorage in same time. Must handle a call one by one.
    window.ebzIsRefreshLocalStorageAlreadyCalled = false;

    function beead_init()
    {
        beead_iframe = beead_makeiframe("http://as.ebz.io/scripts/api/safari/safari.html?v=f751d14ea36a8d4e846bd511abde533ed6ca2b96");
        beead_addLocalStorageListener(beead_iframe,beead_baseUrl);

        var postDataObject = {};
        postDataObject.localstoragename = beead_name;
        postDataObject.publisherhost = beead_getPublisherHost();
        postDataObject.value = "none";
        postDataObject.domain = ebzDomain;


        var postDataString = JSON.stringify(postDataObject);

        beead_iframe.addEventListener('load',
        function (e)
        {
            beead_iframe.contentWindow.postMessage(postDataString, ebzDomain);

            window.addEventListener('message',
            function (e)
            {

                //if origin doesnt start with beead.fr return
                if(!(beead_baseUrl.indexOf(e.origin) === 0))
                {
                    return;
                }
                else
                {
                    //reload choixPubJs with cookie parameter
                    var getData = e.data;
                    try {
                        var postDataObject = JSON.parse(getData);

                        //if message is from publisher return
                        if(postDataObject.isbeeadmessage && postDataObject.isbeeadmessage == "true")
                        {
                            beead_value = postDataObject.value;
                            beead_value_escript = postDataObject.value_escript;

                            beeadLocalstorage = postDataObject.value;

                            if (window.ebzOnLocalStorageRefreshed.length > 0 ) {
                                window.ebzOnLocalStorageRefreshed.shift()();
                            } else if (!window.ebzIsAlreadyStarted) {
                                beead_start(postDataObject.value, beead_value_escript);
                            }
                        }
                        else
                        {
                            return;
                        }
                    } catch(e) { }
                }

            }, false);
        }, false);
    }

    function beead_getLocalStorage()
    {
        return beeadLocalstorage;
    }

    function beead_start(value, value_escript)
    {
        //avoid empty capping value exception impossible de décoder elt
        if(value == "") value = "undefined";
        if(value_escript == "") value_escript = "undefined";

        beead_loadScript(beead_currentUrl + "&localstorage=" + encodeURIComponent(value) + "&localstorageEscript=" + value_escript);
        window.ebzIsAlreadyStarted = true;
    }

    function beead_setLocalStorage(value)
    {
        var postDataObject = {};
        postDataObject.localstoragename = beead_name;
        postDataObject.command="setLocalStorage";
        postDataObject.publisherhost = beead_getPublisherHost();
        postDataObject.value = value;

        var postDataString = JSON.stringify(postDataObject);
        for(var i=0; i< beead_localStorageListerners.length; i++)
            beead_localStorageListerners[i].contentWindow.postMessage(postDataString, beead_localStorageListernersDomain[i]);

        beead_value = value;
        beeadLocalstorage = value;

        if (window.ebzOnLocalStorageRefreshed.length > 0 ) {
            window.ebzOnLocalStorageRefreshed.shift()();
        } else {
            window.ebzIsRefreshLocalStorageAlreadyCalled = false;
        }
    }

    function beead_addLocalStorageListener(window,domain){
        if(typeof beead_localStorageListerners==='undefined'){
            beead_localStorageListerners=new Array();
            beead_localStorageListernersDomain=new Array();
        }
        beead_localStorageListerners.push(window);
        beead_localStorageListernersDomain.push(domain);
    }

    function beead_makeiframe(src)
    {
        var iframe = document.createElement('iframe');
        iframe.setAttribute("src", src);
        iframe.setAttribute("width", "1");
        iframe.setAttribute("height", "1");
        iframe.setAttribute("id", "beeadsafariiframe");
        iframe.setAttribute("style", "visibility:hidden");
        document.getElementsByTagName('body')[0].appendChild(iframe);

        return iframe;
    }

    function beead_loadScript(src)
    {
        var script = document.createElement('script');
        script.setAttribute("src", src);
        script.type = "text/javascript";

        document.getElementsByTagName('body')[0].appendChild(script);

        return script;
    }

    beead_init();

    function ebz_refreshLocalStorage()
    {
        if (ebzIsRefreshLocalStorageAlreadyCalled) {
            return;
        }
        ebzIsRefreshLocalStorageAlreadyCalled = true;
        var postDataObject = {};
        postDataObject.localstoragename = beead_name;
        postDataObject.publisherhost = beead_getPublisherHost();
        postDataObject.value = "none";
        var postDataString = JSON.stringify(postDataObject);
        beead_iframe.contentWindow.postMessage(postDataString, ebzDomain);
    }

    function beead_getPublisherHost(){
        try {
            return top.location.host;
        }catch(e){
            return '';
        }
    }
}

