header_photos       = (header_photos == null) ? new Array() : header_photos;
header_photo_array  = false;
header_photo_timer  = false;
next_header_photo   = false;
header_fade_fx      = false;
//header_fade_back_fx = false;
header_photo_rand_number    = false;

function rotateHeaderPhoto()
{

    if (header_photo_array.length == 0)
    {
        resetHeaderPhotoArray();
    }
    rand_number = Math.random();
    rand_number = rand_number*(header_photo_array.length-1);
    rand_number = Math.round(rand_number);
    next_header_photo   = header_photos[header_photo_array[rand_number]];
    header_photo_array.splice(rand_number, 1);
    if (next_header_photo)
    {
        if (!document.attachEvent) // because Internet Explorer's transparent PNG animation is horrific.
        {
            header_fade_fx.start('opacity', 0);
        }
        setTimeout("changeHeaderPhoto(next_header_photo)", 1000);
    }
}

function changeHeaderPhoto(header_photo_src)
{
    if (header_photo_src)
    {
//        $('header-photo-back').style.visibility = 'hidden';
//        $('header-photo-back').src = $('header-photo').src;
//        $('header-photo-back').style.visibility = 'visible';
//        header_fade_back_fx.set('opacity', 1);
        $('header-photo').style.display = 'none';
        $('header-photo').src  = header_photo_src;
        $('header-photo').style.display = 'block';
        if (!document.attachEvent) // once again, because of IE's infinite failings.
        {
            setTimeout("header_fade_fx.start('opacity', 0, 1)", 200);
        }
//        header_fade_back_fx.start('opacity', 1, 0);
        setTimeout("rotateHeaderPhoto()", 10000);
    }
}

function resetHeaderPhotoArray()
{
    header_photo_array  = new Array();
    for (i=0; i<header_photos.length; i++)
    {
        header_photo_array[header_photo_array.length]   = i;
    }
}

window.addEvent('domready', function() {
    if (header_photo_timer == false)
        header_photo_timer  = 0;
    if (header_photos.length > 0)
    {
        resetHeaderPhotoArray();
        document.getElementById('header-photo').src   = header_photos[header_photo_array[0]];
        header_photo_array.splice(0,1);
        header_fade_fx      = new Fx.Tween('header-photo');
//        header_fade_back_fx = new Fx.Tween('header-photo-back');
        header_photo_array  = new Array();
        setTimeout("rotateHeaderPhoto();", 5000);
    }
});



