// JavaScript Document
var speechTimings = new Array( [30,45,60,75],
                               [60,90,120,130],
                               [120,150,180,210],
                               [180,240,300,330],
                               [300,360,420,450] );
var topic=new Array();
topic[0] = "What was the best thing that happened to you over the New Year holiday? "
topic[1] = "What are you looking forward to the most in the next month?"
topic[2] = "If you could meet any famous person, who would it be and why?"
topic[3] = "If you were given the chance to ask the prime minister one question what would it be and why?"
topic[4] = "What are you going to miss most about leaving school/work/university and why?"
topic[5] = "What was your favourite subject in school and why?"
topic[6] = "What is the best present you have ever received?"
topic[7] = "What two things would you take with you to a desert island?"
topic[8] = "If you were a superhero (or villain), what would your superpowers be?"
topic[9] = "If you could win a dream vacation where would you go and where would you stay?"
topic[10] ="What would you do if you won a million dollars?"
topic[11] ="What was the most memorable thing that happened to your last month? "
topic[12] ="What is your favorite season of the year and why?"
topic[13] ="If you could represent your country at the Olympics which sport would you like to participate in and why? "
topic[14] ="If you could cross two animals to make a new one, which ones would you cross and why?"
topic[15] ="If you got one wish from a genie what would you wish for?"
topic[16] ="Describe your first day at primary school."
topic[17] ="Describe your last day at high school."
topic[18] ="What do you like most about your best friend."
topic[19] ="If you had a choice of pet, what animal would you choose?"
topic[20] = "Why did you choose you current field of occupation?"
topic[21] = "What scares you most?"
topic[22] = "What is a T.V. show you really enjoy watching and why?"
topic[23] = "What is a book have you read that you really enjoyed and why?"
topic[24] = "What is a movie that you would recommend we watch and why?"
topic[25] = "What is your favourite meal?"
topic[26] = "If you could be invisible for a day, what would you do?"
topic[27] = "What is your dream car?"
topic[28] = "What would your ideal job be?"
topic[29] = "If you could go back in time and give a 10 year old version of yourself advice, what would it be?"
topic[30] ="What is your favourite meal?"
topic[31] ="What is your favourite day of the week?"
topic[32] ="What is your favourite T.V. show and why?"
topic[33] ="What is your favourite book and why?"
topic[34] ="What is your favourite movie and why?"
topic[35] = "Would you like to have an identical twin? What about it would be best? Worst?"
topic[36] = "If you were to be granted any one magical power you wanted, what would you pick?"
topic[37] = "If you could see into the future but not change it, would you want to do so?"
topic[38] = "What things scare you even though you know there is no reason to be afraid?"
topic[39] = "What is your favorite season of the year? Why?"
topic[40] = "If you could buy any rare collection in the world, which would you choose?"
var startTime;
var currentlyLit = 0;
var speaking = 0;
function toSeconds (time) {
return (time.getHours()*60*60) +
       (time.getMinutes()*60 ) +
       time.getSeconds();
}
function doneBulbs() {
  document.getElementById("topic").innerHTML = "<b><font color='red'>Your time is up!</font></b>";
  currentlyLit = 0;
}

function resetBulbs() {
  if ( document.images ) {
    document["green"].src= "files/off_g.jpg";
    document["yellow"].src= "files/off_y.jpg";
    document["red"].src= "files/off_r.jpg";
  }
  currentlyLit = 0;
}
function checkTime() {
  if ( !speaking ) {
    return;
  }
  var elapsed = ( toSeconds ( new Date() ) - startTime - 5 );
  var ctl = speechTimings[document.getElementsByName("timing")[0].value];
  
  if ( document.getElementsByName("isTimerOn")[0].checked ) {
	document.getElementById("time").innerHTML = elapsed + " secs";
  } else {
    document.getElementById("time").innerHTML = "";
  }
  if ( currentlyLit == 0 && elapsed >= ctl[0] ) {
    document["green"].src= "files/on_g.jpg";
    currentlyLit = 1;
  } else if ( currentlyLit == 1 && elapsed >= ctl[1] ) {
    document["green"].src= "files/off_g.jpg";
    document["yellow"].src= "files/on_y.jpg";
    currentlyLit = 2;
  } else if ( currentlyLit == 2 && elapsed >= ctl[2] ) {
    document["yellow"].src= "files/off_y.jpg";
    document["red"].src= "files/on_r.jpg";
    currentlyLit = 3;
  } else if ( currentlyLit == 3 && elapsed >= ctl[3] ) {
    document["red"].src= "files/off_r.jpg";
    document.getElementById("time").innerHTML = "";
    document.getElementById("topic").innerHTML = "<br>";
	doneBulbs();
    speaking = 0;
    currentlyLit = 3;
  }
  setTimeout ( "checkTime()", 1000 );
}
function updateTopic() {
  document.getElementById("topic").innerHTML = topic[Math.floor(Math.random()*topic.length)];
  speaking = 1;
  startTime = toSeconds ( new Date() );
  setTimeout ( "checkTime()", 1000 );
}
function newTopic() {
  resetBulbs();
  document.getElementById("topic").innerHTML = "Get ready!";
  setTimeout ( "updateTopic()", 1000 );
}

