<!-- präsentiert von kostenlose-javascripts.de -->

	var Amount;          	 // Anzahl der Konfettis
	var spd;    		 // beeinflusst Fallgeschwindigkeit 
	var duration;		 // Dauer eines Konfettiwurfs (ein negativer Wert bedeutet: unendlich)
	
	var durationCounter;

	var stop = false;
	
	var imgBaseURL = "http://www.swr.de/static/konfetti/img/herzenssache/";

	colors=new Array(2)
	colors[0]="rot.gif";
	colors[1]="pink.gif";
	
	Ypos=new Array();
	Xpos=new Array();
	Speed=new Array();
	Step=new Array();
	Cstep=new Array();

	function initKonfetti(amt, speed, dur) {
		Amount = amt;
		spd = speed;
		duration = dur;
		durationCounter = duration;
		document.write('<div style="position:absolute;top:0px;left:0px;visibility:hidden;" id="konfetti"><div style="position:relative">');
		for (i = 0; i < Amount; i++){
			var P=Math.floor(Math.random()*colors.length);
			rndCol=colors[P];
			document.write('<img src="' + imgBaseURL + rndCol + '" style="position:absolute;top:0px;left:0px;" id="si' + i + '" />');
		}
		document.write('</div></div>');

		WinHeight=window.document.body.clientHeight;
		WinWidth=window.document.body.clientWidth;
		for (i=0; i < Amount; i++){
			Ypos[i] = Math.round(Math.random()*WinHeight);
			Xpos[i] = Math.round(Math.random()*WinWidth);
			Speed[i]= Math.random()*3+spd;
			Cstep[i]=0;
			Step[i]=Math.random()*0.1+0.05;
		}
	}
	
	
	function fall(){
		// a negative value of durationCounter means: loop infinitely
		if (durationCounter > 0) {
			durationCounter--;
		}
		if (durationCounter == 0) {
			setVisibility("hidden");
			stop = true;
			durationCounter = duration;
			return;
		}
		
		var WinHeight=window.document.body.clientHeight;
		var WinWidth=window.document.body.clientWidth;
		var hscrll=document.body.scrollTop;
		var wscrll=document.body.scrollLeft;
		for (i=0; i < Amount; i++){
			sy = Math.floor(Speed[i]*Math.sin(90*Math.PI/180));
			sx = Math.floor(Speed[i]*Math.cos(Cstep[i]));
			Ypos[i]+=sy;
			Xpos[i]+=sx;
			if (Ypos[i] > WinHeight-80){
				Ypos[i]=-60;
				Xpos[i]=Math.round(Math.random()*WinWidth);
				Speed[i]=Math.random()*5+spd;
			}
			Xpos[i] = (Xpos[i] > WinWidth-30)?WinWidth-30:Xpos[i];
			
			var newXValue = Xpos[i]+"px";
			var newYValue = Ypos[i]+hscrll+"px";
			document.getElementById('si'+i).style.left=newXValue;
			document.getElementById('si'+i).style.top=newYValue;

			Cstep[i]+=Step[i];
			
		}
		
		if (!stop) {
			setTimeout('fall()',40);
		}
	}

	function setVisibility(visibility) {
		document.getElementById('konfetti').style.visibility = visibility;
	}

