//The magicallishific falling fish script.
// Just for the fun of it. And because CJ asked for it.
// Achieving working order success on July 30th, 2008.

// Globals:
var tmDelay = 100;
var fishLeft = 25;
var fishTop = 0;
var fishStep = 0;
var numFish = 14;
var flipper = 2; //variable to flip between ascending or descending images
var showme = 0;
var aryFish = new Array(numFish);

function dropFish() {
	initFish();
	shiftFish();
}

function shiftFish() {
	if ( (flipper % 2) == 0 ) {
		incrementFish();
	} else {
		decrementFish();
	}
	fishTop += 2;
	if (fishTop >= 700) { fishTop = 0; }

	for (var y = 1; y <= numFish; y++) {
		showme = y-1;
		if (y == fishStep) { showThisFish(); } 
		else { hideThisFish(); }
	}
	setTimeout('shiftFish()',tmDelay);
}

function showThisFish() {
	aryFish[showme].style.top = fishTop+'px';
	aryFish[showme].style.visibility = 'visible';
	aryFish[showme].style.display = 'block';
}

function hideThisFish() {
	aryFish[showme].style.visibility = 'hidden';
	aryFish[showme].style.display = 'none';
}

function incrementFish() {
	fishStep += 1;
	if (fishStep > numFish) { 
		if (flipper == 1) { flipper = 2; }
		else { flipper = 1; }
	}
}

function decrementFish() {
	fishStep -= 1;
	if (fishStep < 1) { 
		if (flipper == 1) { flipper = 2; }
		else { flipper = 1; }
	}
}

function initFish() {
	for (n = 1; n <= numFish; n++) {
		var fish = 'fish' + n;
		//alert ("fish is " + fish);
		aryFish[n-1] = getObject(fish);
		aryFish[n-1].style.position = 'absolute';
		aryFish[n-1].style.top = fishTop+'px';
		aryFish[n-1].style.left = fishLeft+'px';
	}
}

function getObject( sObj ) {
	var oElement;

	if ( document.getElementById ) {
		oElement = document.getElementById( sObj );
	} else if ( document.all ) {
		oElement = document.all.item( sObj );
	} else {
		oElement = null;
	}
	return oElement;
}
