/* 
TO DO:
Also, add all the others, and make sure their directions are okay. 
Faster, after the directions are okay.
*/

var showThings = Math.random()*10;

if (showThings < 3){ //show things. :-)
	window.status = ("There goes the Squadron...");
	var temp;
	var speed = 10;
	var total = 8; //total # of cars - SET THIS ONE
	var no = Math.ceil(Math.random()*total); //make this random...
	var start = Math.floor(Math.random()*total); //make this random, too.
	var car0='smallCars/Red5KHsmall.gif';
	var car1='smallCars/Vadermobilesmall.gif';
	var car2='smallCars/AwingSC.gif';
	var car3='smallCars/Red4FLsmall.gif';
	var car4='smallCars/PodRacerSsmall.gif';
	var car5='smallCars/SithMobileLAsmall.gif';
	var car6='smallCars/Hummer.gif';
	var car7='smallCars/blackldrsmall.gif';
	var flag;
	var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
	var ie4up = (document.all) ? 1 : 0;
	 
	var x, y;    // positions for all cars
	var dx, dy;  // amplitude and step variables
	var i, doc_width = 300, doc_height = 600;
	var clockTicks = 0;

	if (ns4up) { //set w&h, subtracting the framesets
		doc_width = self.innerWidth - 142; 
		doc_height = self.innerHeight - 90;
	} else if (ie4up) {
		doc_width = document.body.clientWidth - 142;
		doc_height = document.body.clientHeight - 90;
	}
	x = new Array();
	y = new Array();
	dx = new Array();
	dy = new Array();
	flag = new Array();
	randStart = new Array();

	//set the driving angles, and starting x, for each of the images.
	dx[0] = -2;
	dx[1] = -2;
	dx[2] = -2;
	dx[3] = 2;
	dx[4] = 2;
	dx[5] = 2;
	dx[6] = -2;
	dx[7] = -2;
	dy[0] = 0;
	dy[1] = 1;
	dy[2] = 0;
	dy[3] = 0;
	dy[4] = 0;
	dy[5] = 0;
	dy[6] = 1;
	dy[7] = 0;
	x[0] = doc_width + 50;
	x[1] = doc_width + 50;
	x[2] = doc_width + 50;
	x[3] = 0;
	x[4] = 0;
	x[5] = 0;
	x[6] = doc_width + 50;
	x[7] = doc_width + 50;

	for (i = 0; i < no; ++ i) { //number of cars chosen at random
		temp = (start + i)%total; //car we're looking at... wrap-around.
		y[temp] = Math.random()*doc_height; 		// random y-position
		randStart[temp] = Math.random()*1000;		//random number of ticks before starting. 
	
		flag[temp] = (Math.random()>0.5)?1:0;
		if (ns4up) {                      // set layers
			if (i == 0) {
				document.write("<layer name='smcar"+ temp +"' left='15' ");
				document.write("top='15' visibility='show'><img src='");
				document.write(eval("car" + temp) + "' border='0'></layer>");
			} else {
				document.write("<layer name='smcar"+ temp +"' left='15' ");
				document.write("top='15' visibility='show'><img src='");
				document.write(eval("car" + temp) + "' border='0'></layer>");
			}
		} else
		if (ie4up) {
			if (i == 0) {
				document.write("<div id='smcar"+ temp +"' style='POSITION: ");
				document.write("absolute; Z-INDEX: "+ temp +"; VISIBILITY: ");
				document.write("visible; TOP: 15px; LEFT: 15px;'><img src='");
				document.write(eval("car" + temp) + "' border='0'></div>");
			} else {
				document.write("<div id='smcar"+ temp +"' style='POSITION: ");
				document.write("absolute; Z-INDEX: "+ temp +"; VISIBILITY: ");
				document.write("visible; TOP: 15px; LEFT: 15px;'><img src='");
				document.write(eval("car" + temp) + "' border='0'></div>");
			}
		}
	}
	 
	function driveNS() {  // Netscape main animation function
		clockTicks += 1;
		for (i = 0; i < no; ++ i) { 
			temp = (start + i)%total; //car we're looking at... wrap-around.
			if (x[temp] <= doc_width + 150 && x[temp] >= -150 && clockTicks >= randStart[temp]){
				document.all["smcar"+temp].visibility = "show";				
				y[temp] += dy[temp];
				x[temp] += dx[temp];
				document.layers["smcar"+temp].top = y[temp];
				document.layers["smcar"+temp].left = x[temp];

		 	}
			else {
				document.all["smcar"+temp].visibility = "hide";	
				if (clockTicks >= randStart[temp]){
					randStart[temp] += clockTicks;
					if (dx[temp] < 0)
						x[temp] = doc_width + 50;
					else
						x[temp] = 0;
					y[temp] = Math.random()*doc_height/2;
				}			
			}
		}
		setTimeout("driveNS()", speed);
	}
	
	function driveIE() {  // IE main animation function
		clockTicks += 1;
		for (i = 0; i < no; ++ i) {  // iterate for every smcar
			temp = (start + i)%total; //car we're looking at... wrap-around.
			if (x[temp] <= doc_width + 150 && x[temp] >= -150 && clockTicks >= randStart[temp]){
				document.all["smcar"+temp].style.visibility = "visible";
				y[temp] += dy[temp];
				x[temp] += dx[temp];			
				document.all["smcar"+temp].style.pixelTop = y[temp];
				document.all["smcar"+temp].style.pixelLeft = x[temp];
			}
			else {
				document.all["smcar"+temp].style.visibility = "hidden";
				if (clockTicks >= randStart[temp]){
					randStart[temp] += clockTicks;
					if (dx[temp] < 0)
						x[temp] = doc_width + 50;
					else
						x[temp] = 0;
					y[temp] = Math.random()*doc_height/2;
				}			
			}
		}
		setTimeout("driveIE()", speed);
	}
	 
	if (ns4up)
		driveNS();
	else if (ie4up)
		driveIE();
}
