
		var Player = new Array (0, 0);
		var games = 0;
		
		var remote = 0;
		var squareSize = 120;
		var squareSize2 = squareSize*2;
		var squareSize3 = squareSize*3;
		
		var xCorrection = 22;
		var yCorrection = 75;
		var dopusk = 1;
		
		var wiiBlue = "#34BEED";
		var wiiRed = "#EE7A07";
		
		var passive = "#F0F0F0";
		
		var Active = new Array(wiiBlue, wiiRed);
		
		var ex;
		var ou;
		var pic;
		var spanInfo;
		
		var tempNo = 0;
		
		var ttt;

		var Squares = new Array();
		Squares[0] = new Array (0, 0);
		Squares[1] = new Array (squareSize, 0);
		Squares[2] = new Array (squareSize2, 0);
		Squares[3] = new Array (0, squareSize);
		Squares[4] = new Array (squareSize, squareSize);
		Squares[5] = new Array (squareSize2, squareSize);
		Squares[6] = new Array (0, squareSize2);
		Squares[7] = new Array (squareSize, squareSize2);
		Squares[8] = new Array (squareSize2, squareSize2);


		var playedSquares = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1);

		var spanPlayer = new Array();
		var spanResults = new Array();
		
		var activeSquare = -1;
		
		if (!window.opera){
			alert("This Game is intended to be played with Opera for Wii.");
			history.go(-1);
		}
		else {
			alert("Use the 'B' button to place your symbol in a square. Scroll, or Zoom to levels other than 100% is not recommended");
		}
		
		
		function HighLight() {
			for (i = 0; i < 9; i++)
			{
				if (playedSquares[i] == -1){
					if (i != activeSquare) {
						Draw.setFillColor(240, 240, 240);
					}
					else {
						if (remote == 0){
							Draw.setFillColor(200, 240, 250);
						}
						else {
							Draw.setFillColor(250, 220, 180);
						}
					}
					Draw.drawRectangle(Squares[i][0] + dopusk, Squares[i][1] + dopusk, Squares[i][0] + squareSize - dopusk, Squares[i][1] + squareSize - dopusk, true, 0);
				}
			}
		}
		
		function checkSquares(player) {
		
			if ((playedSquares[0] == player) && (playedSquares[4] == player) && (playedSquares[8] == player)) return "d1"; // first diagonal
			if ((playedSquares[2] == player) && (playedSquares[4] == player) && (playedSquares[6] == player)) return "d2"; // second diagonal
			if ((playedSquares[0] == player) && (playedSquares[1] == player) && (playedSquares[2] == player)) return "r1"; // first row
			if ((playedSquares[3] == player) && (playedSquares[4] == player) && (playedSquares[5] == player)) return "r2"; // second row
			if ((playedSquares[6] == player) && (playedSquares[7] == player) && (playedSquares[8] == player)) return "r3"; // third row
			if ((playedSquares[0] == player) && (playedSquares[3] == player) && (playedSquares[6] == player)) return "c1"; // first column
			if ((playedSquares[1] == player) && (playedSquares[4] == player) && (playedSquares[7] == player)) return "c2"; // second column
			if ((playedSquares[2] == player) && (playedSquares[5] == player) && (playedSquares[8] == player)) return "c3"; // third column
			
			for (i = 0; i < 9; i++) {
				if (playedSquares[i] == -1) {
				// at least one square is still blank - continue
				return "continue";
				}
			}
			// board full
			return "done";
		}

		function initGame(){

			// initialize the board
			ttt = document.getElementById("ttt")
			Draw.initialize(ttt);
			Draw.clear(0, 0, squareSize3, squareSize3);
			Draw.setFillColor(240, 240, 240);
			Draw.drawRectangle(0, 0, squareSize3, squareSize3, true, 0);
			Draw.setLineColor(128, 128, 128);
			Draw.drawLine(0, 0, 0, squareSize3);
			Draw.drawLine(squareSize, 0, squareSize, squareSize3);
			Draw.drawLine(squareSize2, 0, squareSize2, squareSize3);
			Draw.drawLine(squareSize3, 0, squareSize3, squareSize3);
			Draw.drawLine(0, 0, squareSize3, 0);
			Draw.drawLine(0, squareSize, squareSize3, squareSize);
			Draw.drawLine(0, squareSize2, squareSize3, squareSize2);
			Draw.drawLine(squareSize3, squareSize3, squareSize3, squareSize3);
			
			//ttt.left = 300;
			
			for (i = 0; i < 9; i++)	{playedSquares[i] = -1;}

			// get the images
			ex = document.getElementById("ex");
			ou = document.getElementById("ou");
			
			spanPlayer[0] = document.getElementById("player1");
			spanPlayer[1] = document.getElementById("player2");
			
			spanResults[0] = document.getElementById("results1");
			spanResults[1] = document.getElementById("results2");
			
			spanGames = document.getElementById("gamesNo");
			
			// start with random palyer
			remote = parseInt(Math.random() + 0.5);

			spanPlayer[remote].style.backgroundColor = Active[remote];
			spanPlayer[(remote + 1)%2].style.backgroundColor = passive;
		
			doPlay();
		}

		function doPlay(){

			Wiimote.SetActive(remote);
			
			if(Wiimote.Current)
			{
				activeSquare = -1;
				
				for(i = 0; i < 9; i++)				
				{
					theX = parseInt(Wiimote.GetX());
					theY = parseInt(Wiimote.GetY());

					if ((playedSquares[i] == -1) && ((theX > (Squares[i][0] + xCorrection)) && (theY > (Squares[i][1] + yCorrection))) && ((theX < (Squares[i][0] + squareSize + xCorrection)) && (theY < (Squares[i][1] + squareSize + yCorrection))))
					{
						// mark the square
						activeSquare = i;
						
						// if pressing the trigger
						//*
						if(Wiimote.GetKeyStatus(Wiimote.BUTTON_B))
						{
							// set the image acording to the active remove
							pic = remote==0?ex:ou;
							
							// square is played from the palyer
							playedSquares[i] = remote;
		
							// draw the image
							Draw.drawImage(Squares[i][0]+ dopusk, Squares[i][1] + dopusk, Squares[i][0] + squareSize - dopusk, Squares[i][1] + squareSize - dopusk, pic, 0);
							
							// check if winning and exit
							code = checkSquares(remote);
							if (code != "continue")
							{
								if (code == "done")
									{
									alert ("You tie!");
									spanPlayer[remote].style.backgroundColor = passive;
									}
								else 
									{
									alert("Player " + (remote + 1) + " Wins!!!");
									spanResults[remote].innerHTML = ":" + (++Player[remote]);
									}
									
								spanGames.innerHTML = "Games:" + (++games);
								
								return code;
							}
							
							// continue - switch the remotes
							remote=(++remote)&1;
							spanPlayer[remote].style.backgroundColor = Active[remote];
							spanPlayer[(remote + 1)%2].style.backgroundColor = passive;
		
							break;
						}
						//*/
					}

				}
				// highlight
				HighLight();
			}

			setTimeout("doPlay()", 20);
		}

