<!-- begin

state="load"
boardLayout = new Array(
 new Array("s","q","q","q","q","q","q","q"),
 new Array("","q","","","","","","q"),
 new Array("","q","","","","q","q","q"),
 new Array("q","q","","","","q","",""),
 new Array("q","","q","q","q","q","q","q"),
 new Array("q","","q","","q","","","q"),
 new Array("q","","q","","q","q","q","q"),
 new Array("q","q","q","","","","","e")
)

function Move(p1,p2) {
 this.from=p1
 this.to=p2
}


validMoves=new Array(
 new Move(0,1), new Move(1,2), new Move(1,9), 
 new Move(2,3), new Move(3,4), new Move(4,5),
 new Move(5,6), new Move(6,7), new Move(7,15),
 new Move(9,17), new Move(15,23), new Move(17,25),
 new Move(21,29), new Move(22,21), new Move(23,22),
 new Move(24,32), new Move(25,24), new Move(29,37),
 new Move(32,40), new Move(34,35), new Move(35,36),
 new Move(36,37), new Move(36,44), new Move(37,38),
 new Move(38,39), new Move(39,47), new Move(40,48),
 new Move(42,34), new Move(44,52), new Move(47,55),
 new Move(48,56), new Move(50,42), new Move(52,53),
 new Move(53,54), new Move(54,55), new Move(55,63),
 new Move(56,57), new Move(57,58), new Move(58,50)
)

function loadImages() {
 questionGIF=new Image(); questionGIF.src="/images/harryface.gif"
 feetGIF=new Image(); feetGIF.src="/images/feet.gif";
}
function startGame() {
 state="start"
 position=0
 direction="F"
 stepsToMove=0
 msg("Click on Start to begin.")
}
function msg(s) {
 var doc=parent.frames[1].document
 doc.open()
 doc.writeln('<BODY BGCOLOR="white">')
 doc.writeln(s)
 doc.writeln('</BODY>')
 doc.close()
}
function square(n) {
 nextPos=parseInt(n)
 if((board(nextPos)=="s")&& (state=="start")) {
   state="move"
   stepsToMove=steps()
   msg(move())
 }else if(state=="move"){
  if(canMove(nextPos)){
   if(board(nextPos)=="e") 
  {
    state="end"
    restoreCurrentPosition()
    showMovement(nextPos)
    winner()
   }
   else if(board(nextPos)=="s") 
   {
     startGame()
   }
   else
   { 
    state="wait"
    restoreCurrentPosition()
    showMovement(nextPos)
    processMovement(nextPos)
   }
  }else msg("Can't move there!")
 }
}
function board(n) {
 return boardLayout[Math.floor(n/8)][n%8]
}
function steps() {
 return Math.round((Math.random()*2)+1)
}
function move() {
 var squares=" squares."
 if(stepsToMove==1) squares=" square."
 var dir=" forward "
 if(direction=="B") dir=" backward "
 return "Move"+dir+stepsToMove+squares
}
function canMove(n) {
 for(var i=0;i<validMoves.length;++i){
  if(direction=="F" && validMoves[i].from==position && 
   validMoves[i].to==n) return true
  if(direction=="B" && validMoves[i].from==n && 
   validMoves[i].to==position) return true
 }
 return false
}
function restoreCurrentPosition() {
 var sq=board(position)
 var imgPos=imagePosition(position)
 var oldImage=questionGIF
 if(sq=="s") return
 else if(sq=="1") oldImage=plus1GIF
 else if(sq=="3") oldImage=plus3GIF
 else if(sq=="6") oldImage=plus6GIF
 else if(sq=="-1") oldImage=minus1GIF
 else if(sq=="-2") oldImage=minus2GIF
 else if(sq=="-3") oldImage=minus3GIF
 else if(sq=="-5") oldImage=minus5GIF
 else if(sq=="-6") oldImage=minus6GIF
 else if(sq=="-10") oldImage=minus10GIF
 window.document.images[imgPos].src=oldImage.src
}

function imagePosition(n) {
 imageCount=0
 for(var i=0;i<n;++i)
  if(board(i)!="") ++imageCount
 var len=window.document.images.length
 // Fixes bug in Navigator 3.0
if(len>38) imageCount+=Math.floor(len/2)
 return imageCount
}

function showMovement(n) {
 var imgPos=imagePosition(n)
 window.document.images[imgPos].src=feetGIF.src
}
function processMovement(n) {
 position=n
 --stepsToMove
 if(stepsToMove==0){
  var sq=board(position)
  var num=0
  if(sq=="q") askQuestion()
  else{
   num=parseInt(sq)
   if(num<0) direction="B"
   else direction="F"
   stepsToMove=Math.abs(num)
   state="move"
   msg(move())
  }
 }else{
  state="move"
  msg(move())
 }
}

function winner() {
 var doc=parent.frames[1].document
 doc.open()
 doc.writeln('<BODY BGCOLOR="white">')
 doc.writeln('<center><H3>Congratulations -- You Win!!!</H3>')
 doc.writeln('<img src="/images/wizardhat.jpg" width=116 height=128 border=0 alt="Wizard"><br><br>')
 doc.writeln('Click Reload to play again.</center>')
 //doc.writeln('<form><input type=button value="Close Game" onClick="self.close()"></form>')
 doc.writeln('</BODY>')
 doc.close()
}
function Question() {
 this.question=Question.arguments[0]
 var n=Question.arguments.length
 this.answers = new Array(n-2)
 for(var i=1; i<n-1; ++i) this.answers[i-1]=Question.arguments[i]
 this.correctAnswer=Question.arguments[n-1]
}
function askQuestion() {
 rnd=Math.round(Math.random()*(qa.length-1))
 var doc=parent.frames[1].document
 doc.open()
 doc.writeln('<HTML>')
 doc.writeln('<BODY BGCOLOR="white">')
 doc.writeln("<H4 ALIGN='CENTER'>"+qa[rnd].question+"</H4>")
 doc.writeln('<FORM NAME="answerForm">')
 for(var ii=0;ii<qa[rnd].answers.length;++ii) {
  doc.writeln('<H4 ALIGN="CENTER">')
  doc.write('<INPUT TYPE="RADIO" NAME="answer">')
  doc.writeln(qa[rnd].answers[ii])
  if(ii+1==qa[rnd].answers.length) {
   doc.write('<BR><BR><INPUT TYPE="BUTTON"')
   doc.writeln('NAME="continue" VALUE="Continue" ')
   doc.writeln(' onClick="parent.frames[0].focus()">')
  }
  doc.writeln('</H4>')
 }
 doc.writeln('</FORM>')
 doc.writeln('</BODY></HTML>')
 doc.close()
}
function checkAnswers() {
 if(state!="wait") return
 var numAnswers=qa[rnd].answers.length
 var correctAnswer=qa[rnd].correctAnswer
 var doc=parent.frames[1].document
 for(var jj=0;jj<numAnswers;++jj) {
  if(doc.answerForm.elements[jj].checked) {
   if(jj==correctAnswer){
    correct()
	break
   }else{
	incorrect()
	break
   }
  }
  if(jj==numAnswers){
   incorrect()
   break
  }
 }
}
function correct() {
 var num=steps()
 direction="F"
 stepsToMove=num
 state="move"
 msg("<H4>Correct!</H4>"+move())
}
function incorrect() {
 var num=steps()
 direction="B"
 stepsToMove=num
 state="move"
 msg("<H4>Incorrect.</H4>"+move())
}

//Questions
qa = new Array()

qa[0] = new Question("Who is You-Know-Who?",
 "Ron Weasley",
 "Voldemort",
 "Harry Potter",
 "Hermoine",
 1)

qa[1] = new Question("What did Mad-Eye used to be?",
 "a wizard",
 "a muggle",
 "an Auror",
 "none of the above",
 2)

qa[2] = new Question("What powered the Hogwarts Express?",
 "gas",
 "magic",
 "wizard wishes",
 "steam",
3)

qa[3]  = new Question("What color is the Hogwarts Express?",
 "scarlet",
 "robin's egg blue",
 "black",
 "all of the above",
0)

qa[4]= new Question("What or who is Pigwidgeon?",
 "an owl",
 "a screamer",
 "a Quidditch player",
 "a Hogwarts house",
 0)

qa[5] = new Question("Who wrote the newspaper article about Harry and the Triwizard Tournament?",
 "Colin Creevey",
 "Hermoine Granger",
 "Rita Skeeter",
 "Sirius",
 2)

qa[6] = new Question("What shape is the unusual scar on Harry Potter's forehead?",
 "crescent moon",
 "bolt of lightning",
 "cat",
 "magic wand",
1)

qa[7] = new Question("Which Quidditch team does Victor Krum play for?",
"Gryffindor",
 "Ireland",
 "Bulgaria",
 "Slytherin",
  2)


qa[8] = new Question("What is the name of Mr. Crouch's house-elf?",
 "Dobby",
 "Blinkie",
 "Smudgie",
 "Winky",
 3)

qa[9] = new Question("Which is the best broomstick?",
 "Nimbus 2000",
 "Firebolt",
 "Sweeper Upper",
 "Nimbus 3000",
 1)

qa[10] = new Question("Who is the newest Dark Arts teacher at Hogwarts?",
 "Mad-Eye Moody",
 "Gildery Lockhart",
 "Professor Lupin",
 "Professor McGonagall",
 0)

qa[11] = new Question("What is Rita Skeeter's profession?",
 "teacher",
 "taxi driver",
 "journalist",
 "auror",
2)

qa[12] = new Question("What is the Third Challenge of the Triwizard Competition?",
 "fight a dragon",
 "find the Triward Cup in a magical maze",
 "find a treasured possession at the bottom of a lake",
  "none of the above",
1)

qa[13] = new Question("How old is Harry in his fourth year at Hogwarts?",
 "16",
 "15",
 "14",
 "13",
 2)

qa[14] = new Question("How old do you have to be to compete in the Triwizard Competition?",
 "14",
 "15",
 "16", 
 "17",
 3)

qa[15] = new Question("Who has the Snitch at the end of the Quidditch World Cup Final?",
 "Ludo Bagman",
 "Victor Krum",
 "Aidan Lynch",
 "Harry Potter",
1)

qa[16] = new Question("What is the acronym for the wizarding exams that Hogwarts students must take at 15?",
 "O.W.Ls",
  "S.P.E.W.",
 "D.U.M.B.L.E.C.H.O.R.E.S.",
 "none of the above",
 0)


qa[17] = new Question("What is the first word in a Summoning Charm?",
 "Accio",
 "Crucio",
 "Expelliarmus",
 "Achtung",
0)


qa[18] = new Question("Who is the Caretaker at Hogwarts?",
 "Hagrid",
 "Professor Sinistra",
 "Flitwick",
 "Mr. Filch",
3)

qa[19] = new Question("Who looks after the dragons brought to Hogwarts for Task One?",
"Hagrid",
"Hermoine Granger",
"Dudley Dursley",
"Charlie Weasley",
3)

qa[20] = new Question("What was the Gryffindor Tower password on the night the Triwizard Tournament is announced?",
 "Divination!",
 "Balderdash!",
 "Abbra Kadabra!",
 "Three Broomsticks!",
1)

qa[21] = new Question("Who is an Animagus known by the canine names Padfoot and Snuffles?",
 "Sirius Black",
 "Voldermort",
 "Cornelius Fudge",
 "Lucius Malfoy",
0)

qa[22] = new Question("What magical object declares: I'll have a look inside your mind and tell you where you belong?",
"the Pensieve",
"the Sneakoscope",
"the Mirror of Erised",
"the Sorting Hat",
3)

qa[23] = new Question("Who eats a Ton-Tongue Toffee and suffers the consequences?",
"Cedric Diggory",
"Hermoine Granger",
"Dudley Dursley",
"Hagrid",
2)


// End -->
