/*
    2008 (c) alekciy
    public-mail@alekciy.ru
*/

function SlideShow(speed, step, parent_elm)
{    this.start_delay;
    this.speed = speed;
    this.step = step;
    this.container = parent_elm;
    this.image_list = this.container.getElementsByTagName('img');
    this.current_image_num = this.image_list.length - 1;

    for ( var i = 0, l = this.image_list.length; i < l; ++i)
    {
        this.image_list[i].style.opacity = 1;
        this.image_list[i].style.filter= "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
        this.image_list[i].style.filter= "alpha(opacity=100)";
    }
}

SlideShow.prototype.startFade = function(start_delay)
{    this.start_delay = (start_delay != undefined) ? start_delay : 0;    var self = this;

    var fadeOut = function()
    {        var current_image = self.image_list[self.current_image_num];
        var current_opacity = current_image.style.opacity;

        if ( current_opacity > 0 )
        {
            current_image.style.opacity = current_opacity - 0.1;
            current_image.style.filter= 'progid:DXImageTransform.Microsoft.Alpha(opacity='+(current_opacity*100-10)+')';
            current_image.style.filter= 'alpha(opacity='+(current_opacity*100-10)+')';
            setTimeout(fadeOut, self.speed);
        }
        else
        {
            self.current_image_num--;
            if ( self.current_image_num > 0 )
            {
                setTimeout(fadeOut, self.step);
            }
            else
            {
                self.current_image_num = 1;
                setTimeout(fadeIn, self.step);
            }
        }    }

    var fadeIn = function ()
    {
        var current_image = self.image_list[self.current_image_num];
        var current_opacity = current_image.style.opacity;
        current_opacity = parseFloat(current_opacity)
        if ( current_opacity < 1 )
        {
            current_image.style.opacity = 0.1 + current_opacity;
            current_image.style.filter= 'progid:DXImageTransform.Microsoft.Alpha(opacity='+(current_opacity*100+10)+')';
            current_image.style.filter= 'alpha(opacity='+(current_opacity*100+10)+')';
            setTimeout(fadeIn, self.speed);
        }
        else
        {
            self.current_image_num++;
            if ( self.current_image_num < self.image_list.length )
            {
                setTimeout(fadeIn, self.step);
            }
            else
            {
                self.current_image_num = self.image_list.length - 1;
                setTimeout(fadeOut, self.step);
            }
        }
    }

    self.image_list.item(self.image_list.length-1).setAttribute('class', 'load');
    if ( self.image_list.length > 1 )
    {        for ( var i = self.image_list.length - 1, l = 0; i >= l; --i)
        {
            self.image_list[i].style.display = 'inline';
        }
        setTimeout(fadeOut, this.start_delay);    }
}

if ( document.getElementById('fotos') != null )
{    var show_1 = new SlideShow(30, 3000, document.getElementById('fotos'));
    show_1.startFade(10000);}

var head_show = new SlideShow(30, 6000, document.getElementById('photo'));
head_show.startFade(9000);

