function arrayShuffle(){
  var tmp, rand;
  for(var i =0; i < this.length; i++){
    rand = Math.floor(Math.random() * this.length);
    tmp = this[i];
    this[i] = this[rand];
    this[rand] =tmp;
  }
}

Array.prototype.shuffle = arrayShuffle;

Array.prototype.foreach = function( callback ) {
    for( var k=0; k<this .length; k++ ) {
        callback( k, this[ k ] );
    }
}

var ab = 0;

function changeImages(bild) {
    k = 0;
    max = ab + 9;
    for(var i = ab; i < max; i++) {
    	if(k == bild) {
            new Effect.Opacity('img' + (k+1), { from: 1, to: 0});
        }

        k++;
    }

    setTimeout('randomImages(' + bild + ')', 100);
}

function randomImages(bild) {
	if(ab == 0) {
		bilder.shuffle();
	}

	setTimeout('appearImages(' + bild + ')', 700);
}

function appearImages(bild) {
	var anzbilder = bilder.length - 1;

    k = 0;
    max = ab + 9;
    for(var i = ab; i < max; i++) {

    	if(k == bild || bild == "first") {
            document.getElementById('img' + (k+1)).src = bilder[ab];
            new Effect.Opacity('img' + (k+1), { from: 0, to: 1});

            ab++;
        }

        k++;
    }

    if(ab == anzbilder) {
    	ab = 0;
    }

    if(bild == "first") {
    	bild = 0;
    } else {
    	bild = bild + 1;

        if(bild > 8) {
            bild = 0;
        }
    }

    if(bild == 0) {
    	setTimeout('changeImages(' + bild + ')', 2000);
    } else {
    	setTimeout('changeImages(' + bild + ')', 700);
    }
}