<html>
<head>

<?php

// get array of six numbers, 0 - 15 (for #RRGGBB purposes)
$bg1 = array(mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15));
$bg2 = array(mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15));
$bg3 = array(mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15),mt_rand(0,15));

// concatenate each group of six, converting decimal to hex
$bgcolor1 = dechex($bg1[0]).dechex($bg1[1]).dechex($bg1[2]).dechex($bg1[3]).dechex($bg1[4]).dechex($bg1[5]);
$bgcolor2 = dechex($bg2[0]).dechex($bg2[1]).dechex($bg2[2]).dechex($bg2[3]).dechex($bg2[4]).dechex($bg2[5]);
$bgcolor3 = dechex($bg3[0]).dechex($bg3[1]).dechex($bg3[2]).dechex($bg3[3]).dechex($bg3[4]).dechex($bg3[5]);

// add values of first digit of R,G,B values
$bgval1 = $bg1[0]+$bg1[2]+$bg1[4];
$bgval2 = $bg2[0]+$bg2[2]+$bg2[4];
$bgval3 = $bg3[0]+$bg3[2]+$bg3[4];


// decide if average RGB is roughly equivalent to light or dark, assign opposite to text color
if (($bgval1/3) < 15/2) {
	$textcolorbg = "ccc";
	}
else {
	$textcolorbg = "333";
	}
if (($bgval2/3) <= 15/2) {
	$textcolorc1 = "ccc";
	}
else {
	$textcolorc1 = "333";
	}
if (($bgval3/3) < 15/2) {
	$textcolorc2 = "ccc";
	}
else {
	$textcolorc2 = "333";
	}


?>

<title><?php echo "#".$bgcolor1; ?></title>

<style type="text/css">
	body {
		padding: 0;
		margin: 0;
		background-color: #<?php echo $bgcolor1; ?>;
		font-family: 'Tahoma', 'Trebuchet MS', 'Verdana', 'Arial', 'Lucida Grande', sans-serif;
		font-size: 70%;
		color: #<?php echo $textcolorbg; ?>;
		}
	div#bgBlock {
		position: absolute;
		bottom: 0px;
		right: 0px;
		margin: 0px;
		width: 100%;
		height: auto;
		color: #<?php echo $textcolorbg; ?>;
		font-size: 15em;
		font-family: 'Tahoma', 'Trebuchet MS', 'Verdana', 'Arial', 'Lucida Grande', sans-serif;
		text-align: right;
		vertical-align: bottom;
		}
	div#c1 {
		width: 30%;
		min-width: 200px;
		height: 200px;
		background-color: #<?php echo $bgcolor2; ?>;
		color: #<?php echo $textcolorc1; ?>;
		position: absolute;
		top: 1em;
		left: 10%;
		margin: 10px 50px;
		font-size: 5em;
		font-family: 'Tahoma', 'Trebuchet MS', 'Verdana', 'Arial', 'Lucida Grande', sans-serif;
		text-align: center;
		vertical-align: middle;
		}
	div#c2 {
		width: 30%;
		min-width: 200px;
		height: 200px;
		background-color: #<?php echo $bgcolor3; ?>;
		color: #<?php echo $textcolorc2; ?>;
		position: absolute;
		top: 2em;
		right: 10%; 
		margin: 10px 50px;
		font-size: 5em;
		font-family: 'Tahoma', 'Trebuchet MS', 'Verdana', 'Arial', 'Lucida Grande', sans-serif;
		text-align: center;
		vertical-align: middle;
		}
	p {
		float: left;
		font-size: 2em;
		margin: 0 20px;
		}
	a {
		display: block;
		padding: 20px;
		text-decoration: none;
		}
	#c1 a, #c2 a {
		height: 160px;
		}
	a:link, a:visited {
		color: #<?php echo $textcolorbg; ?>;
		}
	#c1 a:link, #c1 a:visited {
		color: #<?php echo $textcolorc1; ?>;
		}
	#c2 a:link, #c2 a:visited {
		color: #<?php echo $textcolorc2; ?>;
		}
	a:hover {
		color: #<?php echo $bgcolor1; ?>;
		background-color: #<?php echo $textcolorbg; ?>;
		}
	#c1 a:hover {
		color: #<?php echo $bgcolor2; ?>;
		background-color: #<?php echo $textcolorc1; ?>;
		}
	#c2 a:hover {
		color: #<?php echo $bgcolor3; ?>;
		background-color: #<?php echo $textcolorc2; ?>;
		}
	a:active, a:focus {
		border: none;
		}
	:focus {
		outline: none;
		}
</style>

</head>
<body>

<p>Refresh this page for a new color.</p>

<div id="c1">
	<a href="randombg.php"><?php echo "#".$bgcolor2; ?></a>
</div>

<div id="c2">
	<a href="randombg.php"><?php echo "#".$bgcolor3; ?></a>
</div>

<div id="bgBlock">
	<a href="randombg.php"><?php echo "#".$bgcolor1; ?></a>
</div>

</body>
</html>