// ------------------------- EVENTS functions
// FSCommand messages
function VHSS_DoFSCommand(eventName, args) {
 var VHSSObj = InternetExplorer ? VHSS : document.VHSS;
 if (eventName=="onSlideBegin") {
  // playing scene index = sceneNumber
  //the scene begins playing, add actions here
 }
 else if (eventName=="hostLoaded") {
  //Host loaded, add actions here
  //path to sender = args
 }
 else if (eventName=="talkStarted") {
  //path to sender = args
  //talk begins, add actions here
 }
 else if (eventName=="talkEnded") {
  //path to sender = args
  //talk ended, add actions here
 }
 else if (eventName=="audioLoaded"){
  //loaded audio track name =  args
  //loaded audio is ready
 }
 else if (eventName=="ttsLoaded"){
  //loaded text to sppech audio =  args
  //loaded text to speech is ready
 }
 else if (eventName=="aiResponse"){
  //ai response
 }
}
// ------------------------- API INTIATION AND SERVICE
mouseMode=1;
var vhssObj;
var hostPath=null;
 
var ua = navigator.userAgent.toLowerCase();
var is_pc_ie  = (( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 )) || ((ua.indexOf('mozilla')!=-1)&& (parseInt(navigator.appVersion)==4)));
 
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
 
var hostPath = '/slide/curPuppet/';
 
if(InternetExplorer){
 sep1 = sep2 = ".";
}else{
 sep1 = ":";
 sep2 = "/";
}
 
function getHostPath(){
 if(InternetExplorer){
  mc = VHSS;
  hostPath = mc.GetVariable(hostPath);
  curHost = hostPath + sep2 + "host" + sep2 + "engine";
 }else{
  mc = document.VHSS;
  hostPath = mc.TGetProperty(hostPath,11);
  curHost = hostPath + sep2 + "host" + sep2 + "engine";
 }
}
// -------------------------
 
// Hook for Internet Explorer
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
   navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
 document.write('<SCR'+'IPT LANGUAGE=VBScript\> \n');
 document.write('on error resume next \n');
 document.write('Sub VHSS_FSCommand(ByVal command, ByVal args)\n');
 document.write('  call VHSS_DoFSCommand(command, args)\n');
 document.write('end sub\n');
 document.write('</SCR'+'IPT\> \n');
}
 
function showTranscript(acc_id,ss_id,audioID,slidenum){
 transWindow = window.open( "http://vhost.oddcast.com/transcript_frame.php?acc="+acc_id+"&ss="+ss_id+"&au="+audioID+"&sn="+slidenum,"transWindow","width=500,height=500,toolbar=no,resizable=no");
 transWindow.focus();
}
// -------------------------
 
// ------------------------- Host Speech and Facial API FUNCTIONS
function useFlashLC(meth, args){
 var divcontainer = "vhss_lc";
 if(!document.getElementById(divcontainer)){
  var divholder = document.createElement("div");
  divholder.id = divcontainer;
  document.body.appendChild(divholder);
 }
 document.getElementById(divcontainer).innerHTML = "";
 var divinfo = "<embed src='http://vhost.oddcast.com/vhss_lc.swf' FlashVars='lc_name="+lc_name+"&methodNm="+meth+"&args="+escape(args)+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
 document.getElementById(divcontainer).innerHTML = divinfo;
}
 
function stopSpeech(){
 if(is_pc_ie){
  getHostPath();
  mc.TCallLabel(curHost, "stopSpeech");
 }else{
  useFlashLC("stopSpeech");
 }
}
 
function replay(_val){
 if(is_pc_ie){
  vhssObj = InternetExplorer ? VHSS : window.document.VHSS;
  vhssObj.SetVariable("replayParam", _val);
  vhssObj.TCallLabel("/", "replay");
 }else{
  useFlashLC("replay", _val);
 }
}
 
//function variables:
//newMouseMode: 0 - turns mouse tracking OFF; 1 - turns mouse tracking ON
function followcursor(newMouseMode){
 if(is_pc_ie){
  getHostPath();
  mouseModePath= hostPath + sep2 + "host" + sep1 + "mouseMode" ;
  mc.SetVariable(mouseModePath,newMouseMode);
  mc.TCallLabel(curHost, "followcursor");
 }else{
  useFlashLC("followcursor", newMouseMode);
 }
}
 
function recenter(){
 if(is_pc_ie){
  getHostPath();
  mc.TCallLabel(curHost, "recenter");
 }else{
  useFlashLC("recenter");
 }
}
 
function setGaze(deg, dur, rad){
 if(is_pc_ie){
  getHostPath();
  tmp= hostPath + sep2 + "host" + sep1 + "lookDeg";
  mc.SetVariable(tmp, deg);
  tmp= hostPath + sep2 + "host" + sep1 + "lookRad";
  mc.SetVariable(tmp, rad);
  tmp= hostPath + sep2 + "host" + sep1 + "lookDur";
  mc.SetVariable(tmp, dur);
  mc.TCallLabel(curHost, "setLook");
 }else{
  useFlashLC("setGaze",deg+"~"+dur+"~"+rad);
 }
}
 
function freezeToggle(){
 if(is_pc_ie){
  vhssObj = InternetExplorer ? VHSS : window.document.VHSS;
  vhssObj.TCallLabel("/", "freezeToggle");
 }else{
  useFlashLC("freezeToggle");
 }
}
 
