//Originally released as Autumn leaves- by Kurt Grigg (kurt.grigg@virgin.net)
//This has been modified to include the switching of music and flash by Tim Cree(tim@tcsols.co.uk)

// Use the grphcs array to define your images for the falling confetti
// Change the variable Amount to alter the number.
// Change the variable global speed to alter the speed. Higher is quicker.
// Be aware that the higher the number of falling pieces, the less smooth the animation.

grphcs=new Array(12);
Image0=new Image();
Image0.src=grphcs[0]="flakes/flake4.png";
Image1=new Image();
Image1.src=grphcs[1]="flakes/flake11.png"
Image2=new Image();
Image2.src=grphcs[2]="flakes/flake1.png"
Image3=new Image();
Image3.src=grphcs[3]="flakes/flake8.png"
Image4=new Image();
Image4.src=grphcs[4]="flakes/flake3.png"
Image5=new Image();
Image5.src=grphcs[5]="flakes/flake10.png"
Image6=new Image();
Image6.src=grphcs[6]="flakes/flake12.png"
Image7=new Image();
Image7.src=grphcs[7]="flakes/flake2.png"
Image8=new Image();
Image8.src=grphcs[8]="flakes/flake6.png"
Image9=new Image();
Image9.src=grphcs[9]="flakes/flake9.png"
Image10=new Image();
Image10.src=grphcs[10]="flakes/flake5.png"
Image11=new Image();
Image11.src=grphcs[11]="flakes/flake7.png"

Amount=45; //Smoothness depends on image file size, the smaller the size the more you can use!
globalSpeed=15; // Speed affects the smoothness of the animation

function thisMovie(movieName) 
{ 
	var isIE = navigator.appName.indexOf("Microsoft") != -1; 
	return (isIE) ? window[movieName] : document[movieName]; 
}
//Pre-load your image below!
var sounder=null;
running=false;
Ypos=new Array();
Xpos=new Array();
Speed=new Array();
Step=new Array();
Cstep=new Array();
ns=(document.layers)?1:0;
ns6=(document.getElementById&&!document.all)?1:0;
//ie=(window.document.body)?1:0;
//alert(document.layers);
//alert(document.all);
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
{
 	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'+i+'" src="'+rndPic+'"style="position:absolute;top:0px;left:0px">');
	}
	document.write('</div></div>');
}
function init()
{
	//alertSize();
	var WinWidth = 0, WinHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		WinWidth = window.innerWidth;
		WinHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		WinWidth = document.documentElement.clientWidth;
		WinHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		WinWidth = document.body.clientWidth;
		WinHeight = document.body.clientHeight;
	}
//	alert(WinWidth+"-"+WinHeight);
	for (i=0; i < Amount; i++)
	{
		Ypos[i] = Math.round(Math.random()*WinHeight)-10;
		Xpos[i] = Math.round(Math.random()*WinWidth)-10;
		Speed[i]= Math.random()*globalSpeed+3;
		Cstep[i]=0;
		Step[i]=Math.random()*0.1+0.05;
	}
	for (i=0; i < Amount; i++)
	{
		if (ns)
		{
			document.layers['sn'+i].top="-50px";
		}
		else if (ns6)
		{
			document.getElementById("si"+i).style.display="none";
		}
		else
		{
			eval("document.all.si"+i).style.display="none";
		}
	}
}
function start()
{
	running=true;
	sounder=thisMovie("sound");
	if(sounder!=null&&sounder.playerPlay)
	{
		sounder.playerPlay();
	}
	for (i=0; i < Amount; i++)
	{
		if (ns)
		{
			document.layers['sn'+i].top="0px";
		}
		else if (ns6)
		{
			document.getElementById("si"+i).style.display="";
		}
		else
		{
			eval("document.all.si"+i).style.display="";
		}
	}
	setTimeout('fall()',25);
}
function fall()
{
	var WinWidth = 0, WinHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		WinWidth = window.innerWidth;
		WinHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		WinWidth = document.documentElement.clientWidth;
		WinHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		WinWidth = document.body.clientWidth;
		WinHeight = document.body.clientHeight;
	}
	//alert(WinHeight);
	//alert(WinWidth);

	var hscrll=(ns||ns6)?window.pageYOffset-10:document.body.scrollTop-10;
	var wscrll=(ns||ns6)?window.pageXOffset-10:document.body.scrollLeft-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-10))
		{
			Ypos[i]=-60;
			Xpos[i]=Math.round(Math.random()*WinWidth)-10;
			Speed[i]=Math.random()*5+3;
		}
		if (ns)
		{
			document.layers['sn'+i].left=Xpos[i]+"px";
			document.layers['sn'+i].top=Ypos[i]+hscrll+"px";
		}
		else if (ns6)
		{
			document.getElementById("si"+i).style.left=Math.min((WinWidth-10),Xpos[i])+"px";
			document.getElementById("si"+i).style.top=Ypos[i]+hscrll+"px";
		}
		else
		{
			eval("document.all.si"+i).style.left=Xpos[i]+"px";
			eval("document.all.si"+i).style.top=Ypos[i]+hscrll+"px";
		}
		Cstep[i]+=Step[i];
	}
	if(running==true)
	{
		setTimeout('fall()',25);
	}
}
function stop()
{
	running=false;
	for (i=0; i < Amount; i++)
	{
		if (ns)
		{
			document.layers['sn'+i].top="-50px";
		}
		else if (ns6)
		{
			document.getElementById("si"+i).style.display="none";
		}
		else
		{
			eval("document.all.si"+i).style.display="none";
		}
	}
	//document.getElementById("sound").src="";

	sounder=thisMovie("sound");
	if(sounder!=null&&sounder.playerPlay)
	{
		sounder.playerStop();
	}
}

