function get_image(url) {
    result = new Image;
    result.src = url;
    return result;
}


var fading_anchors = document.getElementsByTagName('a');

var hexa = new Array( '0', '1', '2', '3', '4', '5', '6', '7',
                      '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' );

function color(r, g, b) {
    return Array(r, g, b);
}

function interpolate_colors(from, to, step, steps)
{
    var weight_to   = step/steps;
    var weight_from = 1 - weight_to;
    return Array(
        from[0]*weight_from + to[0]*weight_to,
        from[1]*weight_from + to[1]*weight_to,
        from[2]*weight_from + to[2]*weight_to );
}


function interpolate_arrows(urls, step, steps)
{
    return urls[Math.floor(urls.length*(step/(steps+1)))];
}

function hex(i) {
    if (i < 0)
        return "00";
    else if (i > 255)
        return "ff";
    else
       return "" + hexa[Math.floor(i/16)] + hexa[Math.floor(i%16)];
}

function color_to_hex(x)
{
    return '#' + hex(x[0]) + hex(x[1]) + hex(x[2]);
}

function fade(anchor) {
    color = interpolate_colors(anchor.colorFrom, anchor.colorTo, anchor.step, anchor.steps);
    anchor.style.setAttribute('color', color_to_hex(color));
    if(anchor.arrow)
        anchor.arrow.src = interpolate_arrows(anchor.arrow_images, anchor.step, anchor.steps ).src;
}

function fadeIn(n) {
    anchor = fading_anchors[n]; fade(anchor);
    if(anchor.step < anchor.steps)
    {
        anchor.step = anchor.step + 1;
        anchor.timer = setTimeout('fadeIn('+n+');', anchor.delayIn);
    }
};

function fadeOut(n) {
    anchor = fading_anchors[n];  fade(anchor);
    if(anchor.step > 0)
    {
        anchor.step = anchor.step - 1;
        anchor.timer = setTimeout('fadeOut('+n+');', anchor.delayIn);
    }
};

arrow_images = Array(
    get_image('images/arrow-blauw.gif'),
    get_image('images/arrow-fade1.gif'),
    get_image('images/arrow-fade2.gif'),
    get_image('images/arrow-fade3.gif'),
    get_image('images/arrow-groen.gif') );

for(var n = 0; n < fading_anchors.length; ++n)
{
    var anchor = fading_anchors[n];
    if(anchor.className == 'nofade')
        continue;

    anchor.colorFrom = (anchor.className == 'menu') ? color(0, 0, 0) : color(0, 0, 102);
    anchor.colorTo   = color(67, 178, 0);
    anchor.arrow_images = arrow_images;

    anchor.steps     = 32;
    anchor.delayIn   = 10;
    anchor.delayOut  =  5;
    
    anchor.aid       = n;
    anchor.step      = 0;
    anchor.timer     = false;
    anchor.arrow     = false;

    anchor.onmouseover = function() {
        if(this.timer)
            clearTimeout(this.timer);
        fadeIn(this.aid);
    }
    
    anchor.onmouseout = function() {
        if(this.timer)
            clearTimeout(this.timer);
        fadeOut(this.aid);
    }
}

var images = document.getElementsByTagName('img');
for(var n = 0; n < images.length; ++n)
{
    var image = images[n];
    if(image.className=='arrow' && image.parentNode.tagName=='A')
            image.parentNode.arrow = image;
}