
      window.addEvent('domready',function() {
        var animationLengthForEach = GALLERY_ANIMATION_LENGTH*1000/2;
        var showDuration = GALLERY_ANIMATION_INTERVAL*1000 + GALLERY_ANIMATION_LENGTH*1000;
        
        var container = $('slide-container');
        var images = container.getElements('div');
        var currentIndex = 0;
        var interval;
        var controls = [];
        var thumbOpacity=0.4;

        images.each(function(img,i){ 
          if(i > 0) {
            img.set('opacity',0);
          }
        });

        var controlContainer = new Element('div',{
          id: 'slide-container-controls'
	}).inject(container);

        images.each(function(img,i){
          controls.push(new Element('img',{
            src: '/img/slide_active.png',
            styles: {
              opacity: (i == 0 ? 0.99 : thumbOpacity)
            },
            events: {
              click: function(e) {
                if(e) e.stop();
                stop();
                show(i);
                start();
              }
            }	
          }).inject(controlContainer));
        });

        var start = function() { interval = show.periodical(showDuration); };
        var stop = function() { $clear(interval); };
        var show = function(to) {
          images[currentIndex].set('tween', {duration: animationLengthForEach}).fade('out');
          controls[currentIndex].set('tween', {duration: animationLengthForEach}).fade(thumbOpacity);
          if(GALLERY_LOOP_IMAGES)
            currentIndex = ($defined(to) ? to : (currentIndex < images.length - 1 ? currentIndex+1 : 0));
          else
            currentIndex = ($defined(to) ? to : (currentIndex < images.length - 1 ? currentIndex+1 : currentIndex));
          images[currentIndex].set('tween', {duration: animationLengthForEach}).fade('in');
          controls[currentIndex].set('tween', {duration: animationLengthForEach}).fade(0.99);
        };
        window.addEvent('load',function(){
          interval = show.periodical(showDuration);
        });
      });


