

function startTopPics() {

	tpP = new Array();
	tpP[0] = document.getElementById("top1");
	tpP[1] = document.getElementById("top2");
	tpP[2] = document.getElementById("top3");
	tpP[3] = document.getElementById("top4");
	
	tpPics = new Array();
	var tpXmlHttp;
	
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		tpXmlHttp = new XMLHttpRequest();
		}
	else {// code for IE6, IE5
		tpXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	
	tpXmlHttp.onreadystatechange=function() {
		if (tpXmlHttp.readyState == 4 && tpXmlHttp.status == 200) {
			tpX = tpXmlHttp.responseText;
			tpPics = tpX.split("^");
			tp = setTimeout("timedPics()", 1000);
			}
		}	
	
	tpXmlHttp.open("GET", "gettoppics.php", false);
	tpXmlHttp.send();
	}
	
function timedPics() {
	do {
		randImg = Math.floor(Math.random() * 4);
		randPic = Math.floor(Math.random() * tpPics.length);
		}
	while (isInP(tpPics[randPic])); // Continue 'til we find unused one
	tpP[randImg].src = tpPics[randPic];
	tp = setTimeout("timedPics()", 5000);
	}

function isInP(tpPhoto) {
	var tpBool = false;
	for (tpI = 0; tpI < 4; tpI++) {
		if (tpFindFn(tpP[tpI].src) == tpPhoto) {
			tpBool = true;
			}
		}
	return tpBool;
	}

function tpFindFn(filePath) {
	return filePath.substr(filePath.lastIndexOf('/') + 1);
	}
