/*
Copyright $year by Diedrich Vorberg <diedrich@tux4web.de>
Copyright $year by JungePartner, Witten <info@jungepartner.de>

All Rights Reserved

The customer, JungePartner, Witten, is granted the right to use this
and all related sourcecode in running and maintaining above website
now and in the future. For this purpose it may be modified at
will. However, publication and commercial distribution is restricted
as for any other peace of proprietary software.
*/

/* Slideshow */
var slideshow = Class.create({
    initialize: function(container, slide_selector)
    {
        var div = $(container);
        if (div)
        {
            if (!slide_selector)
            {
                slide_selector = "img";
            }
            
            this._timeout = 30;
            this._steps = 40;
            this._show_steps = 80;
            this._images = div.select(slide_selector);
            this._current = 0;
            this._previous = null;

            this._images.each(function(img) {
                img.style.position = "absolute";
            });
            
            var self = this;
            setTimeout(function(){self.next()}, this._timeout*this._show_steps);
        }    
    },

    next: function()
    {
        this._previous = this._current;
        this._current += 1;
        
        if ( this._current > this._images.length-1 )
        {
            this._current = 0;
        }

        this._step = 0;
        
        this.step();
    },

    step: function()
    {
        var self = this;
        
        this._step += 1;
        if (this._step <= this._steps)
        {
            this.set_opacity(this._current, this._step / this._steps);
            this.set_opacity(this._previous, 1-(this._step / this._steps));
            
            setTimeout(function(){self.step()}, this._timeout);
        }
        else
        {
            var self = this;
            setTimeout(function(){self.next()}, this._timeout*this._show_steps);
        }    
    },

    set_opacity: function(idx, value)
    {
        var img = this._images[idx];
	    img.style.opacity = value;
	    img.style.filter = 'alpha(opacity=' + value*100 + ')';
        
        if ( value > 0 )
        {
            img.show();
        }
        else
        {
            img.hide();
        }
    }
});


