var ch = 0;
var aktuell = "#bild0";
var neu;
var bildcounter = 0;

function fadeIn(tofade) {	
	$(tofade).animate({ 
			opacity: ".85"
	}, 800 );
};

function fadeFullIn(tofade) {	
	$(tofade).animate({ 
			opacity: "1"
	}, 800 );
};

function fadeOut(tofade) {	
	$(tofade).animate({ 
			opacity: "0"
	}, 800 );
};

function MyGetElementsByClassName(className) {
    var muster = new RegExp("(^| )" + className + "($| )");
    var alles = document.getElementsByTagName("*");
    var gefunden = new Array();
    var i;

    for (i=0; i < alles.length; i++) {
        if (alles[i] && alles[i].className && alles[i].className != "") {
            if (alles[i].className.match(muster))
                gefunden[gefunden.length] = alles[i];
        }
    }
   return gefunden;
};

function makeneu() {
	aktuell = "#bild"+bildcounter;
	bildcounter++;
	if(bildcounter >= ch.length) {
		bildcounter = 0;
	}
	neu = "#bild"+bildcounter;
}

function wechsel() {
	makeneu()

	fadeOut(aktuell);
	$(neu).css("display", "block");
	$(neu).css("opacity", "0");
	fadeFullIn(neu);

	hide = window.setTimeout(function(){
		$(aktuell).css("display", "none");
	}, 1000);

	next = window.setTimeout(function() {
		wechsel();
	}, 5500);
}

$(document).ready(function() {
	ch = MyGetElementsByClassName("slidebilder");
	if(ch.length != '') {
		$(aktuell).css("display", "block");
		fadeIn(".headerwrap7");
	
		$(".headerwrap7").bind("mouseover", function(e){
			fadeOut(".headerwrap7");
		});
		$(".headerwrap7").bind("mouseout", function(e){
			fadeIn(".headerwrap7");
		});
		
		next = window.setTimeout(function() {
			wechsel();
		}, 6000);
	}
});

