// JavaScript Document

var bild = 5;
var lastbild = 0;
var time = 0;
var time2 = 100;
var time3 = 40;

function init() {
	document.getElementById('image').src = "images/bild5.png";
	document.getElementById('logobar').style.backgroundImage = "url(images/bild5bg.png)";	
	document.getElementById('bar').innerHTML = "<p>Stocker &amp; Partner, ein starker Partner für Veranlagungen, Finanzierungen und Versicherungen...</p>";
	setup();	
}
function setup() {
	
	var a = Math.random();
	
	if(a < 0.2) {
		//bild 1
		bild = 1;
	} else {
		if(a < 0.4) {
		//bild 2
		bild = 2;
		} else{
			if(a < 0.6) {
			//bild 3
				bild = 3;
			} else {
				if(a < 0.8) {
				//bild 4
				bild = 4;
				} else {
					bild = 5;
				}
			}
		}
	}
	if(bild == lastbild) {
		bild = bild + 1;
		if(bild > 5) {
			bild = 1;	
		}
	}
	lastbild = bild;
	time = 0;
	time2 = 100;
	time3 = 100;
	setTimeout('updatePic()', 25);
}
function updatePic() {
	time++;
	if(time < 100) {
		
		
		time2--;
		time3--;
		document.getElementById('image').style.opacity = "" + (time2 * 0.01);
		document.getElementById('bar').style.opacity = "" + (time3 * 0.01);
		setTimeout('updatePic()', 25);

	} else {
		if(time == 100) {
			document.getElementById('image').src ="images/bild" + bild + ".png";
			document.getElementById('logobar').style.backgroundImage = "url(images/bild" + bild +"bg.png)";	
			if(bild == 1) {
				document.getElementById('bar').innerHTML = "<p>Damit Ihnen nichts passiert, wenn einmal etwas passiert. <a href='versichern.html'>Versichern</a></p>";
			}
			if(bild == 2) {
				document.getElementById('bar').innerHTML = "<p>Wir helfen Ihnen, Ihren Traum vom eigenen Zuhause zu verwirklichen. <a href='finanzieren.html'>Finanzieren</a></p>";
			}
			if(bild == 3) {
				document.getElementById('bar').innerHTML = "<p>Wir unterstützen Sie beim Management Ihrer Finanzen. <a href='anlegen.html'>Anlegen</a></p>";
			}
			if(bild == 4) {
				document.getElementById('bar').innerHTML = "<p>Schützen Sie sich vor finanziellen Sorgen bei Unfall und Krankheit! <a href='versichern-allgemein.html'>Versichern</a></p>";
			}
			if(bild == 5) {
				document.getElementById('bar').innerHTML = "<p>Stocker &amp; Partner, ein starker Partner für Veranlagungen, Finanzierungen und Versicherungen...</p>";
			}
			setTimeout('updatePic()', 25);
		} 
		if(time > 110) {
			if(time2 < 100) {
				time2++;
				
				time3++;	
				
			}
			
			document.getElementById('image').style.opacity = "" + (time2 * 0.01);
			document.getElementById('bar').style.opacity = "" + (time3 * 0.01);

				if(time < 610) {
					
					setTimeout('updatePic()', 25);
				} else {
					if(time == 610) {
						setTimeout('setup()', 25);	
				
					}
				}
			
		} else {
			if(time > 100) {
				setTimeout('updatePic()', 25);	
			}
		}
	}
}
