/** * * $Id$ * * This script waits for the document to be loaded, * then seeks the right table cell for today's date * and changes it's background color. * * Fading is just an additional effect. * **/ set_hilight_timer(); function set_hilight_timer() { window.setTimeout(hilight_today, 50); } function hilight_today() { /* Has document fetching completed enough? */ if (document.getElementById("upcoming")) { var now = new Date(); var today_id = "calendar-" + now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate(); var today = document.getElementById(today_id); var td = today.parentNode; if (td) { td.style.backgroundColor = "#ebc63c"; td.style.backgroundColor = "black"; fade_td(td, 0, 100); } } else { /* No calendar, continue waiting */ window.setTimeout(hilight_today, 300); } } function fade_td(td, step, interval) { var colors = new Array( "#edece5", "#edece7", "#edebe1", "#ede9db", "#ede8d5", "#ede7cf", "#ede5c9", "#ede4c3", "#ede2bc", "#ede1b6", "#ece0b0", "#ecdeaa", "#ecdda4", "#ecdc9e", "#ecda98", "#ecd991", "#ecd78b", "#ecd685", "#ecd57f", "#ecd379", "#ebd273", "#ebd16d"); td.style.backgroundColor = colors[step]; var next_step = step + 1; if (next_step < colors.length) { /* These three lines feature two techniques: * * lambda * * tail-recursive */ window.setTimeout(function() { fade_td(td, next_step, interval); },(next_step == 1) ? interval * 10 : interval); /* Delay the first step */ } }