function pbs_toggle_language(language){
    if (language == 'english'){
        document.getElementById('reading-activity-calendar-module').style.display = 'block';
        document.getElementById('reading-activity-calendar-module-esp').style.display = 'none';
    }
    else if (language == 'spanish'){
        document.getElementById('reading-activity-calendar-module-esp').style.display = 'block';
        document.getElementById('reading-activity-calendar-module').style.display = 'none';
    }
}

function pbs_reading_calendar_module(){
    var imageurl = 'http://pbskids.org/read/images/calendar/';
    var images = ['abc-blocks.gif', 'red-wagon.gif', 'goodjob.gif', 'book-blocks.gif', 'book-tree-dog.gif', 'abc-blocks.gif'];
    var ipick = Math.floor(Math.random()*6);
    var title = 'Reading Activity Calendar';
    var month = 'January';
    var day = '27';
    var link = 'http://pbskids.org/read/activities/calendar/';
    var link_esp = 'http://pbskids.org/read/activities/calendar/index.html?sp';
    var link_text = 'Check out our year-round reading activity calendar at the PBS KIDS Island';
    var link_text_esp = 'Visite a PBS KIDS Island para encontrar más actividades de la lectura en nuestro calendario';
    var activity_title = 'Family Recipe';
    var description = 'Many meals we make don&rsquo;t come from recipes. Your child can make a recipe card for a simple meal, for example &ldquo;How to make a peanut butter sandwich.&rdquo; Give your child paper and crayons and ask her to draw each step as you make the sandwich. Help her say the important words slowly, like spread for example. She can try to write it by listening to the sounds of the letters, s-p-r-ea-d. You can help her notice silent letters like the &ldquo;a&rdquo; in spread. &ldquo;The word spread is like the word bread. Both of those words have an ‘a&rsquo; that doesn&rsquo;t make any sound.&rdquo;'; 
    var activity_title_esp = 'Recetas de familia';
    var description_esp = 'Muchas comidas caseras no tienen recetas, por eso pídale a su hijo que anote la receta de su plato favorito, como una quesadilla. Proporciónele una hoja de papel y lápices de colores y pídale que dibuje los pasos que se deben seguir. Ayude a su hijo a pronunciar las palabras mientras las escribe, así podrá deletrearlas en forma fonética. Un ejemplo en donde necesitará de su ayuda en con la palabra q-u-e-s-o. Le tendrá que explicar que la &quot;u&quot; combinada con la &quot;q&quot; no tiene sonido independiente. Le puede dar ejemplos de otras palabras donde ocurre lo mismo, como quedarse o queja.'; 

    // create top element
    var top = document.createElement('span');
    top.id = 'reading-activity-calendar-module';
    var top_h4 = document.createElement('h4');
    top_h4.innerHTML=title;
    var top_h5 = document.createElement('h5');
    top_h5.innerHTML = month + '<br /><span class="date">' + day + '</span>';

    // create side element
    var side = document.createElement('div');
    side.setAttribute('class','side');
    var image = document.createElement('img');
    image.src = imageurl + images[ipick]; 
    image.width = '97'; 
    image.height = '96'; 
    side.appendChild(image);
    side.appendChild(top_h5);

    // create main element
    var main = document.createElement('div');
    main.innerHTML = '<p><strong>' + activity_title + '.</strong> ' + description + '</p><p class="calendar-link"><a href="' + link +'">' + link_text + '</a></p><input type="button" value="En Espa&ntilde;ol" onclick="pbs_toggle_language(\'spanish\')">';
    // assemble
    top.appendChild(top_h4);
    top.appendChild(side);
    top.appendChild(main);

    // create top spanish element
    var top_esp = document.createElement('span');
    top_esp.style.display='none';
    top_esp.id = 'reading-activity-calendar-module-esp';
    var top_h4_esp = document.createElement('h4');
    top_h4_esp.innerHTML=title;
    var top_h5_esp = document.createElement('h5');
    top_h5_esp.innerHTML = month + '<br /><span class="date">' + day + '</span>';

    // create side spanish element
    var side_esp = document.createElement('div');
    var image_esp = document.createElement('img');
    image_esp.src = imageurl + images[ipick]; 
    image_esp.width = '97'; 
    image_esp.height = '96'; 
    side_esp.setAttribute('class','side');
    side_esp.appendChild(image_esp);
    side_esp.appendChild(top_h5_esp);

    // create main element
    var main_esp = document.createElement('div');
    main_esp.innerHTML = '<p><strong>' + activity_title_esp + '.</strong> ' + description_esp + '</p><p class="calendar-link"><a href="' + link_esp + '">' + link_text_esp + '</a></p><input type="button" value="In English" onclick="pbs_toggle_language(\'english\')">';

    // assemble
    top_esp.appendChild(top_h4_esp);
    top_esp.appendChild(side_esp);
    top_esp.appendChild(main_esp);

    var the_div = document.getElementById("pbs-reading-calendar-module");
    the_div.appendChild(top);
    the_div.appendChild(top_esp);

    //var scripts = document.body.getElementsByTagName('script');
    //for (var i=0; i < scripts.length; i++){
    //    scripts[i].parentNode.appendChild(top);
    //    scripts[i].parentNode.appendChild(top_esp);
    //    scripts[i].parentNode.removeChild(scripts[i]);
    //}
}
document.body.onDomReady=pbs_reading_calendar_module();
