<!doctype html>
<html>
<head>
	<title>Picture This 2: Control</title>
	<link rel="stylesheet" type="text/css" href="control.css">
	<script src="ptlib.js"></script>
<script>
var imagelist = new Array();
<?php
	$team1="TEAM ONE";
	$team2="TEAM TWO";
	$clocktime=90;
	$cloudmode=0;
	$directmode=0;
	$imagelist = array_slice(scandir('match'), 2); //all the matches
	$imagecount = count($imagelist);
	for ($i=0;$i<$imagecount;$i++)
	{
		$imagelist[$i]="match/"."$imagelist[$i]";
	}
	$backlist = array_slice(scandir('cardbacks'), 2); //all the folders
	$numbacks = count($backlist);
	for ($i=0;$i<$numbacks;$i++)
	{
		$cardpath="cardbacks/"."$backlist[$i]"."/blue.png";
		$imagelist[$imagecount]=$cardpath;
		$imagecount++;
		$cardpath="cardbacks/"."$backlist[$i]"."/red.png";
		$imagelist[$imagecount]=$cardpath;
		$imagecount++;
	}
	for ($i=0;$i<$imagecount;$i++)
	{
		print "imagelist["."$i"."]=\""."$imagelist[$i]"."\";\r\n";
	}
?>
var numimages = <?=$imagecount?>;
var domain = "http://localhost";
var mypopup = window.open(domain+'/PT2/display.php', 'myWindow');
var cardfolder = "interplay1";
var ptCode = 0;
var theGame = "idle";
var team1pick1 = 99;
var team1pick2 = 99;
var team2pick1 = 99;
var team2pick2 = 99;
var team1r1 = 0;
var team1c1 = 0;
var team2r1 = 0;
var team2c1 = 0;
var team1r2 = 0;
var team1c2 = 0;
var team2r2 = 0;
var team2c2 = 0;
var clocktime = <?=$clocktime?>;
var clockmin="01";
var clocksec="30";
var team1score = 0;
var team2score = 0;
var bigkeys = 0;
var teamname1 = "<?=$team1?>";
var teamname2 = "<?=$team2?>";
var newname = "";
var newnamechars = 0;
var cloudmode=<?=$cloudmode?>;
var bumpX = -2903;
var bumpY = -407;
var bumpmode=0;
var live = 0;
var livestate = 0;
var clockloop=0;
var GameOn=0;
var controls=0;
function place()
{
	var randomindex = Math.floor((Math.random() * (numimages-1)) + 1);
	var newimage=imagelist[randomindex];
	var randomrow = Math.floor((Math.random() * 5) +1);
	var randomcol = Math.floor((Math.random() * 12) +1);
	var message = ["image",randomrow,randomcol,newimage,1,0,0];
	mypopup.postMessage(message,domain);
	newimage="small_"+newimage;
	var id = "r"+randomrow+"c"+randomcol;
	var theslot = document.getElementById(id);
	theslot.src = newimage;
	theslot.style.visibility="visible";
	var removetimer = setTimeout(function(){ remove(); },200 );
}
function remove()
{
	var randomrow = Math.floor((Math.random() * 5) +1);
	var randomcol = Math.floor((Math.random() * 12) +1);
	var message = ["hide",randomrow,randomcol,"image"];
	mypopup.postMessage(message,domain);
	var id = "r"+randomrow+"c"+randomcol;
	var theslot = document.getElementById(id);
	theslot.style.visibility="hidden";
	var placetimer = setTimeout(function(){ place(); },200 );
}
	
function init()
{
	setclock(clocktime);
	//gobumpy(0);
	controls=1;
}
function offBigKeys()
{
	live=0;
	if (cloudmode==1) goBigClouds(0,0,1); else cardbackshalf(cardfolder,1);
}
</script>
</head>
<body>
<div id="container">
<div id="games">
<?php include("panel.php"); ?>
</div>
<div id="keyboard">
<input type="text" class="arduino" id="keyin" value="" onkeypress="return dokey(event)">
<BR><div id="ptindex">0</div><div id="ptgrid">r0 c0</div>
</div>
<div id="smallboard">
	<img id="smallscreen" src="small_graphics/smallscreen.png">
<!-- banners -->
	<img id="banner1" class="row0" class="col1" src="small_banners/startup1.png">
	<img id="banner2" class="row0" class="col5" src="small_banners/startup2.png">
	<img id="banner3" class="row0" class="col9" src="small_banners/startup3.png">
<?php include "preview.php";?>
</div>
</div>
</body>
<script>
var inittimer = setTimeout(function(){ init(); },1000 );
var placetimer = setTimeout(function(){ place(); },3000 );

</script>
</html>