//toggles the bumpy cloud on or off
function togglebumpy(controls)
{
	if (bumpmode==1) 	// it's on turn it off
	{
		goBigClouds(1,1,1);
		
	}
	else				//it's off, turn it on
	{
		gobumpy(controls);
	}
	
}
//puts up big bumpy cloud and sets it in motion
function gobumpy(controls)
{

	var message=["image",5,1,"graphics/dailydashfind.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,2,"graphics/dailydashwin.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,3,"graphics/dailydashkeep.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,4,"graphics/white.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,5,"graphics/powerpair.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,6,"graphics/white.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,7,"graphics/white.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,8,"graphics/white.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,9,"graphics/white.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,10,"graphics/white.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,11,"graphics/white.png",1,0];
	mypopup.postMessage(message,domain);
	var message=["image",5,12,"graphics/white.png",1,0];
	mypopup.postMessage(message,domain);
	bumpy(1);	
}

function bumpy(mode)
{
	clockstop();
//	bannerTextOff();
	clearalltext();
	hideallborders();
	live=0;
	livestate=0;
	var message=["hide","bigbumpy",0,"div"];
	if (mode==1)
	{
		var message=["show","bigbumpy",0,"div"];
		bumpmode=1;
		bumpX = -2903;
        bumpY = -407;
	}
	else
	{
		var message=["hide","bigbumpy",0,"div"];
		bumpmode=0;
		bumpX = -2903;
        bumpY = -407;
	}
	mypopup.postMessage(message,domain);
	if (bumpmode==1) var bumpytimer = setTimeout(function(){ bump(1,1); },100 );
}
//the bumping cloud motion
function bump(xmult,ymult)
{
	xinc = 10*xmult;
	yinc = 10*ymult;
	bumpX=bumpX+xinc;
	bumpY=bumpY+yinc;
	if (bumpX > -5) xmult=-1
	if (bumpX < (-2950)) xmult=1;
	//if (bumpY > -15) ymult=-1;
	if (bumpY > -250) ymult=-1;
	if (bumpY < (-620)) ymult=1;
	message = ["bump",bumpX,bumpY];
	mypopup.postMessage(message,domain);
	if (bumpmode==1) var bumptimer = setTimeout(function(){ bump(xmult,ymult); },50 );
}
//turns cloud mode on and off
function gocloudmode(state)
{
	modeinput = document.getElementById('cloudmode');
	cloudmode=state;
	modeinput.value=state;
}

//slides three new banners in from the left
function slide3(bannerfile,count)
{
	slide(bannerfile,0);
    count++;
	if (count<3) var slidetimer=setTimeout(function(){ slide3(bannerfile, count); },2500 );
}
function slide3different(bannerfile1,bannerfile2,bannerfile3,count)
{
	if (count==0) slide(bannerfile1,0);
	if (count==1) slide(bannerfile2,0);
	if (count==2) slide(bannerfile3,0);
    count++;
	if (count<3) var slidetimer=setTimeout(function(){ slide3different(bannerfile1,bannerfile2,bannerfile3,count); },2500 );
}
//slides one new banners in from the left
function slide(bannerfile,done)
{
	//turn off text before sliding any banners
	clockstop();
	livestate = live;
	live = 0;
	bannerTextOff();
	clearalltext();
	hideallborders();
	//var banner0=document.getElementById('banner0');
	//banner0.src="banner/"+bannerfile;
	if (done==1)
	{
		//move all banners back one
		var message=["bannerstep"];
		mypopup.postMessage(message,domain);
		//must also change small banners, without the scrolling effect
		var banner1=document.getElementById('banner1');
		var banner2=document.getElementById('banner2');
		var banner3=document.getElementById('banner3');
		var file0="small_banners/"+bannerfile;
		var file1=banner1.src;
		var file2=banner2.src;
		banner1.src=file0;
		banner2.src=file1;
		banner3.src=file2;
		live = livestate;
	}
	else
	{
		slidestep(bannerfile,1);
	}
}
//helper function to slide banners
function slidestep(bannerfile,count)
{
	if (count==1)
	{
		var thebanner = "banners/"+bannerfile;
		var message=["banner",0,thebanner];
		mypopup.postMessage(message,domain);
	}
	var message=["bannerslide"];
	mypopup.postMessage(message,domain);
	count++;
	if (count<33) var steptimer=setTimeout(function(){ slidestep(bannerfile, count); },50 ); else var steptimer = setTimeout(function(){ slide(bannerfile,1); },50 );
}
//flash all borders green and red
function flashBordersOn(winner, max, count, center)
{
	if (winner==0) 
	{
		var bigborder1 = "border_green.png";
		var bigborder2 = "border_green.png";
		var border1 = "small_graphics/border_green.png";
		var border2 = "small_graphics/border_green.png";
	}
	if (winner==1) 
	{
		var bigborder1 = "border_green.png";
		var bigborder2 = "border_red.png";
		var border1 = "small_graphics/border_green.png";
		var border2 = "small_graphics/border_red.png";
	}
	if (winner==2)
	{
		var bigborder1 = "border_red.png";
		var bigborder2 = "border_green.png";
		var border1 = "small_graphics/border_red.png";
		var border2 = "small_graphics/border_green.png";
	}
	if (center) var maxcol=7; else var maxcol=6;
	for (col=1;col<maxcol;col++)
	{
		for (row=1;row<6;row++)
		{
			var message=["border",row,col,bigborder1,1];
			mypopup.postMessage(message,domain);
			var id = "br"+row+"c"+col;
			var border = document.getElementById(id);
			border.src=border1;
			border.style.visibility="visible";
		}
	}
	if (center) var mincol=7; else var mincol=8;
	for (col=mincol;col<13;col++)
	{
		for (row=1;row<6;row++)
		{
			var message=["border",row,col,bigborder2,1];
			mypopup.postMessage(message,domain);
			var id = "br"+row+"c"+col;
			var border = document.getElementById(id);
			border.src=border2;
			border.style.visibility="visible";
		}
	}
	count++;
    if (count<max) 
	{
		var flashtimer = setTimeout(function(){ flashBordersOff(winner,max,count,center); },500 );
	}
}
//turns off all borders and passes control back to flashBordersOn
function flashBordersOff(winner,max,count, center)
{
	hideallborders();
	var flashtimer = setTimeout(function(){ flashBordersOn(winner,max,count, center); },500 );
}
//turns off all the text in the banner area
function bannerTextOff()
{
		var stats = document.getElementById('stats')
		stats.style.visibility="hidden";
		var name1 = document.getElementById('team1name');
		var name2 = document.getElementById('team2name');
		name1.style.visibility="hidden";
		name2.style.visibility="hidden";
		var message = ["hide","stats",0,"div"];
		mypopup.postMessage(message,domain);
		var message = ["hide","team1name",0,"div"];
		mypopup.postMessage(message,domain);
		var message = ["hide","team2name",0,"div"];
		mypopup.postMessage(message,domain);
		var message = ["hide","score1",0,"div"];
		mypopup.postMessage(message,domain);
		var message = ["hide","score2",0,"div"];
		mypopup.postMessage(message,domain);
		var message = ["hide","clock",0,"div"];
		mypopup.postMessage(message,domain);	
}
function showControls()
{
		var message=["image",5,1,"graphics/dailydashfind.png",1,0]; //no spin on these
		mypopup.postMessage(message,domain);
		var message=["image",5,2,"ggraphics/dailydashwin.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,3,"ggraphics/dailydashkeep.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,4,"graphics/white.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,5,"graphics/powerpair.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,6,"graphics/white.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,7,"graphics/blue.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,8,"graphics/blue.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,9,"graphics/blue.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,10,"graphics/blue.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,11,"graphics/blue.png",1,0];
		mypopup.postMessage(message,domain);
		var message=["image",5,12,"graphics/blue.png",1,0];
		mypopup.postMessage(message,domain);	
}
//Show Screen Big Clouds
function goBigClouds(mode,start, controls)
{
	livestate = live;
	live=0;
	bumpy(0);
	//put up the controls
	if (mode==1)
	{
		//first turn off all the text in the banners...
		bannerTextOff();
		//and in the grid....
		clearalltext();
		//then all the borders...
		hideallborders();
	}
	//now bring on the clouds
	showallimages();
	goBigCloudHalf(1);
	goBigCloudHalf(2);
	if (controls)
	{
		var controltimer = setTimeout(function(){ showControls(); },2500 );
	}
	if (start==1) 
	{
		slide3different('startup3.png','startup2.png','startup1.png',0);
	}
	else
	{
		// bannerTextOn();
	}
	live=livestate;
}
//does each half of the big cloud
function goBigCloudHalf(side)
{
	clockstop();
	var count=1;
	if (side==1)
	{
		var low = 1;
		var high = 7;
		var path = "cloud/blue/";
	}
	if (side==2)
	{
		var low=7;
		var high=13;
		var path = "cloud/red/";
	}
	for (row=1;row<6;row++)
	{
		for (col=low;col<high;col++)
		{
			var id="r"+row+"c"+col;
			var image=document.getElementById(id);
			source = path+count+".png";
			message=["image",row,col,source,1,1];
			mypopup.postMessage(message,domain);
			source = "small_"+source;
			var id="r"+row+"c"+col;
			var image=document.getElementById(id);
			image.src=source;
			count++;
		}
	}	
}
//goes to no game - back to beginning
function goStart()
{
	theform = document.getElementById('panelform');
	theform.action = "start.php";
	theform.submit();
}
//goes to the appropriate dash game
function goDash(key,direct)
{
	theform = document.getElementById('panelform');
	thekey = document.getElementById('key');
	thedirect = document.getElementById('directmode');
	theform.action = "dash.php";
	thekey.value=key;
	thedirect.value=direct;
	theform.submit();
}

//goes to the appropriate match game
function goMatch(key,direct)
{
	theform = document.getElementById('panelform');
	thekey = document.getElementById('key');
	thedirect = document.getElementById('directmode');
	theform.action = "match.php";
	thekey.value=key;
	thedirect.value=direct;
	theform.submit();
}
//goes to the appropriate match game
function goSoup(key, direct)
{
	theform = document.getElementById('panelform');
	thekey = document.getElementById('key');
	thedirect = document.getElementById('directmode');
	theform.action = "boggle.php";
	thekey.value=key;
	thedirect.value=direct;
	theform.submit();
}
//sets the team names to TEAM ONE and TEAM TWO
//IS THIS ONLY FOR MATCH?
function resetTeamNames()
{
	var teamname = document.getElementById('team1name');
	teamname.innerHTML="TEAM ONE";
	teamname = document.getElementById('team2name');
	teamname.innerHTML="TEAM TWO";		
	var message1 = ["names","match",1,"TEAM ONE",0];
	var message2 = ["names","match",2,"TEAM TWO",0];
	teamname = document.getElementById('team1');
	teamname.value="TEAM ONE";
	teamname = document.getElementById('team2');
	teamname.value="TEAM TWO";
	mypopup.postMessage(message1,domain);
	mypopup.postMessage(message2,domain);
}
//displays a big keyboard on the bigboard
function getBigKeys()
{
	var rows = new Array();
	rows[0]=['return_left','space','space','space','space','space','space','space','space','space','backspace','return_right'];
	rows[1]=['q','w','e','r','t','y','u','i','o','p','(',')'];
	rows[2]=['exclamation','a','s','d','f','g','h','j','k','l','plus','minus'];
	rows[3]=['at','octothorpe','z','x','c','v','b','n','m','colon','semi','quote'];
	rows[4]=['percent','dollar','ampersand','_s','_p','_a','_c','_e','comma','period','slash','question'];
	for (r=0;r<5;r++)
	{
		for (c=0;c<12;c++)
		{
			var row = r+1;
			var col = c+1; 
			var thechar = rows[r][c];
			var thefile = "chars/"+thechar+".png";
			var message=["image",row,col,thefile]; 
			mypopup.postMessage(message,domain);
			var imageid="r"+row+"c"+col;
			var image = document.getElementById(imageid);
			thefile = "small_"+thefile;
			image.src=thefile;
			image.style.visibility="visible";
		}
	}
	bigkeys=1;
	live=1;
}


//keeps the cursor in the input box
function setFocus()
{
    document.getElementById("keyin").focus();
} 
//sets all grid text to blank
function clearalltext()
{
	for (i=1;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var notext = "";
			var message=["text",j,i,notext]; 
			mypopup.postMessage(message,domain);
			var textid="tr"+j+"c"+i;
			var thetext = document.getElementById(textid);
			data = "";
			thetext.innerHTML=data;
		}

	}		
}
//sets all borders to the selected image
//technically, this is just an overlay layer,
//and doesnt' really have to be a border.
function changeallborders(image)
{
	for (i=1;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var message=["border",j,i,image, 1]; 
			mypopup.postMessage(message,domain);
			//also send it to the small board...
			var borderid="br"+j+"c"+i;
			var border = document.getElementById(borderid);
			data = "small_graphics/"+image;
			border.src=data;
			border.style.visibility="visible";
		}
	}
}
//turns off all borders for team1
function hideteam1borders()
{
	for (i=1;i<6;i++)
	{
		for (j=1;j<6;j++)
		{
			var message=["hide",j,i,"border"]; 
			mypopup.postMessage(message,domain);
			var imageid="br"+j+"c"+i;
			var image = document.getElementById(imageid);
			image.style.visibility="hidden";
		}
	}	
}
//turns off all borders for team2
function hideteam2borders()
{
	for (i=8;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var message=["hide",j,i,"border"]; 
			mypopup.postMessage(message,domain);
			var imageid="br"+j+"c"+i;
			var image = document.getElementById(imageid);
			image.style.visibility="hidden";
		}
	}
}
//turns off all borders
function hideallborders()
{
	for (i=1;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var message=["hide",j,i,"border"]; 
			mypopup.postMessage(message,domain);
			var imageid="br"+j+"c"+i;
			var image = document.getElementById(imageid);
			image.style.visibility="hidden";
		}
	}
}
//turns on all borders
function showallborders()
{
	for (i=1;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var message=["show",j,i,"border"]; 
			mypopup.postMessage(message,domain);
			var imageid="br"+j+"c"+i;
			var image = document.getElementById(imageid);
			image.style.visibility="visible";
		}
	}
}
//hides everything on the image layer
function hideallimages()
{
	for (i=1;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var message=["hide",j,i,"image"]; 
			mypopup.postMessage(message,domain);
			var imageid="r"+j+"c"+i;
			var image = document.getElementById(imageid);
			image.style.visibility="hidden";
		}
	}
}
//shows everything on the image layer
function showallimages()
{
	for (i=1;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var message=["show",j,i,"image"]; 
			mypopup.postMessage(message,domain);
			var imageid="r"+j+"c"+i;
			var image = document.getElementById(imageid);
			image.style.visibility="visible";
		}
	}
}
//sets all the banners to the same selected image
function setallbanners(banner)
{
	for (i=1;i<4;i++)
	{
		var bannerfile = "banners/"+banner;
		var message=["banner",i,bannerfile, 1]; 
		mypopup.postMessage(message,domain);
		//also send it to the small board...
		var bannerid="banner"+i;
		var bannerimage = document.getElementById(bannerid);
		var bannerfile = "small_banners/"+banner;
		bannerimage.src=bannerfile;
		bannerimage.style.visibility="visible";
	}
}
//puts a specific banner in the specified slot
function setbanner(bannername,slot)
{
	var bannerfile = "banners/"+bannername+".png";
	var message=["banner",slot,bannerfile, 1]; 
	mypopup.postMessage(message,domain);
	var bannerid="banner"+slot;
	var bannerimage = document.getElementById(bannerid);
	var bannerfile = "small_"+bannerfile;
	bannerimage.src=bannerfile;
	bannerimage.style.visibility="visible";
}
//puts up all the cardbacks in one color (blue)
function cardbacksfull(folder,vis)
{
	livestate = live;
	live=0;
	cardfolder = folder;
	for (i=1;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var imagefile = "cardbacks/"+folder+"/blue.png";
			var message=["image",j,i,imagefile, vis,1]; 
			mypopup.postMessage(message,domain);
			//also send it to the small board...
			var imageid="r"+j+"c"+i;
			var image = document.getElementById(imageid);
			data = "small_cardbacks/"+folder+"/blue.png";
			image.src=data;
			if (vis==1) image.style.visibility="visible";
		}
	}
	bigkeys=0;
	live=livestate;
}
//puts up all the cardbacks in two colors
function cardbackshalf(folder,vis)
{
	livestate = live;
	live=0;
	cardfolder = folder;
	for (i=1;i<7;i++)
	{
		for (j=1;j<6;j++)
		{
			var imagefile = "cardbacks/"+folder+"/red.png";
			var message=["image",j,i,imagefile, vis,1]; 
			mypopup.postMessage(message,domain);
			//also send it to the small board...
			var imageid="r"+j+"c"+i;
			var image = document.getElementById(imageid);
			data = "small_cardbacks/"+folder+"/red.png";
			image.src=data;
			if (vis==1) image.style.visibility="visible";
		}
	}
	for (i=7;i<13;i++)
	{
		for (j=1;j<6;j++)
		{
			var imagefile = "cardbacks/"+folder+"/blue.png"
			var message=["image",j,i,imagefile, vis,1]; 
			mypopup.postMessage(message,domain);
			//also send it to the small board...
			var imageid="r"+j+"c"+i;
			var image = document.getElementById(imageid);
			data = "small_cardbacks/"+folder+"/blue.png";
			image.src=data;
			if (vis==1) image.style.visibility="visible";
		}
	}
	bigkeys=0;
	live=livestate;
}
//shuffles an array
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex ;

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {

    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
  return array;
}
//unlock the keyboard
function unlock()
{
	live=1;
}
//sets the clock start time
function setclock(secs)
{
	//turn off all the other ones...
	var times=['30','45','60','90','120'];
	for (i=0;i<5;i++)
	{
	  var clockid = times[i]+'sec';
	  var aclock = document.getElementById(clockid);
	  var image = "graphics/"+times[i]+"_sec.png";
	  aclock.src = image;
	}
	//now highlight the selected one
	clockid = secs+'sec';
	aclock = document.getElementById(clockid);
	var imagefile = "graphics/"+secs+"_green.png";
	aclock.src=imagefile;
	//set the form value to pass to the next page
	var theclock = document.getElementById('clocktime');
	theclock.value=secs;
	//set the internal javascript variable
	clocktime=secs;
	//let's see it...
	clockinit();
}
//starts the clock
function clockstart()
{
	var gif = document.getElementById('clockgif');
	gif.src="small_graphics/00.gif";
	var message=["clockgif",1];
	mypopup.postMessage(message,domain);
	clockloop = setInterval("clocktick(1);", 1000);
	live=1;
	var message=["sound","start.wav"];
	mypopup.postMessage(message,domain);
	doGameClockStart();
//    audiotick = new Audio("sounds/ticktock.wav");
//	audiotick.loop = true;
//	audiotick.play();
}
//pauses the clock
function clockpause()
{
	var gif = document.getElementById('clockgif');
	gif.src="small_graphics/00.png";
	var message=["clockgif",0];
	mypopup.postMessage(message,domain);
	clearInterval(clockloop);
	clockloop=0;
	live=0;
//	audiotick.pause();
}
//stops the clock
function clockstop()
{
	if (clockloop)
	{
		var gif = document.getElementById('clockgif');
		gif.src="small_graphics/00.png";
		var message=["clockgif",0];
		mypopup.postMessage(message,domain);
		clearInterval(clockloop);
		clockloop=0;
		clocktime=0;
		clocktick(0);
		live=0;
	}
//	audiotick.pause();
}
//adds five seconds to clock
function plusfivesec()
{
	clocktime=clocktime+5;
	clocktick(0);
}
//subtracts five seconds from clock
function minusfivesec()
{
	clocktime=clocktime-5;
	clocktick(0);
}
//sets the initial time on the clock
function clockinit()
{
	if (clocktime==120) 
	{
		clockmin = "02"; 
		clocksec = "00";
	}			
	if (clocktime==90) 
	{
		clockmin = "01"; 
		clocksec = "30";
	}
	if (clocktime==60) 
	{
		clockmin = "01"; 
		clocksec = "00";
	}
	if (clocktime==45) 
	{
		clockmin = "00"; 
		clocksec = "45";
	}
	if (clocktime==30) 
	{
		clockmin = "00"; 
		clocksec = "30";
	}
	var clocktext = clockmin+":"+clocksec;
	clock = document.getElementById('clock');
	clock.innerHTML=clocktext;
	var message=["time",clocktext,0]; 
	mypopup.postMessage(message,domain);	
}
//moves all clocks one second forward
function clocktick(amt)
{
	if (clocktime>0)
	{
		clocktime=clocktime-amt;
		if (clocktime>59) 
		{
			clockmin = "01"; 
			tempsec = clocktime-60; 
		}			
		if (clocktime>119) 
		{
			clockmin = "02"; 
			tempsec = clocktime-120; 
		}
		if (clocktime>179) 
		{
			clockmin = "03"; 
			tempsec = clocktime-180; 
		}
		if (clocktime>239) 
		{
			clockmin = "04"; 
			tempsec = clocktime-240; 
		}
		if (clocktime>299) 
		{
			clockmin = "05"; 
			tempsec = clocktime-300; 
		}
		if (clocktime<60)
		{
			clockmin="00";
			tempsec = clocktime;
		}
		if (tempsec>9) clocksec = tempsec.toString(); else clocksec = "0"+tempsec.toString();
	}
	else
	{
		//make sure the display is stopped...
		//ah, but clock is still ticking...try killing it
		clearInterval(clockloop);
		clockmin="00";
		clocksec="00";
		var gif = document.getElementById('clockgif');
		gif.src="small_graphics/00.png";
		var message=["clockgif",0];
		mypopup.postMessage(message,domain);
		live=0;
		if (theGame == "boggle")
		{
			//the big board
			var message = ["image",1,6,"graphics/black.png",0,0]
			mypopup.postMessage(message,domain);
			var message = ["image",1,7,"graphics/black.png",0,0]
			mypopup.postMessage(message,domain);
			var message = ["image",2,6,"graphics/black.png",0,0]
			mypopup.postMessage(message,domain);
			var message = ["image",2,7,"graphics/black.png",0,0]
			mypopup.postMessage(message,domain);
			var message = ["image",3,6,"graphics/black.png",0,0]
			mypopup.postMessage(message,domain);
			var message = ["image",3,7,"graphics/black.png",0,0]
			mypopup.postMessage(message,domain);
			var message = ["names","boggle",1,teamname1,1];
			mypopup.postMessage(message,domain);
			var message = ["names","boggle",2,teamname2,1];
			mypopup.postMessage(message,domain);
			//the small board
			var teambox1 = document.getElementById('r1c6');
			var teambox2 = document.getElementById('r1c7');
			var enter1 = document.getElementById('r2c6');
			var enter2 = document.getElementById('r2c7');
			var clear1 = document.getElementById('r3c6');
			var clear2 = document.getElementById('r3c7');
			var team1 = document.getElementById('team1name');
			var team2 = document.getElementById('team2name');
			teambox1.src = "small_graphics/black.png";
			teambox2.src = "small_graphics/black.png";
			enter1.src = "small_graphics/black.png";
			enter2.src = "small_graphics/black.png";
			clear1.src = "small_graphics/black.png";
			clear2.src = "small_graphics/black.png";
			team1.innerHTML = teamname1;
			team2.innerHTML = teamname2;
			var centerused=0;
		}
		if (theGame == "dailydash")
		{
			var thetag = document.getElementById('tag');
			thetag.innerHTML=clockdone[tagno];
			message=["tag",clockdone[tagno],0];
			mypopup.postMessage(message,domain);
			var centerused=0;
			for (i=1;i<6;i++)
			{
				var message = ["hide",i,6,"border"];
				mypopup.postMessage(message,domain);
				var message = ["hide",i,7,"border"];
				mypopup.postMessage(message,domain);
				var message = ["text",i,6,""];
				mypopup.postMessage(message,domain);
				var message = ["text",i,7,""];
				mypopup.postMessage(message,domain);
				var message = ["image",i,6,"graphics/black.png",1,0];
				mypopup.postMessage(message,domain);
				var message = ["image",i,7,"graphics/black.png",1,0];
				mypopup.postMessage(message,domain);
			}
		}
		if (theGame == "halfmatch")
		{
			count=0;
			for (col=1;col<7;col++)
			{
				for (row=1;row<6;row++)
				{
					if (matchcheck[count]!="")
					{
						var data = "match/"+matchcheck[count];
						var message = ["image",row,col,data,1,1];
						mypopup.postMessage(message,domain);
						data = "small_"+data;
						id="r"+row+"c"+col;
						var image = document.getElementById(id);
						image.src=data;
						//experinemtnal
						image.style.marginLeft="";
					}
					count++;
				}
			}
			for (col=7;col<13;col++)
			{
				for (row=1;row<6;row++)
				{
					if (matchcheck[count]!="")
					{
						var data = "match/"+matchcheck[count];
						var message = ["image",row,col,data,1,1];
						mypopup.postMessage(message,domain);
						data = "small_"+data;
						id="r"+row+"c"+col;
						var image = document.getElementById(id);
						image.src=data;
					}
					count++;
				}
			}
			var centerused=1;
		}
		//kill the loop!
		clearInterval(clockloop);
		//play the horn and applause
		var message=["sound","applause.wav"];
		mypopup.postMessage(message,domain);
		//see who won and flash the borders
		var winner = 0;
		if (team1score>team2score) winner=1; 
		if (team2score>team1score) winner=2;
		if ((centerused)) flashBordersOn(winner, 6, 1, 1, 1); else flashBordersOn(winner, 6, 1, 0, 1);
	}
	var clocktext = clockmin+":"+clocksec;
	clock = document.getElementById('clock');
	clock.innerHTML=clocktext;
	var message=["time",clocktext,1]; 
	mypopup.postMessage(message,domain);
	
}
function goBigKey(ptCode)
{
	var bigChar =	["team1","Q","!","@","%","","W","A","#","$","","E","S","Z","&","","R","D","X"," ",
					"","T","F","C"," ","","Y","G","V"," ","","U","H","B"," ","","I","J","N"," ",
					"","O","K","M",",","","P","L",":",".","backspace","(","+",";","/","team2",")","-","'","?"];
					
	var bigCode =	["team1","q","exclamation","at","percent","","w","a","octothorpe","dollar","","e","s","z","ampersand","","r","d","x","space",
					"","t","f","c","space","","y","g","v","space","","u","h","b","space","","i","j","n","space",
					"","o","k","m","comma","","p","l","colon","period","backspace","(","plus","semi","slash","team2",")","minus","quote","question"];
					
	//pressing RETURN on either side of screen
	if ((bigChar[ptCode]=="team1")||(bigChar[ptCode]=="team2"))
	{
		//team one
		if (bigChar[ptCode]=="team1")
		{
			teamname1 = newname;
			var teamname = document.getElementById('team1name');
			var message = ["names","match",1,newname,1];
			var teamnameform = document.getElementById('team1');
			var theteam = 1;
		}
		else
		{
			teamname2 = newname;
			var teamname = document.getElementById('team2name');
			var message = ["names","match",2,newname,1];
			var teamnameform = document.getElementById('team2');
			var theteam = 2;
		}
		mypopup.postMessage(message,domain);
		teamname.innerHTML=newname;
		teamnameform.value=newname;
		newname="";
		newnamechars=0;
		for (c=2;c<11;c++) //clear the name row
		{
			var imageid   = "r1"+"c"+c;
			var borderid = "br1"+"c"+c;
			var image   = document.getElementById(imageid);
			var border = document.getElementById(borderid);
			image.style.visibility="hidden";
			border.style.visibility="hidden";
			message=["hide",1,c,"image"];
			mypopup.postMessage(message,domain);
			message=["hide",1,c,"border"];
			mypopup.postMessage(message,domain);
		}
	}
	else
	{
		//press BACKSPACE
		if (bigChar[ptCode]=="backspace")
		{
			var row = 1;
			newnamelength=newnamechars-1;
			newname = newname.substring(0,newnamelength);
			var col = newnamechars+1;
			var message = ["hide",row,col,"border"];
			mypopup.postMessage(message,domain);
			var message = ["hide",row,col,"image"];
			mypopup.postMessage(message,domain);
			var imageid   = "r"+row+"c"+col;
			var borderid = "br"+row+"c"+col;
			var image   = document.getElementById(imageid);
			var border = document.getElementById(borderid);
			image.style.visibility="hidden";
			border.style.visibility="hidden";
			newnamechars=newnamelength;
		}
		else
		{
		//press any other valid key until filled
			if ((bigChar[ptCode]!="")&&(newnamechars<9))
			{
				var row = 1;
				newnamechars++;
				var newchar = bigChar[ptCode];
				newname = newname+newchar;
				var col = newnamechars+1;
				var imagefile = "chars/"+bigCode[ptCode]+".png";
				var borderfile = "border_red.png";
				var message = ["image",row,col,imagefile,1];
				mypopup.postMessage(message,domain);
				message = ["border",row,col,borderfile,1];
				mypopup.postMessage(message,domain);
				var imageid   = "r"+row+"c"+col;
				var borderid = "br"+row+"c"+col;
				imagefile = "small_"+imagefile;
				borderfile = "small_graphics/"+borderfile;
				var image   = document.getElementById(imageid);
				var border = document.getElementById(borderid);
				image.src  = imagefile;
				image.style.visibility="visible";
				border.src = borderfile;
				border.style.visibility="visible";
			}
		}
	}
}
//translates generic keystrokes, parses to appropriate game handler
function dokey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode;
	//if (charCode > 31 && (charCode < 48 || charCode > 57)) hideimages();
	if ((charCode>47)&&(charCode<53)) ptCode = charCode-48;
	if ((charCode>52)&&(charCode<58)) ptCode = charCode+2;
		
	if ((charCode>64)&&(charCode<90)) ptCode = charCode-35;
	if ((charCode>96)&&(charCode<122)) ptCode = charCode-92;
	if (live==1)
	{
		var keyin = document.getElementById('keyin');
		keyin.value = "";
		//these are for monitoring
		var ptindex = document.getElementById('ptindex');
		ptindex.innerHTML=ptCode;
		var row = ((ptCode)%5)+1;
		var col = (Math.floor(ptCode/5))+1;
		var ptgrid = document.getElementById('ptgrid');
		ptgrid.innerHTML="r"+row+" c"+col;
		if (bigkeys==1) goBigKey(ptCode);
		else
		{
			if (theGame=="halfmatch") goHalfMatch(ptCode,row,col);
			if (theGame=="dailydash") goDailyDash(ptCode,row,col);
			if (theGame=="boggle") goBoggle(ptCode,row,col);
		}
	}
}
