function bild_vor(event) {
    Effect.Fade(xaFadeImages[xnImageShow], { duration: 0.3 });
    if ( xaFadePicSubs[xnImageShow] != undefined ) {
      Effect.Fade(xaFadePicSubs[xnImageShow], { duration: 0.3 });
    }
    if ( xnImageShow >= xaFadeImages.length-1 ) {
     xnImageShow = 0;
    } else {
      xnImageShow = xnImageShow+1;    
    }
    Effect.Appear(xaFadeImages[xnImageShow], { duration: 0.3 });
    if ( xaFadePicSubs[xnImageShow] != undefined ) {
      Effect.Appear(xaFadePicSubs[xnImageShow], { duration: 0.3 });
    }
  changeaktCount();
}
function bild_zurueck(event) {
  
    Effect.Fade(xaFadeImages[xnImageShow], { duration: 0.3 });
    if ( xaFadePicSubs[xnImageShow] != undefined ) {
      Effect.Fade(xaFadePicSubs[xnImageShow], { duration: 0.3 });
    }
    if ( xnImageShow > 0 ) {
      xnImageShow = xnImageShow-1;
    } else {
      xnImageShow = xaFadeImages.length-1;
    }
    Effect.Appear(xaFadeImages[xnImageShow], { duration: 0.3 });
    if ( xaFadePicSubs[xnImageShow] != undefined ) {
      Effect.Appear(xaFadePicSubs[xnImageShow], { duration: 0.3 });
    }
  changeaktCount();
}
function changeaktCount() {
  var xnCounter = xnImageShow+1;
  if ( xnCounter < 10 ) {
    $('aktCount').innerHTML = '0'+xnCounter;  
  } else {
    $('aktCount').innerHTML = xnCounter;
  }
    

}
function text_anzeigen(event) {
  $('infotextI').hide();
  $('infotext').show();
}

Event.observe(window, 'load', function() { 
  if ( $$(".pic_sub") != null ) {
    xaFadePicSubs = $$(".pic_sub span");
    Effect.Appear(xaFadePicSubs[0], { duration: 0.1 });
    xnPicSubMaxHeight = 0;
    for ( i=0; i<xaFadePicSubs.length; i++ )  {
      var layout = xaFadePicSubs[i].getLayout();
      if ( layout.get('height') > xnPicSubMaxHeight ) {
        xnPicSubMaxHeight = layout.get('height');
      }
    }
    if ( xnPicSubMaxHeight > 0 ) {
    /*
      if ( $('pic_sub_id') ) {
        $('pic_sub_id').setStyle({
          'top':(585+xnPicSubMaxHeight)+'px'
        });
      }
    */
      if ( $('infotxt') ) {
        $('infotxt').setStyle({
          'top':(600+xnPicSubMaxHeight)+'px'
        });
      }

    }
  }
  if ( $("bild_zurueck") != null ) {
    xnImageShow = 0;
    xaFadeImages = $$('.fade_image');
    xnCountImages = xaFadeImages.length;
    xbAutomaticFade = true;
    $("bild_zurueck").observe("click", function (event) {
        bild_zurueck(null);
        xbAutomaticFade = false;
      }
    );
    
    new PeriodicalExecuter( function(pe) {
      if ( xbAutomaticFade == false ) {
        pe.stop();
      }
      
      if ( xbAutomaticFade == true ) {
        bild_vor(null);
      }
    },7.5 );
  }
  if ( $("bild_vor") != null ) {
    $("bild_vor").observe("click", function (event) {
        bild_vor(null);
        xbAutomaticFade = false;
      }
    );
  }
  $$('.fade_image').each(
    function(item) {
      item.observe("click", function (event) {
        bild_vor(null);
        xbAutomaticFade = false;
      });
    }
  );
  
  
  if ( $("infotextI") != null ) {
    $("infotextI").observe("click", text_anzeigen);
  }
  
});
