
var flickerTimeout = new Array(); /* For flickering in the same block */
var flickerCycleTimeout; /* For flickering through all images */
var randSequence = new Array(0, 2, 4, 6, 3, 1, 5); /* Random block numbers to flicker */
var seqIndex = 0; /* Which stage of the cycle? */

/* Fade out slowly first, then fade in quickly. */
function flickerEffect(element, flag, blocknum) {
    if(flag == 0) {
	new Effect.Appear(element, {duration: 1.0, to: 1.0});
	flickerTimeout[blocknum] = setTimeout("flickerEffect(\"" + element + "\", 1, " + blocknum + ")", 2200);
    } else {
	new Effect.Fade(element, {duration: 2.5, to: 0.1});
    }
}

/* Onload function that gives rise to all effects */
function setUpFlickerShow() {
    /* First dull them all out evenly. */
    temp1 = setTimeout("dullAll()", 1000);
    temp2 = setTimeout("flickerRandomly()", 4000);
}

/* Random flickering initiation */
function flickerRandomly() {
    flickerEffect("block" + randSequence[seqIndex].toString(), 0, randSequence[seqIndex]);
    seqIndex = (seqIndex + 1)%7;
    flickerCycleTimeout = setTimeout("flickerRandomly()", 1500);
}

/* Initial dulling of all colored blocks */
function dullAll() {
    for(i=0; i<7; i++) {
	new Effect.Fade("block" + i.toString(), {duration: 2, to:0.1});
    }
}

function installHoverEffects()
{
    function appearFn(e)
    {
        args = $A(arguments);
        args.shift();
        new Effect.Appear(args[0], {duration: 0.5, to:1.0});
    }

    function fadeFn(e)
    {
        args = $A(arguments);
        args.shift();
        new Effect.Fade(args[0], {duration: 0.5, to:0.1});
    }

    for(i=0; i<7; i++) {
        Event.observe("block" + i.toString(), 'mouseover', appearFn.bindAsEventListener(null,"block" + i.toString()));
        Event.observe("block" + i.toString(), 'mouseout', fadeFn.bindAsEventListener(null,"block" + i.toString()));
    }
}
