// ------------------------- API INTIATION AND SERVICE
mouseMode=1;
var vhssObj;
var hostPath=null;

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

//This is the path when using the oddcast players. In case you are embedding the model (without a player) in a Flash movie, adjust the path to the instance.
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";
	}
}
// -------------------------

// ------------------------- EVENTS functions
// FSCommand messages
function VHSS_DoFSCommand(command, args) {
	var VHSSObj = InternetExplorer ? VHSS : document.VHSS;
	if (command=="onSlideBegin") {
		//the scene begins playing, add actions here
		// playing scene index = args
	}
	else if (command=="hostLoaded") {
		//Host loaded, add actions here
	}
	else if (command=="talkStarted") {
		//talk begins, add actions here
	}
	else if (command=="talkEnded") {
		//talk ended, add actions here
	}
}

// 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('<SCRIPT 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('</SCRIPT\> \n');
}

function showTranscript(acc_id,ss_id,audioID,slidenum){
	transWindow = window.open( "http://vhss.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 control API FUNCTION (embed show, scene, model)
function stopSpeech(){
	getHostPath();
	mc.TCallLabel(curHost, "stopSpeech");
}

function replaySpeech(){
	getHostPath();
    mc.TCallLabel(curHost, "replaySpeech");
}

//function variables:
//newMouseMode: 0 - turns mouse tracking OFF; 1 - turns mouse tracking ON
function followcursor(newMouseMode){
	getHostPath();
	mouseModePath= hostPath + sep2 + "host" + sep1 + "mouseMode" ;
	mc.SetVariable(mouseModePath,newMouseMode);
	mc.TCallLabel(curHost, "followcursor");
}

function recenter(){
	getHostPath();
	mc.TCallLabel(curHost, "recenter");
}

function sayText(ttsText,voice,lang,engine,noInterrupt){
	getHostPath();
	mc.SetVariable("tts.lang",lang);
	mc.SetVariable("tts.voice",voice);
	mc.SetVariable("tts.text",ttsText);
	mc.SetVariable("tts.engine",engine);
	mc.TCallLabel("/tts", "sayTTS");
}

// ------------------------- Scene Flow API FUNCTION (embed show, scene)

function replay(){
   vhssObj = InternetExplorer ? VHSS : window.document.VHSS;
   vhssObj.TCallLabel("/", "replay");
}

function freezeToggle(){
   vhssObj = InternetExplorer ? VHSS : window.document.VHSS;
   vhssObj.TCallLabel("/", "freezeToggle");
}

// ------------------------- Link API FUNCTION (embed show, scene)

function SetLink (href){
   vhssObj = InternetExplorer ? VHSS : window.document.VHSS;
   vhssObj.SetVariable("slide.BUTTON.HREF",href);
}

function SetTarget (targetName){
   vhssObj = InternetExplorer ? VHSS : window.document.VHSS;
   vhssObj.SetVariable("slide.BUTTON.WINDOW",targetName);
}

function sayDAVE(){
sayText(
"Human: are you dave the ESL bot? Bot: Yes I am DAVE E.S.L. bot. Human: what is your surname? Bot: E. S. L. Bot Human: and your first name? Bot: My first name is DAVE. Human: no what is your first name? Bot: Are you serious? DAVE. Human: okay, what does dave stand for? Bot: Yeah okay, DAVE = Dynamic Advanced Version Equipment.",1,2,1);
}

function talkToAlice()
{
	window.open("http://www.pandorabots.com/pandora/talk?botid=f5d922d97e345aa1", "", "dependent=yes,directories=no,width=450,height=550,location=no,menubar=no,personalbar=no,scrollbars=yes,status=no,toolbar=yes");
}

function askAlice(whatToAsk)
{
	if (whatToAsk.length > 0)
	{
		window.open("http://alicebot.org/join.html", "", "dependent=yes,directories=no,width=450,height=550,location=no,menubar=no,personalbar=no,scrollbars=yes,status=no,toolbar=yes");
	}
}

function openInSeparateWindow(url, innerWidth, innerHeight)
{
	window.open(url, "", "dependent=no,directories=no,width=" + (innerWidth + 40) + ",height=" + (innerHeight + 40) + ",location=no,menubar=no,personalbar=no,scrollbars=yes,status=no,toolbar=no");
}

function getArguments()
{
	wlocation = new String(window.location);
	argstart = wlocation.indexOf("?");
	if (argstart > -1)
	{
		args = new String(wlocation.substr(argstart));
		return args;
	} else {
		return "";
	}
}

function addToList(theList, toAdd)
{
	if (theList == "")
	{
		theList = toAdd;
	} else {
		andPosition = theList.indexOf(" and");
		if (andPosition > -1)
		{
			theList = theList.substr(0, andPosition) + ", " + theList.substr(andPosition + 5) + " and " + toAdd;
		} else {
			theList = theList + " and " + toAdd;
		}
	}

	return theList;
}

function missingArgument(description, argName, argDescription)
{
	if (getArguments().indexOf(argName) > -1)
	{
		description = addToList(description, argDescription);
	}

	return description;
}

function LaunchMediaModule(url) {
	var list = 'width=358,height=455,resizable=0,status=0,location=0,toolbar=0';
	mm_window = window.open(url, 'mm_window', list);
	mm_window.focus();		
}
