Amount=10; //Anzahl der Konfettis

//Pre-load your image below!
Image0=new Image();
Image0.src="con1.gif";
Image1=new Image();
Image1.src="con2.gif";
Image2=new Image();
Image2.src="con3.gif";
Image3=new Image();
Image3.src="con4.gif";
Image4=new Image();
Image4.src="con5.gif";

grphcs=new Array(5)
grphcs[0]="templates/konfetti/con1.gif"
grphcs[1]="templates/konfetti/con2.gif"
grphcs[2]="templates/konfetti/con3.gif"
grphcs[3]="templates/konfetti/con4.gif"
grphcs[4]="templates/konfetti/con5.gif"

Ypos=new Array();
Xpos=new Array();
Speed=new Array();
Step=new Array();
Cstep=new Array();
ns=(document.layers)?1:0;
isFireFox=(navigator.userAgent.toLowerCase().search(/firefox/) != -1)?1:0;
if (ns){
    for (i = 0; i < Amount; i++){
	var P=Math.floor(Math.random()*grphcs.length);
	rndPic=grphcs[P];
	document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0><img src="+rndPic+"></LAYER>");
    }
}
else if (isFireFox) {
    document.write('<div style="position:absolute;top:0px;left:0px">\n');
    document.write('<div style="position:relative">\n');
    for (i = 0; i < Amount; i++){
	var P=Math.floor(Math.random()*grphcs.length);
	rndPic=grphcs[P];
	document.write('<img id="si'+i+'" src="'+rndPic+'" style="position:absolute;top:0px;left:0px">\n');
    }
    document.write('</div></div>');
} 
else
{
    document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i = 0; i < Amount; i++){
	var P=Math.floor(Math.random()*grphcs.length);
	rndPic=grphcs[P];
	document.write('<img id="si" src="'+rndPic+'" style="position:absolute;top:0px;left:0px">');
    }
    document.write('</div></div>');
}
WinHeight=(document.layers)?window.innerHeight:window.document.body.clientHeight;
WinWidth=(document.layers)?window.innerWidth: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+2;
    Cstep[i]=0;
    Step[i]=Math.random()*0.1+0.05;
}

var ttJsEffectSwitchState = -1;
function fall(){
    if (ttJsEffectSwitchState == 0)
	return;
    var WinHeight=(document.layers)?window.innerHeight:window.document.body.clientHeight;
    var WinWidth=(document.layers)?window.innerWidth:window.document.body.clientWidth;
    var hscrll=(document.layers)?window.pageYOffset:document.body.scrollTop;
    var wscrll=(document.layers)?window.pageXOffset:document.body.scrollLeft;
    WinHeight = WinHeight - 10;
    WinWidth = WinWidth - 10;
    for (i=0; i < Amount; i++){
	sy = Speed[i]*Math.sin(90*Math.PI/180);
	sx = Speed[i]*Math.cos(Cstep[i]);
	Ypos[i]+=sy;
	Xpos[i]+=sx;
	if (Ypos[i] > WinHeight){
	    Ypos[i]=-60;
	    Xpos[i]=Math.round(Math.random()*WinWidth);
	    Speed[i]=Math.random()*5+2;
	}
	if (ns){
	    document.layers['sn'+i].left=Xpos[i];
	    document.layers['sn'+i].top=Ypos[i]+hscrll;
	}
	else if (isFireFox) {
	    if (document.getElementById('si'+i)) {
		document.getElementById('si'+i).style.left=Xpos[i]+'px';
		document.getElementById('si'+i).style.top=Ypos[i]+hscrll+'px';
	    }
	}
	else{
	    si[i].style.pixelLeft=Xpos[i];
	    si[i].style.pixelTop=Ypos[i]+hscrll;
	}
	Cstep[i]+=Step[i];
    }

    if (document.getElementById('ttJsEffectSwitch')) {
	if (ttJsEffectSwitchState == -1) {
	    document.getElementById('ttJsEffectSwitch').innerHTML = '<a href="javascript:fall_off()">Konfetti aus</a>';
	    ttJsEffectSwitchState = 1;
	}
    }
    if (ttJsEffectSwitchState != 0)
	setTimeout('fall()',30);
}

function fall_off() {
    ttJsEffectSwitchState = 0;
    document.getElementById('ttJsEffectSwitch').innerHTML = '<a href="javascript:fall_on()">Konfetti an</a>';
    document.cookie = 'ttEffectsStateSave=off; path=/';
    for (i=0; i < Amount; i++){
	if (ns){
	    document.layers['sn'+i].left=i;
	    document.layers['sn'+i].top=i;
	}
	else if (isFireFox) {
	    if (document.getElementById('si'+i)) {
		document.getElementById('si'+i).style.left=0+'px';
		document.getElementById('si'+i).style.top=0+'px';
	    }
	}
	else{
	    si[i].style.pixelLeft=i;
	    si[i].style.pixelTop=i;
	}
    }
}

function fall_on() {
    document.cookie = 'ttEffectsStateSave=on; path=/';
    document.getElementById('ttJsEffectSwitch').innerHTML = '<a href="javascript:fall_off()">Konfetti aus</a>';
    ttJsEffectSwitchState = 1;
    setTimeout('fall()', 30);
}

ttCookieVal='on';
ttCookieNameEQ='ttEffectsStateSave=';
ttCookies=document.cookie;
ttCookieIdx=ttCookies.indexOf(ttCookieNameEQ);
if (ttCookieIdx != -1) {
    ttCookiesTmp = ttCookies.substring(ttCookieIdx);
    ttCookiesIdx2 = ttCookiesTmp.indexOf(';');
    if (ttCookiesIdx2 == -1)
	ttCookiesIdx2 = ttCookiesTmp.length;
    ttCookieVal = ttCookiesTmp.substring(ttCookiesTmp.indexOf('=')+1, ttCookiesIdx2);
}

if (ttCookieVal == 'on')
    setTimeout('fall_on()',500);
else
    setTimeout('fall_off()',500);
//-->