var interval = 5000; // Zeit in ms zwischen Bildwechsel
var duration = 1800; // Dauer Fade in ms 

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;

Images = new Array(
		"http://www.chapella.ch/sites/img/banner/image1.jpg",
		"http://www.chapella.ch/sites/img/banner/image2.jpg",
		"http://www.chapella.ch/sites/img/banner/image3.jpg",
		"http://www.chapella.ch/sites/img/banner/image4.jpg",
		"http://www.chapella.ch/sites/img/banner/image5.jpg",
		"http://www.chapella.ch/sites/img/banner/image6.jpg",
		"http://www.chapella.ch/sites/img/banner/image7.jpg",
		"http://www.chapella.ch/sites/img/banner/image10.jpg",
		"http://www.chapella.ch/sites/img/banner/image8.jpg"
	);

Images.shuffle();

jQuery(function() {
	setInterval("changeImage()", interval);
	if (isset("Images")) {
		jQuery(Images).each(function(Key, Image) {
			if (Key == 0)  {
				jQuery("#head_img img:first").replaceWith("<img src='" + Image + "' style='display: block; position: absolute;' />");
			}
			else {
				jQuery("#head_img").append("<img src='" + Image + "' style='display: none; position: absolute;' />");
			}
		});
	}
});

var current = 1;
var pos = 0;

function changeImage() {
	if (isset("Images")) {
		if (current == Images.length)
			current = 0;
			
		jQuery('#head_img').children(":nth(" + current + ")").hide().css("z-index", pos).fadeIn(duration);
			
		pos++;
		current++;
	}
}

function isset(varname){    
	if(typeof( window[ varname ] ) != "undefined") return true;    else return false;
}
