/*
    slideshow.js

    Copyright 2008 Nir Aides.

    This program is free software; you can redistribute it and/or modify it 
    under the terms of the GNU General Public License as published by the 
    Free Software Foundation; either version 2 of the License, or any later 
    version.

    This program is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along 
    with this program; if not, write to the Free Software Foundation, Inc., 
    51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA    
*/



function slideshow(element_id, images,speed)
{
    if( typeof(speed) == 'undefined' ) speed = 13;


    if (!images.last())
    {
        images.pop();
    }

    var pe1;

    element = $(element_id);

    foo1 = function() {
        pe1.stop();

        images.find(function(image, index) {
            if (!element.src.endsWith(image.src))
                return false;

            index = ++index % images.size();
            next = images[index];

            element.alt = next.alt;
            element.src = next.src;

            return true;
        })

        pe1 = new PeriodicalExecuter(foo1, speed);
    }

    element.observe('click', foo1);
    pe1 = new PeriodicalExecuter(foo1, speed);
}



function slideshow_fadein(div_id, images, speed)
{

	if( typeof(speed) == 'undefined' ) speed = 6;
    
    if (!images.last())
    {
        images.pop();
    }

    var pe;

    div = $(div_id);
    div.setStyle({position: 'relative'});

    img1 = div.down();
    img2 = $(document.createElement('img'));
    img2.src = img1.src;
    img2.alt = img1.alt;
    img2.setStyle({position: 'absolute', top: '0', left: '0'});
    
    div.appendChild(img2);
    
    foo = function() {
        pe.stop();

        images.find(function(image, index) {
            if (!img2.src.endsWith(image.src))
                return false;

            index = ++index % images.size();
            next = images[index];

            img1.src = img2.src;
            img1.alt = img2.alt;

            img2.hide({duration: 0.0});
            $(img2).setStyle({ opacity: 0.0 });
            img2.src = next.src;
            img2.alt = next.alt;
            img2.appear({duration: 1.0});

            return true;
        })

        pe = new PeriodicalExecuter(foo, speed);
    }

    div.observe('click', foo);
    pe = new PeriodicalExecuter(foo, speed);
}


function slideshow_fadein2(div_id2, images2, speed2)
{

	if( typeof(speed2) == 'undefined' ) speed2 = 6;
	
    if (!images2.last())
    {
        images2.pop();
    }

    var pe2;

    div2 = $(div_id2);
    div2.setStyle({position: 'relative'});

    img21 = div2.down();
    img22 = $(document.createElement('img'));
    img22.src = img21.src;
    img22.alt = img21.alt;
    img22.setStyle({position: 'absolute', top: '0', left: '0'});
    
    div2.appendChild(img22);
    
    foo2 = function() {
        pe2.stop();

        images2.find(function(image2, index2) {
            if (!img22.src.endsWith(image2.src))
                return false;

            index2 = ++index2 % images2.size();
            next2 = images2[index2];

            img21.src = img22.src;
            img21.alt = img22.alt;

            img22.hide({duration: 0.0});
            $(img22).setStyle({ opacity: 0.0 });
            img22.src = next2.src;
            img22.alt = next2.alt;
            img22.appear({duration: 1.0});

            return true;
        })

        pe2 = new PeriodicalExecuter(foo2, speed2);
    }

    div2.observe('click', foo2);
    pe2 = new PeriodicalExecuter(foo2, speed2);
}


function slideshow_fadein3(div_id3, images3, speed3)
{

	if( typeof(speed3) == 'undefined' ) speed3 = 6;
	
    if (!images3.last())
    {
        images3.pop();
    }

    var pe3;

    div3 = $(div_id3);
    div3.setStyle({position: 'relative'});

    img31 = div3.down();
    img32 = $(document.createElement('img'));
    img32.src = img31.src;
    img32.alt = img31.alt;
    img32.setStyle({position: 'absolute', top: '0', left: '0'});
    
    div3.appendChild(img32);
    
    foo3 = function() {
        pe3.stop();

        images3.find(function(image3, index3) {
            if (!img32.src.endsWith(image3.src))
                return false;

            index3 = ++index3 % images3.size();
            next3 = images3[index3];

            img31.src = img32.src;
            img31.alt = img32.alt;

            img32.hide({duration: 0.0});
            $(img32).setStyle({ opacity: 0.0 });
            img32.src = next3.src;
            img32.alt = next3.alt;
            img32.appear({duration: 1.0});

            return true;
        })

        pe3 = new PeriodicalExecuter(foo3, speed3);
    }

    div3.observe('click', foo3);
    pe3 = new PeriodicalExecuter(foo3, speed3);
}


