<!--
/**
 * @package ImageRotator
 */

function ImageRotator(container, imgwidth, imgheight, rotatingImages, pauseTime)
{
    this.imgs      = rotatingImages;
    this.imgs_c    = this.imgs.length;
    this.position  = 1;
    this.pauseTime = (typeof pauseTime == 'undefined')?
        3000: pauseTime;
    
    for (i = 0; i < this.imgs_c; i++)
    {
        cache.loadImage(this.imgs[i].url, this.imgs[i].width, this.imgs[i].height,
            function(image)
            {
                ImageRotator.images.push(image);
            }
        );
    }
    
    this.image0                        = document.getElementById(container);
    this.image0.style.backgroundRepeat = "no-repeat";
    this.image0.style.backgroundImage  = 'url("' + this.imgs[0].url + '")';
    
    this.image1 = document.getElementById(container + "_img");
    setOpacity(this.image1, 0);
    
    if (this.imgs_c > 0)
        this.fadeAndSwitch();
}

ImageRotator.images = new Array(0);

ImageRotator.prototype.fadeAndSwitch = function()
{
    var fAS = function()
    {
        if (this.position == this.imgs_c - 1)
            this.position = 0;
        else
            this.position++;
        
        if (this.position == 0 && ImageRotator.images.length > 0)
            this.image0.style.backgroundImage = 'url("' + ImageRotator.images[0].src + '")';
        else if (this.position % 2 != 0 && ImageRotator.images.length > this.position)
        {
            this.image1.src = ImageRotator.images[this.position].src;
            this.image1.alt = ImageRotator.images[this.position].title;
        }
        else if (this.position % 2 == 0 && ImageRotator.images.length > this.position)
            this.image0.style.backgroundImage = 'url("' + ImageRotator.images[this.position].src + '")';
            
        window.setTimeout(this.fadeAndSwitch.bind(this), this.pauseTime);
    };
    
    opacityFade(this.image1, -1, fAS.bind(this));
};

-->