
var slidedelay = 5000;

function loadimage() {
    //var newImg = document.getElementById('sliderimage').getElementsByTagName('img')[0];
    //newImg.setAttribute('src', 'content/media/image/startseite/slideshow/' + variableslide[currentslide]);
    
    document.getElementById('sliderimage').innerHTML = '';
    
    var newImg = document.createElement('img');
    var addImg = document.getElementById('sliderimage').appendChild(newImg);
    addImg.setAttribute('src', 'content/media/image/startseite/slideshow/' + variableslide[currentslide]);
}

function checkload() {
    var theImg = document.getElementById('sliderimage').getElementsByTagName('img')[0];
        
    if(theImg.complete == true) {
        return;
    }
    else {
        window.setTimeout("checkload()", 100);
    }
    return false;
}

function rotateimages() {
    loadimage();
    checkload();
            
    if(currentslide == variableslide.length-1)
        currentslide = 0;
    else
        currentslide++;
        
    window.setTimeout("fadeOut('sliderimage')", slidedelay);
}

function fadeIn(eID) {
    rotateimages();
    setOpacity(eID, 0);
    var timer = 0;
    for (var i=1; i<=100; i++) {
        window.setTimeout("setOpacity('"+eID+"',"+i+")", timer * 9);
        timer++;
    }
}

function fadeOut(eID) {
    var timer = 0;
    for (var i=100; i>=1; i--) {
        window.setTimeout("setOpacity('"+eID+"',"+i+")", timer * 6);
        timer++;
    }
    setTimeout("fadeIn('sliderimage')", 700);
}

function setOpacity(eID, opacityLevel) {
    var eStyle = document.getElementById(eID).style;
    eStyle.opacity = opacityLevel / 100;
    eStyle.filter = 'alpha(opacity='+opacityLevel+')';
}

function startrotate() {
    if(document.getElementById('sliderdiv')) {
        fadeIn('sliderimage');
    }
}

function addImgFaderLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}


addImgFaderLoadEvent(startrotate);








