
function say(text, name, options, callback)
{
  var pace = 0;
  $("#question_box").html('');
  $("#response_box").html('');
  $("#question_box").append(text.charAt(0));
  setTimeout( function() { keepTyping(text, name, options, callback); }, pace);
}

function keepTyping(text, callback, name, options)
{
  currentText = $("#question_box").html();
  position = currentText.length;
  $("#question_box").append(text.charAt(position));
  lapse = Math.floor((200-49)*Math.random()) + 50;
  if (currentText.length < text.length)
    setTimeout( function() { keepTyping(text, callback, name, options); }, lapse);
  else
    stopTyping(text, callback, name, options);
}

function stopTyping(text, callback, name, options)
{
  if (options!==undefined)
  {
    optionInfo = options.split(",");

    responseHTML = '<select id="' + name + '" class="answer_options"><option value="">--Select One--</option>';

    for ( var i in optionInfo )
    {
      responseHTML += '<option value="' + optionInfo[i] + '">' + optionInfo[i] + '</option>';
    }

    responseHTML += '</select>';
  }
  else if (name!==undefined)
  {
    responseHTML = '<input class="answer_text" type="text" id="' + name + '" /><button class="answer_button">Reply</button>';
  }
  else
    responseHTML = '';

  $("#response_box").html(responseHTML);
  $(".answer_options").unbind();
  $(".answer_reply").unbind();
  callback();
}

function toggleCursor()
{
  var blank = "&#9608;";
  if ($("#cursor_box").html() == blank)
    $("#cursor_box").html("");
  else
    $("#cursor_box").html(blank); 
}

$(document).ready( function()
{
  //setInterval("toggleCursor()", 700);
});

