// Gabriel Rebsamen AG
// jQuery - Effekte

$(document).ready(function() {

  initPageImage();  
  setInterval('slideSwitch()', 6000);

});
 
function initPageImage(){
  var img1 = $('#siteimage img');
  var img2 = $(img1).attr('src').replace('_1.jpg','_2.jpg');
  //var img3 = $(img1).attr('src').replace('_1.jpg','_3.jpg');
  //var img4 = $(img1).attr('src').replace('_1.jpg','_4.jpg');
  //$(img1).clone().attr('src', img4).removeAttr('class').insertAfter(img1).clone().attr('src', img3).insertAfter(img1).clone().attr('src', img2).insertAfter(img1);
  $(img1).clone().attr('src', img2).removeAttr('class').insertAfter(img1);
} 

function slideSwitch() {
    var $active = $('#siteimage IMG.active');

    if ( $active.length == 0 ) $active = $('#siteimage IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#siteimage IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
        });
}
