// JavaScript Document
window.addEvent('domready',function() {
	/* settings */
	var showDuration = 7000;    /*This is the clock (when to do each transition)*/
        var slideDuration = 5000;   /*Need to be less then the showDuration :>*/
	var container = $('slideshow-container');
	var images = container.getElements('img');
	var currentIndex = 0;
	var interval;
	/* opacity and fade */
	images.each(function(img,i){ 
		if(i > 0) {
			img.set('opacity',0);
                        img.setStyle("visibility","visible");
		}
	});
	/* worker */
	var show = function() {
                var previousIndex = currentIndex;
                var nextIndex = (currentIndex < images.length - 1) ? currentIndex+1 : 0;

                //Previous Image (Image we are changing from)
                var previousImage = images[previousIndex];
                var fxout = new Fx.Tween(previousImage, {
                    duration: slideDuration, 
                    property: 'opacity'
                });
                fxout.start(1, 0.00);
                
                

                //Next Image (Image we are changing to)
                var nextImage = images[nextIndex];
                var fxin = new Fx.Tween(nextImage, {
                    duration: slideDuration, 
                    property: 'opacity'
                });
                fxin.start(0.00, 1.00);

                /*Goto The next*/
                currentIndex = nextIndex; 
	};
        
	/* start once the page is finished loading */
	window.addEvent('load',function(){
		interval = show.periodical(showDuration);
	});
});

