/***********************************
 * Load the rotating images for Feature Column and Math in the Media
 * Assumption: the onLoad function of the <body> tag
 * of the page is called "bodyOnLoad".
 *  ngb 2006-06-09
 **************************************/

if(typeof(onloads)=="undefined") {
    var onloads = new Array();   
}
if(typeof(bodyOnLoad)=="undefined") {
    function bodyOnLoad() {
        for ( var i = 0 ; i < onloads.length ; i++ )
            onloads[i]();
    };
}

function loadMonthlyImage(id, prefix, alttext) {
    var e = document.getElementById(id);
    if ( e == null) {
        //alert("No element named "+id);
        return;
    }
    var now = new Date();
    var thisMonth = now.getMonth();
    if (thisMonth < 6) ++thisMonth;
    var imageFilename = prefix;
    imageFilename = imageFilename.concat(thisMonth, '.gif');
    //alert("Loading image: \n"+imageFilename);
    //var img = document.createElement("img");
    e.setAttribute("src", imageFilename);
    e.setAttribute("alt", alttext);
    e.setAttribute("border", "0");
    e.setAttribute("width", "75");
    e.setAttribute("height", "75");
    // so that run-in for headlines and deadlines works
    if (document.title.indexOf("Deadline") >= 0) 
        e.setAttribute("align", "left");
    var oldKids = e.childNodes;
    for ( var i = 0; i < oldKids.length; i++) {
        e.removeChild(oldKids[i]);
    }
    //e.appendChild(img);
}
function loadAllMonthlyImages() {
    loadMonthlyImage('mmImage', '/mathmedia/images/homepageimages/mm', 
                     'Math in the Media');
    loadMonthlyImage('fcImage', '/featurecolumn/images/homepageimages/fc', 
                     'Feature Column');
}
onloads.push(loadAllMonthlyImages);
