//Copywrite notice.
//You may copy this javascript but must leave this notice in place.
//This script was developed by Paul Alcock of Agility Systems, Inc. 
//http://www.agilitysystems.com
//The script is designed to show the old 3X3 pieces realign puzzle trick.
//To install and use this script follow these easy steps.
//Copy the js file to your webserver public java folder.
//eg. /web/Java/PuzzleGold.js
//Modify the script variables
// All vars with the //** should be edited to suite your needs.
//Copy the html page to the web directory
//eg. /web/mypuzzlepage.html
//Don't edit the puzzle page until you have the script working correctly.
//Create the pieces of the puzzle.
//I use paintshop pro 8.01 to do this, the image slicer is an ideal tool for this.
//Rename the bits for the puzzle to be Tile_0_0.gif (or what ever extension you choose.)
//
			var aRows= new Array();
		  aRows[0]= new Array('','Tile_1_2','Tile_2_0');
		 	aRows[1]= new Array('Tile_0_0','Tile_1_0','Tile_0_2');
		 	aRows[2]= new Array('Tile_1_1','Tile_2_1','Tile_0_1');
		 	
		 	var Rows;
		 	var Cols;
		 	var WSet="Tile_0_0Tile_1_0Tile_2_0Tile_0_1Tile_1_1Tile_2_1Tile_0_2Tile_1_2Tile_Blank";
		 	var CurrentSet="";
		 
			var aCurrentBlank = new Array(0,0);			
			var CurrentBlank="Tile_0_0";
			
			var BlankImage = "/_Images/Puzzle/Tile_Blank.gif";//**
			
			var SelectedTile;			
			var ImgPath="/_Images/Puzzle/";//**
			var ImgPrefix="Tile_";//**
			var ImgExt=".gif";//**
			var ImgField;
			var WinImage;
			var ImgResultPrefix="WinTile_";//**
			var WinPage="www.rotary6990.org";//**
			
			function TryMove(x,y){
				if (	 (x-1 == aCurrentBlank[0]) && (y 		== aCurrentBlank[1])
						|| (x+1 == aCurrentBlank[0]) && (y 		== aCurrentBlank[1])
						|| (x 	== aCurrentBlank[0]) && (y-1 	== aCurrentBlank[1])
						|| (x 	== aCurrentBlank[0]) && (y+1 	== aCurrentBlank[1])
					)
				{
					MoveTile(x,y)
				}
			}
			
			function MoveTile(x,y){
				SelectedTile= aRows[y][x];
				document.images[CurrentBlank].src=ImgPath + SelectedTile + ImgExt;
				
				aRows[aCurrentBlank[1]][aCurrentBlank[0]]= SelectedTile;				
				aRows[y][x]=ImgPrefix + "Blank";
				aCurrentBlank[0] = x;
				aCurrentBlank[1] = y;
				CurrentBlank = ImgPrefix + x + "_" + y;
				document.images[CurrentBlank].src=BlankImage;
				CurrentSet="";
				for (Rows=0;Rows<=2;Rows++){
					for (Cols=0;Cols<=2;Cols++){
						CurrentSet = CurrentSet + aRows[Rows][Cols];
					}
				}
				if (CurrentSet == WSet){
					document.images[CurrentBlank].src="/_Images/Puzzle/Tile_2_2.gif";
					document.images.EntryImage.src="/_Images/Puzzle/Tile_Entry_Ani.gif";
					
				}
			}
			function ShowTest(){
				if (CurrentSet == WSet){
					self.location="http://www.coralspringsrotaryclub.org/Winner.cgi?showwinnerform+" + WSet;
				}
				else{
					alert("You have not won yet!");
				}
			}
