
// Config
var appear_speed = 25;
var hold_image = 5000;
var appear_delay = 2000;
var images = new Array('img_01.png', 'img_02.png', 'img_03.png', 'img_04.png', 'img_05.png', 'img_06.png', 'img_07.png', 'img_08.png', 'img_09.png', 'img_10.png', 'img_11.png', 'img_12.png', 'img_13.png', 'img_14.png', 'img_15.png', 'img_16.png', 'img_17.png', 'img_18.png', 'img_19.png', 'img_20.png', 'img_21.png', 'img_22.png');

// Do NOT change
var crt_image_id = 0;
var image_order = new Array();
var images_length = 0;

var animation_done = true;

var left_image_element = null;
var right_image_element = null;

var header_element = null;


function header_init() {

    images_length = images.length;
    header_element = document.getElementById('site').getElementsByTagName('div')[0];

    left_image_element = document.createElement('img');
    left_image_element.alt = 'Left Image';
    left_image_element.className = 'left';

    header_element.appendChild(left_image_element);

    right_image_element = document.createElement('img');
    right_image_element.alt = 'Right Image';
    right_image_element.className = 'right';

    header_element.appendChild(right_image_element);

    shuffle_images();
    start_header();
}


function shuffle_images() {

    image_order = images;
    image_order.shuffle();
}

function start_header() {

    if (animation_done) {

        if (crt_image_id < images_length) {

            var left_image_id = crt_image_id;
            var right_image_id = crt_image_id + 1;

            left_image_element.src = 'graphics/design/header/' + images[left_image_id];
            right_image_element.src = 'graphics/design/header/' + images[right_image_id];

            animation_done = false;
            appear_images();

            crt_image_id += 2;
        }
        else {

            shuffle_images();
            crt_image_id = 0;
        }

    }

    setTimeout('start_header()', 1);
}

function appear_images() {

    var opacity_value = 0;
    if (arguments[0] != undefined) {
        opacity_value = arguments[0];
    }

    set_opacity(opacity_value);

    opacity_value++;

    if (opacity_value <= 100) {
        setTimeout('appear_images(' + opacity_value + ')', appear_speed);
    }
    else {
        setTimeout('disappear_images()', hold_image);
    }
}

function disappear_images() {

    var opacity_value = 100;
    if (arguments[0] != undefined) {
        opacity_value = arguments[0];
    }

    set_opacity(opacity_value);

    opacity_value--;

    if (opacity_value >= 0) {
        setTimeout('disappear_images(' + opacity_value + ')', appear_speed);
    }
    else {
        setTimeout('animation_done = true;', appear_delay);
    }
}








function set_opacity(opacity_value) {

    if (navigator.appName == 'Microsoft Internet Explorer') {

        left_image_element.style.filter = 'Alpha(opacity=' + opacity_value + ')';
        right_image_element.style.filter = 'Alpha(opacity=' + opacity_value + ')'; ;
    }
    else {

        left_image_element.style.opacity = opacity_value / 100;
        right_image_element.style.opacity = opacity_value / 100;
    }
}

function shuffle_array() {
    var tmp, rand;
    for (var i = 0; i < this.length; i++) {
        rand = Math.floor(Math.random() * this.length);
        tmp = this[i];
        this[i] = this[rand];
        this[rand] = tmp;
    }
}

Array.prototype.shuffle = shuffle_array;
