var header_img = Array();
var duration = 10; 	//Intervall in Sekunden
var current = 0;
var count =0;

function switchImg(){
	var new_img = GetRandom(0, count-1);
	
	while (new_img == current){
		new_img = GetRandom(0, count-1);
	}
	$(header_img[new_img]).fadeIn(1600);
	$(header_img[current]).fadeOut(1600);
	current = new_img;
	
	setTimeout("switchImg()",duration*1000);
}

function GetRandom( min, max ) {
        if( min > max ) {
                return( -1 );
        }
        if( min == max ) {
                return( min );
        }
        return( min + parseInt( Math.random() * ( max-min+1 ) ) );
} 

function hideAll(){
	header_img.each(function(){
		$(this).css("display","none");
	});
}



   $(document).ready(function() {

	
	header_img = $("#header img");


	hideAll();
	count = header_img.length;

	//erstes Bild anzeigen	
	current = GetRandom(0,count-1);
	$(header_img[current]).css("display","block");
	if (header_img.length>1){
		setTimeout("switchImg()",duration*1000);
	}
   });




// (function($) {
// 
// 	
// 	header_img = $("#header img");
// 
// 	
// 	hideAll();
// 	count = header_img.length;
// 
// 	//erstes Bild anzeigen	
// 	current = GetRandom(0,count-1);
// 	$(header_img[current]).css("display","block");
// 	if (header_img.length>1){
// 		setTimeout("switchImg()",duration*1000);
// 	}
// })(jQuery);

