// FallT v1.0  By Maxx Blade - http://www.maxxblade.co.uk
//       v1.1     Mike M - Added 3 diff texts, better space handling (stays in screen), widthfactor (hack) to push stuff to edge of screen.
/////////////  Only Edit these lines  ////////////////
//var no=15,speed=30,slider=30,fallmax=8,wind=0,fallwhat="?;o)",fallsize=20,fallfont="Tahoma";
var no=15,speed=30,slider=30,fallmax=8,wind=0,xplus=690,fallwhat1="Population Genetics",fallwhat2="Phylogenetics",fallwhat3="Genomics",fallsize=15,fallfont="Tahoma",widthfactor=2.5;
var colours=new Array("#000000","#1B1B1B","#383838","#555555","#717171","#8D8D8D","#AAAAAA","#C6C6C6","#E3E3E3","#FFFFFF");
//////////////////////////////////////////////////////
//o[][1] x
//o[][2] y
//o[][3] spin
//o[][4] 
//o[][5]
//o[][6]
//o[][7]
//o       - layer object, instance of one of the fallwhats
//dofallt - array of timers controling each object

var o=new Array(), tog=1, dofallt=new Array();
var ns4=(document.layers)?1:0;
var ie4=(document.all)?1:0;
var ns6=(document.getElementById&&!document.all)?1:0;
if(ie4)	falllayer="document.all['gf'+i].style";
if(ns4) falllayer="document.layers['gf'+i]";
if(ns6) falllayer="document.getElementById('gf'+i).style";
function winWid(){ return ((ns4||ns6)?window.innerWidth:document.body.clientWidth)/widthfactor; }
function winHei(){ return ((ns4||ns6)?window.innerHeight:document.body.clientHeight)-15; }
function winOfy(){ return (ns4||ns6)?window.pageYOffset:document.body.scrollTop; }
function togFall() { 
  for(i=0;i<no;i++){
    if(tog==1){ 
      with(eval(falllayer))
        { left=-500; } 
      clearTimeout(dofallt[i]); 
    } else { 
      fallt(i); 
    } 
  } 
  tog*=-1 
} 
/*function newobj(q,t){
fallwhat=fallwhat1;
	spin = parseInt(Math.random()*slider);
	spin = (Math.random()>0.5) ? spin : -spin;
	o[q] = new Array(parseInt(Math.random()*(winWid()-slider)),-30,spin,0.02+Math.random()/10,parseInt(1+Math.random()*fallmax),0);
	if(t==1){
		if(ns4){ document.write('<layer name="gf'+q+'" left="0" top="0" visibility="show">'+fallwhat+'</layer>'); }
		if(ie4||ns6){ document.write('<span id="gf'+q+'" style="POSITION: absolute; Z-INDEX: -'+q+'; VISIBILITY: visible; TOP: 0px; LEFT: 0px; font-size: '+fallsize+'px; font-family: '+fallfont+';">'+fallwhat+'</span>'); }
	}
}*/
function newobj(q,t){
	spin = parseInt(Math.random()*slider);
	spin = (Math.random()>0.5) ? spin : -spin;
	if (parseInt((Math.random()*9)%3)==0) 
		{
		fallwhat=fallwhat1;
		}
	else 
		{ 
		if (parseInt((Math.random()*9)%3)==1) 
			{
			fallwhat=fallwhat2;
			} 
		else 
			{
			fallwhat=fallwhat3;
			}
	}
	//Pick an x within the usable area, then shift it to the right...
	newx=10000;
	brkCounter=0;
	LJUsableAreaX=winWid() - slider - (fallsize*fallwhat.length);
	while ( newx>LJUsableAreaX ) {
		brkCounter=brkCounter+1;
		if ( parseInt(brkCounter) > 20 ) {
			break;
		}
		newx=parseInt( Math.random()*LJUsableAreaX );
		//cotr=cotr+1;
		//document.write(Math.random() + " " + cotr + "  ");
	}
	
	fixfactor=0;
	if ( (winWid()+xplus) < newx+(fallsize*fallwhat.length)+slider+90) {
		alert("The xplus variable extends the fallwhat text beyond the edge of the screen.");
		fixfactor = LJUsableAreaX + xplus - (winWid()*widthfactor);
	}
	newx = newx + xplus - fixfactor;

	o[q] = new Array(newx,-30,spin,0.02+Math.random()/10,parseInt(1+Math.random()*fallmax),0, fallwhat.length);
	//o[q] = new Array(parseInt(Math.random()*(winWid()-slider)),-30,spin,0.02+Math.random()/10,parseInt(1+Math.random()*fallmax),0);
	if(t==1){
		if(ns4){ document.write('<layer name="gf'+q+'" left="0" top="0" visibility="show">'+fallwhat+'</layer>'); }
		if(ie4||ns6){ document.write('<span onClick="this.visible=false" id="gf'+q+'" style="POSITION: absolute; Z-INDEX: -'+q+'; VISIBILITY: visible; TOP: 0px; LEFT: 0px; font-size: '+fallsize+'px; font-family: '+fallfont+';">'+fallwhat+'</span>'); }
	}
	if ( parseInt(brkCounter) > 10 ) {;
		newx=0;
	}
	//
}
function fallt(i){
if (timeoutID) 
    {
	LJUsableAreaX=winWid() - slider - (fallsize*fallwhat.length)
	if(o[i][1]>winHei()-(fallsize*1.5)){ newobj(i,0); }
	o[i][1] += o[i][4];
	o[i][0]+=wind;
	o[i][5] += o[i][3];
	sizexy=Math.sin(o[i][5]);
	lay=(ie4)?sizexy:parseInt(sizexy+1);
	sizexy=(sizexy>0)?sizexy:0-sizexy;
	with(eval(falllayer)){
		top = o[i][1]+winOfy();
		yeOldeLeft=left;
		left = o[i][0]+o[i][2]*Math.cos(o[i][5]);
		//'alert("left="+left);
		//alert("leftside=" + parseInt(left+(fallsize*fallwhat.length)) + "  rightside=" + parseInt((winWid()*widthfactor) - slider - 520));
		if ( parseInt(left+(fallsize*fallwhat.length)) > parseInt((winWid()*widthfactor) - slider-60) ) {
			left=yeOldeLeft;

			//alert("washere"); 
		}
		if ( (parseInt(left) < 30) || (parseInt(left) > parseInt(winWid()*widthfactor+scroll) ) ) {
			left=parseInt(xplus+90);
		}
		if (parseInt(left) < 0) {
			visible = false;
		}
		if(!ns4){
			zIndex=lay;
			color=colours[parseInt(sizexy*(colours.length-1))]
		}
	}
	if (parseInt(eval(falllayer).left) > 0) {
		dofallt[i] = setTimeout("fallt("+i+")", speed);
	}
    } 
}

for (i = 0; i < no; i++){ newobj(i,1); fallt(i); }
