// Site Pal Library <sysSitePal.js> 
// Copyright (C) 2007 HighTower

var spFirstTime = true;
var spTalking = true;
var spCounter = 0;
var spResponse = 1;
var spMaximum = 5;
var spAudioFile = "4eBM Home";
var spText2Talk = new String ("");
var spFeaturedSpeech = true;

function characterClicked() {
  spCounter += 1;
  if (spFirstTime) {
    if (spCounter >= spMaximum) {
      stopSpeech();
      sayAudio('4eBM Click ReadItYourself');
      spCounter = 0;
    }
  } else {
    if (spTalking == false) {
      switch (spResponse) {
        case 5 :
          sayAudio('4eBM Click Not Fair');
          break;
        case 4 :
          sayAudio('4eBM Click Come On');
          break;
        case 3 :
          sayAudio('4eBM Click Switch');
          break;
        case 2 :
          sayAudio('4eBM Click StopPoking');
          break;
        default :
          sayAudio('4eBM Click StopThat');
      }
//    sayText('\\_Ah',2,1,4)
      spResponse += 1;
      if (spResponse>spMaximum) {
        spResponse = 1
      }
    }
  }
}

// sayText syntax
// sayText(text,voice,language,engine);
// last used sayText(spText2Talk,3,1,3);

function vh_sceneLoaded(sceneIndex) {
  if (spText2Talk=="") {
    sayAudio(spAudioFile);
  } else {
    sayText(spText2Talk,3,1,3);
  }
  spText2Talk = "";
  spAudioFile = "";
  document.all.toggleCheckBox.disabled = false;
}

function vh_talkStarted() {
  spTalking = true;
}

function vh_talkEnded() {
  if (spFeaturedSpeech) {
    spFeaturedSpeech = false;
    sayThis = new String ("");
    sayThis = "By the way, if you have any information on ";
    sayThis = sayThis + document.all.sayThisNext.value;
    sayThis = sayThis + ", please press the Provide Info button below."
    sayText(sayThis,3,1,3);
  }
  spFirstTime = false;
  spTalking = false;
}

function setCookie(c_name,value,expiredays) {
  var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
} 

function getCookie(c_name) {
  if (document.cookie.length>0) {
    c_start=document.cookie.lastIndexOf(c_name + "=");
    if (c_start!=-1) { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}

function isSpeechEnabled() {
  spSpeechEnabled = getCookie("speechEnabled");
  if (spSpeechEnabled == "") {
    spSpeechEnabled = "Y"
    setCookie("speechEnabled",spSpeechEnabled,1);
  }
  if (spSpeechEnabled == "Y") {
    return true;
  } else {
    return false;
  }
}

function spAssignSpeech(spAudioFile) {
  if (!(isSpeechEnabled())) {
    spAudioFile = "";
  }
  return spAudioFile;
}


function toggleSpeech(e) {
  if (e.checked == 1) {
    setCookie("speechEnabled","Y",1);
    vh_talkStarted();
    speech = new String(document.all.audioFile.value);

    // "4eBM" indicates that it is an Audio File save at OddCast
    if (speech.substring(0,4)=="4eBM") {
      sayAudio(speech);
    } else {
      sayText(speech,3,1,3);
    }

  } else {
    stopSpeech();
    setCookie("speechEnabled","N",1);
  }
  return true;
}

function speechCheckbox(e) {
  document.write ("<br>");
  document.write ("Speech Enabled");
  document.write ("&nbsp;");
  isChecked = "";
  if (isSpeechEnabled()) {
    isChecked = "checked";
  }
  document.write ("<input type=checkbox class=entry id=toggleCheckBox disabled "+isChecked+" onClick='toggleSpeech(this);'>");
  document.write ("<input type=hidden class=entry id=audioFile value='"+e+"'>");
}

isSpeechEnabled();


