var current_index;
var current_obj;
var current_img;
var current_alpha;
var switch_index;
var switch_obj;
var switch_img;

function fader() {
    var tmp;
    var rand_image;
    var foot_obj = document.getElementById("f" + current_index);
    var foot_switch = document.getElementById("f" + switch_index);

    if (current_alpha > 0) {
        current_alpha -= 5;
        current_obj.style.opacity = foot_obj.style.opacity = current_alpha / 100;
        current_obj.style.filter = foot_obj.style.filter = "alpha(opacity=" + current_alpha + ")";
        setTimeout('fader()', 50);

    } else {
        switch_obj.style.zIndex = foot_switch.style.zIndex = "2";
        current_obj.style.zIndex = foot_obj.style.zIndex = "1";
        current_obj.style.opacity = foot_obj.style.opacity = "1";
        current_obj.style.filter = foot_obj.style.filter = "alpha(opacity=100)";
        current_alpha = 100;

        tmp = current_obj;
        current_obj = switch_obj;
        switch_obj = tmp;

        tmp = current_img;
        current_img = switch_img;
        switch_img = tmp

        tmp = current_index;
        current_index = switch_index;
        switch_index = tmp;

        do {
            rand_image = header_imgs[Math.floor(Math.random() * header_imgs.length)];
        } while (rand_image == current_image);

        current_image = rand_image;

        switch_img.src = "header_imgs/" + rand_image;
        foot_obj.style.background = "url(header_imgs/" + rand_image + ")";
        setTimeout('fader()', 10000);
    }
}

function fader_init() {
    switch_index = 1;
    current_index = 2;
    current_alpha = 100;
    current_obj = document.getElementById('h2');
    current_img = document.getElementById('i2');
    switch_obj = document.getElementById('h1');
    switch_img = document.getElementById('i1');
    fader();
}

