var twinkles = new Array; // initialized below

function twinkleOn() {
    // Choose a random element of array twinkles.
    var w = Math.round(Math.random() * twinkles.length);

    // focus it, and set a timer to unfocus it.
    twinkles[w].focus();
    setTimeout('twinkleOff(' + w + ');', 300);
}

function twinkleOff(w) {
    // unfocus it.
    twinkles[w].blur();

    // choose a random amount of time, and twinkle again after that.
    var time = Math.round(Math.random() * 10);
    setTimeout('twinkleOn();', 1000 * time);
}

function startup() {
    var anchors = document.getElementsByTagName('a');

    // Put every anchor with class "twinkle" in array twinkles;
    for (var i = 0; i < anchors.length; i++) {
        var a = anchors.item(i);
        if (a.className.match(/\btwinkle\b/)) {
            twinkles.push(a);
        }
    }

    // Start twinkling after a delay.
    setTimeout('twinkleOn();', 15000);

    // focusListener is an EventListener to add "focus" to the class
    // of an element while it has the focus.
    /*
    var focusListener = new Object();
    focusListener.handleEvent = function (evt) {
        var o = evt.target;
        if (evt.type == 'focus') {
            o.className = 'focus ' + o.className;
        } else {
            o.className = o.className.substring(6);
        }
    };

    // add focusListener to all the elements of class notifyfocus.
    var anchors = document.getElementsByTagName('a');
    for (var i = 0; i < anchors.length; i++) {
        var a = anchors.item(i);
        if (a.className == 'notifyfocus') {
            a.addEventListener('focus', focusListener, false);
            a.addEventListener('blur', focusListener, false);
        }
    }
    */
}
