nameArray = new Array("contact", "about", "works");
contNumArray = new Array();
count = 0;
maxImgNum = 5;
imgNum = Math.floor(Math.random()*maxImgNum)+1;
timerID = 10;

backImg = new Image();
backImg.src = '../shared/images/top_backImg' + imgNum + '.jpg';

function checkBackImg () {
	if (document.images[0].complete) {
		appearBackImg();
		clearInterval(timerID);
	}
}

colorKind = 2;
if (navigator.appVersion.charAt(0) >= "3") {
	var colorImg = new Array();
	for (i=0; i<nameArray.length; i++) {
		for (j=0; j<colorKind; j++) {
			colorImg[i+j*nameArray.length] = new Image();
			colorImg[i+j*nameArray.length].src = '../shared/images/top_color_' + nameArray[i] + (j+1) + '.gif';
		}
	}
	colorImg[colorKind*nameArray.length] = new Image();
	colorImg[colorKind*nameArray.length].src = '../shared/images/spacer.gif';
}

for (i=0; i<nameArray.length; i++) {
	contNumArray[i] = Math.floor(Math.random()*6)*6+(Math.floor(Math.random()*2)+i*2);
}

function writeContents () {
	var exist = 0;

	for (i=0; i<nameArray.length; i++) {
		if (count == contNumArray[i]) {
			document.write('<a href="./' + nameArray[i] + '.html"><img id="map' + count + '" name="map' + count + '" src="../shared/images/top_contS_' + nameArray[i] + '.gif" width="132" height="66" border="0" alt="' + nameArray[i] + '"></a>');
			exist = 1;
		}
	}
	if (!exist) {
			var rndCNum1 = Math.floor(Math.random()*nameArray.length);
			var rndCNum2 = Math.floor(Math.random()*colorKind)+1;
			document.write('<img id="map' + count + '" name="map' + count + '" src="../shared/images/top_color_' + nameArray[rndCNum1] + rndCNum2 + '.gif" width="132" height="66" border="0" alt="">');
	}

	count++;
}

function appearBackImg () {
	ahocount=0;
	for (i=0; i<36; i++) {
		var exist = 0;
		for (j=0; j<nameArray.length; j++) {
			exist = (i == contNumArray[j]) ? 1 : 0;
			if (exist) {
				break;
			}
		}
		if (!exist) {
			document.images['map'+i].src = colorImg[colorKind*nameArray.length].src;
		ahocount++;
		}
	}
}

document.writeln('<style type="text/css">');
document.writeln('<!--');
document.writeln('.screen {');
document.writeln('background-image: url(../shared/images/top_backImg' + imgNum + '.jpg);');
document.writeln('}');
document.writeln('-->');
document.writeln('</style>');
