//Edge Pix Script version 080704
//copyright © 2007 Hal Barwood & Finite Arts

//..............................................................................

//globals...

imagelist = new Array(63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64);

cyclecount = 0;

pathstring = "../images/";
namestring = "fpix_";

//..............................................................................

//start the whole thing up...
window.onload = startpulse();

function startpulse()
{
	popinterval = setInterval("cyclepix()", 500);
}

//..............................................................................

function cyclepix()
{
	//locals...	
	var newimage = 0;
	var goodimage = true;
	var botimage = imagelist[15];

	//move images downward...
	for (var i = 15; i > 0; i--)
	{
		imagelist[i] = imagelist[(i-1)];
	}

	//pick new top image...
	++cyclecount;
	newimage = 12 + (Math.round((Math.random() * 50)));	
	if (cyclecount % 11 == 0)
	{
		newimage = 63;
	}
	else
	{
		//check for image dupes...
		for ( i = 0; i < 16; i++)
		{
			if (newimage == imagelist[i])
			{
				goodimage = false;
				break;
			}		
		}
	}
	//change top display image if no dupe exists...
	if (goodimage)
	{
		imagelist[0] = newimage;
	}
	else
	{
		//tidy up consecutive dupes...
		if (botimage >= 63)
		{
			if (newimage > 36)
			{
				botimage = newimage - Math.round((Math.random() * 25));
			}
			else
			{
				botimage = newimage + Math.round((Math.random() * 26));
			}
		}
		imagelist[0] = botimage;
	}

	//place tiles onscreen...
	for (var i = 15; i > -1; i--)
	{
		var imagetag = "";
		var cellref = "edge_" + i;
		imagelist[i] < 64 ? imagetag = ".jpg" : imagetag = ".gif";
		document[cellref].src = pathstring + namestring + imagelist[i] + imagetag;
	}

	//slow down after 1st move...
	clearInterval(popinterval);
	popinterval = setInterval("cyclepix()", 1200);
}
