//Used to set customer id, Reading language and preferred voice
var customerID = 13655;
var lang = 'es_co';    
var voice = 'Carlos';

//DO NOT EDIT below this line!

//Adds CSS container
var rsCSS = document.createElement('style');
rsCSS.type = 'text/css';
rsCSS.id = 'rsCSS'    
var css = '.rsbtn {\nposition:absolute!important;\ntop:60px;\nleft:20px;\nwidth:385px!important\n}\n.rsbtn.rs_mobile {\nz-index:10;\ntop:0px;\nleft:165px;\nmargin-top:12px;\nwidth:121px!important;\n}\n@media screen and (min-width: 400px) { .rsbtn.rs_mobile {top:0px;left:185px;} }\n@media screen and (min-width: 500px) { .rsbtn.rs_mobile {top:0px;left:205px;} }\n@media screen and (min-width: 600px) { .rsbtn.rs_mobile {top:0px;left:225px;} }\n@media screen and (min-width: 640px) { .rsbtn.rs_mobile {top:50px;left:155px;} }\n@media screen and (min-width: 1050px) { .rsbtn.rs_mobile {top:0px;left:730px;} }\n@media screen and (min-width: 1100px) { .rsbtn.rs_mobile {top:0px;left:760px;} }\n@media screen and (min-width: 1200px) { .rsbtn.rs_mobile {top:0px;left:800px;} }\n.rspkr_dr_link { margin:-35px 35px 0px 10px!important; }\n.rspkr_dr_link img { height:40px; }';
if (rsCSS.styleSheet) {   // IE
        rsCSS.styleSheet.cssText = css;
    } else {                // the world
        rsCSS.appendChild(document.createTextNode(css));
    }
document.getElementsByTagName('head')[0].appendChild(rsCSS);
                          
//Adds config script
var rsConf = document.createElement('script');
rsConf.id = 'rsConf';    
rsConf.type = 'text/javascript';
rsConf.text = '\nwindow.rsConf = { general: { usePost:true, readidOrder: true, skipHiddenContent:true }, ui: { mobileVertPos: "bottom=115" } };';
document.head.appendChild(rsConf);

//Adds DocReader config script
var docReaderConf = document.createElement('script');
docReaderConf.id = 'docReaderConf';    
docReaderConf.type = 'text/javascript';
docReaderConf.text = '\nwindow.rsDocReaderConf = {lang: \''+ lang +'\', img_href: \'https://media.readspeaker.com/buttons/images/listen_icons/icon_16px_black.gif\'};';

document.head.appendChild(docReaderConf);

//Adds webReader script (CustomerID)
var rsScript = document.createElement('script');
rsScript.type = 'text/javascript';
rsScript.id = 'rs_req_Init';  
rsScript.src = 'https://cdn1.readspeaker.com/script/' + customerID + '/webReader/webReader.js?pids=wr&dload=DocReader.AutoAdd';
document.head.appendChild(rsScript);

document.addEventListener("DOMContentLoaded", function () {

  setTimeout(function () {   
var targetList = document.getElementsByClassName('Header_main__Jm5OG');
for (var i = 0; i < targetList.length; i++) {

//Adds Player code
var player = document.createElement('div');
player.id = 'ReadSpeakerContainer';
player.innerHTML = '<div id="readspeaker_button1" class="rs_skip rsbtn rs_preserve">\n<a rel="nofollow" class="rsbtn_play" accesskey="L" title="Escucha esta p&aacute;gina utilizando ReadSpeaker webReader" href="//app-eu.readspeaker.com/cgi-bin/rsent?customerid=' + customerID +'&lang=' + lang + '&voice=' + voice + '&readclass=Cover_main__3KAsw,readText1,readText2,readText3,readText4,readText5,readText6,readText7,readText8,InteractiveABC_InteractiveABC_bgOver__2Amkp&url=">\n<span class="rsbtn_left rsimg rspart"><span class="rsbtn_text"><span>Escuchar</span></span></span>\n<span class="rsbtn_right rsimg rsplay rspart"></span></a></div>';
targetList[i].prepend(player);

}
ReadSpeaker.init();
}, 50);

window.onpopstate = function() { setTimeout(window.pageSwap, 125); }
window.onload = window.onpopstate;

});

//Compare logic
function compareStyleTop ( a, b ) {
    if ( a.style.top < b.style.top ){
      return -1;
    }
    if ( a.style.top > b.style.top ){
      return 1;
    }
    return 0;
  }

function compareStyleLeft ( a, b ) {
    if ( a.style.left < b.style.left ){
      return -1;
    }
    if ( a.style.left > b.style.left ){
      return 1;
    }
    return 0;
  }  

  function compareMobileOrder ( a, b ) {
    if ( a.style.order < b.style.order ){
      return -1;
    }
    if ( a.style.order > b.style.order ){
      return 1;
    }
    return 0;
  }  

//On page swap or refresh
function pageSwap () {

//Stopping player
ReadSpeaker.q(function() {if (rspkr.ui.getActivePlayer()) {rspkr.ui.getActivePlayer().close();}});

//Init DocReader AutoAdd
ReadSpeaker.DocReader.AutoAdd.init();

//Skip ▬ icons
        var boxList = document.getElementsByClassName('block-font-size-hugeTitle');
        for (var i = 0; i < boxList.length; i++) {
            
        if (boxList[i].firstChild.innerHTML === '▬') {
            boxList[i].firstChild.classList.add('rs_skip');
        }
        }

//Skip inactive interactive cards
var cardList = document.getElementsByClassName('InteractiveCard_flipper__-k2LL');
for (var i = 0; i < cardList.length; i++) {
cardList[i].classList.add('rs_skip');
}  

//Add Onclick to card interaction
var cardButtonList = document.getElementsByClassName('InteractiveCardVert_call__2UGVE');
for (var i = 0; i < cardButtonList.length; i++) {
cardButtonList[i].onclick = function() { cardClick() };
}

//Add Onclick to Information buttons
var infoButtonList = document.getElementsByClassName('InfographicsVerticalPanelsInformation_button__1nd2s');
for (var i = 0; i < infoButtonList.length; i++) {
infoButtonList[i].onclick = function() { infoClick() };
}

//Add Onclick to Quiz activation
var quizStartList = document.getElementsByClassName('CallToAction_bg__27EVA');
for (var i = 0; i < quizStartList.length; i++) {
  if (!quizStartList[i].parentNode.parentNode.parentNode.classList.contains('InteractiveCardVert_content__2pCVO')) {
    quizStartList[i].onclick = function() { quizStartClick() };
} 
}

var quizStartList2 = document.getElementsByClassName('CallToAction_icon__1KrmU');
for (var i = 0; i < quizStartList2.length; i++) {
  if (!quizStartList2[i].parentNode.parentNode.parentNode.parentNode.classList.contains('InteractiveCardVert_content__2pCVO')) {
    quizStartList2[i].onclick = function() { quizStartClick() };
} 
}

//Add Onclick to interactive cover
var interCoverList = document.getElementsByClassName('interactiveCoverFlow_main__2ZpnG');
for (var i = 0; i < interCoverList.length; i++) {
console.log(interCoverList[i]);

var interButtonList = document.getElementsByClassName('CoverFlowTextOverlapping_button__2MHiA');
for (var i = 0; i < interButtonList.length; i++) {
interButtonList[i].onclick = function() { infoCoverClick() }; 
}

}

var styleList = [];
var stack = [];

//Useing: InteractiveWrapper_main__1EOLB to detemine element placement
//Use style.top and style.left to determine page placement and sort into stack.
//Add reading order classes based on stack order.

var slideElementList = document.getElementsByClassName('InteractiveWrapper_main__1EOLB');
for (var i = 0; i < slideElementList.length; i++) {
styleList[i] = slideElementList[i];
}

styleList.sort( compareStyleTop );
styleList.sort( compareStyleLeft );

for (var i = 0; i < styleList.length; i++) {
    var thing = styleList[i]; 
    stack.push(thing);
}
/*
console.log(stack);
console.log('STACK POP!');
*/
for (var i = stack.length; i > 0; i--) {
 
n = stack.pop();
n.classList.add('readText' + i);
//console.log(n);

}

var mobileStyleList = [];
var mobileStack = [];

//Useing class: InteractiveWrapperSmall_main__1tV5j (Mobile) to detemine text placement
var mobileSlideElemList = document.getElementsByClassName('InteractiveWrapperSmall_main__1tV5j');
for (var i = 0; i < mobileSlideElemList.length; i++) {
mobileStyleList[i] = mobileSlideElemList[i];
}

//Sorting in mobile order
mobileStyleList.sort( compareMobileOrder );

for (var i = 0; i < mobileStyleList.length; i++) {
    var thing = mobileStyleList[i]; 
    mobileStack.push(thing);
}
/*
console.log(mobileStack);
console.log('mobile STACK POP!');
*/
for (var i = mobileStack.length; i > 0; i--) {  
n = mobileStack.pop();
n.classList.add('readText' + i);
//console.log(n);
}

} //pageswap end

//When card is clicked
function cardClick () {

var cardList = document.getElementsByClassName('InteractiveCard_flipper__-k2LL');
for (var i = 0; i < cardList.length; i++) {

if (cardList[i].classList.contains('rs_skip')) {
cardList[i].classList.remove('rs_skip');
} else if (!cardList[i].classList.contains('rs_skip')) {
var target = cardList[i]
setTimeout(function () { target.classList.add('rs_skip'); }, 50);
}

}
}

//When an info button is clicked
function infoClick () {

//Closing active player
ReadSpeaker.q(function() {if (rspkr.ui.getActivePlayer()) {rspkr.ui.getActivePlayer().close();}});

var infoGraphList = document.getElementsByClassName('InfographicsVerticalPanelsItems_panel__XpevU');
for (var i = 0; i < infoGraphList.length; i++) {
    infoGraphList[i].classList.add('rs_skip');
}

var infoTitleList = document.getElementsByClassName('RichTextViewer_RichText_ql_container__26wyB');
for (var i = 0; i < infoTitleList.length; i++) {
    infoTitleList[i].classList.add('rs_skip');
}

setTimeout(function () {  
var infoCloseList = document.getElementsByClassName('InteractiveInfographicsCard_closeButton__2wUXV');
for (var i = 0; i < infoCloseList.length; i++) {
infoCloseList[i].onclick = function() { infoCloseClick() };
}
}, 50);

}

//When info card is closed
function infoCloseClick () { 

//Closing active player
ReadSpeaker.q(function() {if (rspkr.ui.getActivePlayer()) {rspkr.ui.getActivePlayer().close();}});

var infoGraphList = document.getElementsByClassName('InfographicsVerticalPanelsItems_panel__XpevU');
for (var i = 0; i < infoGraphList.length; i++) {
    infoGraphList[i].classList.remove('rs_skip');
}

var infoTitleList = document.getElementsByClassName('RichTextViewer_RichText_ql_container__26wyB');
for (var i = 0; i < infoTitleList.length; i++) {
    infoTitleList[i].classList.remove('rs_skip');
}
}

//When quiz is started
function quizStartClick () {
console.log('QUIZ WAS STARTED!');

//Closing active player
ReadSpeaker.q(function() {if (rspkr.ui.getActivePlayer()) {rspkr.ui.getActivePlayer().close();}});

setTimeout(function () { 
var quizCardList = document.getElementsByClassName('InteractiveABCQuestion_main__3v6yx');
for (var i = 0; i < quizCardList.length; i++) {
  console.log('quizCard FOUND!');
  console.log('quizCardList[' + i + '] = ');
  console.log(quizCardList[i]);

}

//Finding quiz index text
var quizIndexText = document.getElementsByClassName('InteractiveABCPagination_InteractiveABCPagination__AL4eU');
for (var i = 0; i < quizIndexText.length; i++) {
console.log('Silencing indextext');
quizIndexText[i].classList.add('rs_skip');  
}

//Finding quiz index text (variant)
var quizIndexText2 = document.getElementsByClassName('InteractiveDragDropPagination_main__xFvAo');
for (var i = 0; i < quizIndexText2.length; i++) {
console.log('Silencing indextext2');
quizIndexText2[i].classList.add('rs_skip');  
}

//Finding pretext on quiz pages and silencing
var quizPreText = document.getElementsByClassName('readText1');
for (var i = 0; i < quizPreText.length; i++) {
quizPreText[i].classList.add('rs_skip'); 
}

//Finding pretext on quiz pages and silencing (variant for empty first elements) 
if (quizPreText.length === 0) {
  var quizPreText2 = document.getElementsByClassName('readText2');
  for (var i = 0; i < quizPreText2.length; i++) {
  quizPreText2[i].classList.add('rs_skip'); 
  }
}

//Adding onclick for next button
var quizAnswerBtnList = document.getElementsByClassName('InteractiveABCAnswer_InteractiveABCAnswer_radioButtonContainer__rN8lI');
for (var i = 0; i < quizAnswerBtnList.length; i++) {
quizAnswerBtnList[i].onclick = function() { quizNextClick() };
}

}, 50);

}

//When quiz nextbutton is clicked (repeat)
function quizNextClick () {
setTimeout(function () {

//Closing active player
ReadSpeaker.q(function() {if (rspkr.ui.getActivePlayer()) {rspkr.ui.getActivePlayer().close();}});

//Finding quiz index text
var quizIndexText = document.getElementsByClassName('InteractiveABCPagination_InteractiveABCPagination__AL4eU');
for (var i = 0; i < quizIndexText.length; i++) {
quizIndexText[i].classList.add('rs_skip');  
}

//Finding quiz index text (variant)
var quizIndexText2 = document.getElementsByClassName('InteractiveDragDropPagination_main__xFvAo');
for (var i = 0; i < quizIndexText2.length; i++) {
quizIndexText2[i].classList.add('rs_skip');  
}

//Adding onclick for next button
var quizAnswerBtnList = document.getElementsByClassName('InteractiveABCAnswer_InteractiveABCAnswer_radioButtonContainer__rN8lI');
for (var i = 0; i < quizAnswerBtnList.length; i++) {
quizAnswerBtnList[i].onclick = function() { quizNextClick() };
}    

//Adding onclick for redo button
var quizRedoBtnList = document.getElementsByClassName('InteractiveABCConclusion_InteractiveABCConclusion_callToAction__MHDzk');
for (var i = 0; i < quizRedoBtnList.length; i++) {
  quizRedoBtnList[i].onclick = function() { quizStartClick() };
  }  

}, 500);

}

//Info cover onclick
function infoCoverClick () {

//Closing active player
ReadSpeaker.q(function() {if (rspkr.ui.getActivePlayer()) {rspkr.ui.getActivePlayer().close();}});

//Find current page count
setTimeout(function () { 
var interPageCountList = document.getElementsByClassName('CoverFlowTextOverlapping_current__1yVXa');
for (var i = 0; i < interPageCountList.length; i++) {
var html = interPageCountList[i].innerHTML;
if (html !== '1') {
  var introTextList = document.getElementsByClassName('readText1');
  for (var i = 0; i < interPageCountList.length; i++) {
    introTextList[i].classList.add('rs_skip');
  } 
  }
if (html == '1') {
  var introTextList = document.getElementsByClassName('readText1');
  for (var i = 0; i < interPageCountList.length; i++) {
    introTextList[i].classList.remove('rs_skip');
  } 
}
}

var interButtonList = document.getElementsByClassName('CoverFlowTextOverlapping_button__2MHiA');
for (var i = 0; i < interButtonList.length; i++) {
interButtonList[i].onclick = function() { infoCoverClick() }; 
}

}, 225 );

} //infoCoverClick END

WRIsEazy = {
meta: {version: 'Beta',date: '2022-06-03'}
}