var lc_name;
var showURL;
var objWidth;
var objHeight;
var curSpot=0;

function goToShow(showId, firstslide, forcePlayback){
	var newRegExp = new RegExp("ss%3D[0-9]{1,}%","g");
	showURL = showURL.replace(newRegExp,"ss%3D"+showId+"%");

	var newRegExp = new RegExp("sl%3D[0-9]{1,}%","g");
	showURL = showURL.replace(newRegExp,"sl%3D0%");

	if(forcePlayback>0){
		var newRegExp = new RegExp("3Facc%3D","g");
		showURL = showURL.replace(newRegExp,"3FforcePlayback=1%26acc%3D");
	}

	if(firstslide>0){
		var newRegExp = new RegExp("\&firstslide=[0-9]{1,}\&","g");
		showURL = showURL.replace(newRegExp,"&firstslide="+firstslide+"&");
	}

	if(2==1){
		vh_mc.LoadMovie(0,showURL);
	}else{
		useFlashLC("loadMovie", showURL+"~_level0");
	}
	vh_mc = null;
}

function goToWorkshop(spot){

	document.onmousemove = null;

	if(curSpot==spot){
		return;
	}

	var newRegExp = new RegExp("ss%3D","g");
	tempShowURL = showURL.replace(newRegExp,"sp%3D"+spot+"%26ss%3D");

	var newRegExp = new RegExp("&acc=","g");
	tempShowURL = tempShowURL.replace(newRegExp,"&stretch=1&acc=");

	var newRegExp = new RegExp("getshow","g");
	tempShowURL = tempShowURL.replace(newRegExp,"getworkshop");

	if(2==1){
		if(!vh_mc) return;
		vh_mc.LoadMovie(0,tempShowURL);
	}else{
		useFlashLC("loadMovie", tempShowURL+"~_level0");
	}
	vh_mc = null;

	curSpot = spot;
}

function domainOfPage() {
	domainName = document.location.hostname;
	if(domainName.length<=0)
		domainName = 'not_found';
	return domainName;
}

var isOverlay = false;
function AC_VHost_Embed_25205 (height, width, bgcolor, firstslide, loading, ss, sl, transparent, minimal, embedId, flashVersion, overlayStr) {
	flashVersion = flashVersion ? flashVersion : 6;
	objWidth	= width;
	objHeight	= height;
	lc_name 	= '1191875754006';
	embedId 	= embedId==''?'nothing':embedId;
	domString 	= '&pageDomain=sofie1.com';
	tokenString = '&token=8ef6dda434cbe907c3a1235a93de14c9';
	getShow 	= 'http%3A%2F%2Fvhost.oddcast.com%2Fgetshow.php%3Facc%3D25205'+escape('&ss='+ss+'&sl='+sl+'&embedid='+embedId+'&fs='+firstslide+domString+tokenString);
	url 		= 'http://vhost.oddcast.com/vhsssecure.php?doc='+getShow+'&edit=0&acc=25205&firstslide='+firstslide+'&loading='+loading+'&minimal='+minimal+'&bgcolor=0x'+bgcolor+domString+tokenString+'&lc_name='+lc_name+'&fv='+flashVersion+'&is_ie=0&followCursor=1';
	showURL 	= url;
	loading 	= 1; // done after request not to allow admin not to have a loader

	if (overlayStr && overlayStr != "_OVERLAYSTR_") {isOverlay = true;}

	if (transparent != 1){
		AC_RunFlContentX( 'height',height,'swliveconnect','true','src',url,'scale','noborder','id','VHSS','width',width,'bgcolor','#'+bgcolor,'quality','high','movie',url,'name','VHSS','codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashVersion+',0,0,0', 'allowScriptAccess', 'always');
	}else{
		AC_RunFlContentX( 'height',height,'swliveconnect','true','src',url,'scale','noborder','id','VHSS','width',width,'bgcolor','#'+bgcolor,'quality','high','movie',url,'name','VHSS','codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashVersion+',0,0,0', 'allowScriptAccess', 'always', 'wmode','transparent');
	}

	if (isOverlay) {initOverlay(overlayStr);}
}

function AC_VHost_Embed_25205_dbg (height, width, bgcolor, firstslide, loading, ss, sl, transparent, minimal, embedId, flashVersion, overlayStr) {
	flashVersion = flashVersion ? flashVersion : 6;
	objWidth	= width;
	objHeight	= height;
	lc_name 	= '1191875754006';
	embedId 	= embedId==''?'nothing':embedId;
	domString 	= '&pageDomain=sofie1.com';
	tokenString = '&token=8ef6dda434cbe907c3a1235a93de14c9';
	getShow 	= 'http%3A%2F%2Fvhost.oddcast.com%2Fgetshow_dbg.php%3Facc%3D25205'+escape('&ss='+ss+'&sl='+sl+'&embedid='+embedId+'&fs='+firstslide+domString+tokenString);
	url 		= 'http://vhost.oddcast.com/vhss_v3_dbg.swf?doc='+getShow+'&edit=0&acc=25205&firstslide='+firstslide+'&loading='+loading+'&minimal='+minimal+'&bgcolor=0x'+bgcolor+domString+tokenString+'&lc_name='+lc_name+'&fv='+flashVersion+'&is_ie=0&followCursor=1';
	showURL 	= url;
	loading 	= 1; // done after request not to allow admin not to have a loader

	if (overlayStr && overlayStr != "_OVERLAYSTR_") {isOverlay = true;}

	if (transparent != 1){
		AC_RunFlContentX( 'height',height,'swliveconnect','true','src',url,'scale','noborder','id','VHSS','width',width,'bgcolor','#'+bgcolor,'quality','high','movie',url,'name','VHSS','codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashVersion+',0,0,0', 'allowScriptAccess', 'always');
	}else{
		AC_RunFlContentX( 'height',height,'swliveconnect','true','src',url,'scale','noborder','id','VHSS','width',width,'bgcolor','#'+bgcolor,'quality','high','movie',url,'name','VHSS','codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashVersion+',0,0,0', 'allowScriptAccess', 'always', 'wmode','transparent');
	}

	if (isOverlay) {initOverlay(overlayStr);}
}


function AC_RunFlContentX(){

	var codebase = AC_GetCodebase

	             (  "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="

	              , "7,0,0,0", arguments

	             );



	AC_GenerateObj

	(  "AC_RunFlContentX()", true, "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"

	, codebase

	, "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"

	, "application/x-shockwave-flash", arguments

	);

}

var MSG_EvenArgs = 'The %s function requires an even number of arguments.'
                 + '\nArguments should be in the form "atttributeName","attributeValue",...';
var MSG_SrcRequired = "The %s function requires that a movie src be passed in as one of the arguments.";

function AC_GetCodebase(baseURL, defaultVersion, args){
	var codebase = baseURL + defaultVersion;
	for (var i=0; i < args.length; i=i+2) {
		currArg = args[i].toLowerCase();
		if (currArg == "codebase" && args.length > i+1) {
			if (args[i+1].indexOf("http://") == 0) {
				codebase = args[i+1];
			}else{
				codebase = baseURL + args[i+1];
			}
		}
	}

	return codebase;
}

function AC_sprintf(str){
	for (var i=1; i < arguments.length; i++){
		str = str.replace(/%s/,arguments[i]);
	}
	return str;
}

function AC_checkArgs(args,callingFn){
	var retVal = true;
	if (parseFloat(args.length/2) != parseInt(args.length/2)){
		alert(sprintf(MSG_EvenArgs,callingFn));
		retVal = false;
	}
	return retVal;
}

function AC_GenerateObj(callingFn, useXHTML, classid, codebase, pluginsPage, mimeType, args){

	if (!AC_checkArgs(args,callingFn)){
	return;
	}

	var tagStr = '';
	var currArg = '';
	var closer = (useXHTML) ? '/>' : '>';
	var srcFound = false;
	var embedStr = '<embed';
	var paramStr = '';
	var embedNameAttr = '';
	var objStr = '<object classid="' + classid + '" codebase="' + codebase + '"';

	for (var i=0; i < args.length; i=i+2){
		currArg = args[i].toLowerCase();

		if (currArg == "src"){
			if (callingFn.indexOf("RunSW") != -1){
				paramStr += '<param name="' + args[i] + '" value="' + args[i+1] + '"' + closer + '\n';
				embedStr += ' ' + args[i] + '="' + args[i+1] + '"';
				srcFound = true;
			}else if (!srcFound){
				paramStr += '<param name="movie" value="' + args[i+1] + '"' + closer + '\n';
				embedStr += ' ' + args[i] + '="' + args[i+1] + '"';
				srcFound = true;
			}
		}else if (currArg == "movie"){
			if (!srcFound){
				paramStr += '<param name="' + args[i] + '" value="' + args[i+1] + '"' + closer + '\n';
				embedStr += ' src="' + args[i+1] + '"';
				srcFound = true;
			}
		}else if (   currArg == "width"
		          || currArg == "height"
		          || currArg == "align"
		          || currArg == "vspace"
		          || currArg == "hspace"
		          || currArg == "class"
		          || currArg == "title"
		          || currArg == "accesskey"
		          || currArg == "tabindex"){
			objStr += ' ' + args[i] + '="' + args[i+1] + '"';
			embedStr += ' ' + args[i] + '="' + args[i+1] + '"';
		}else if (currArg == "id"){
			objStr += ' ' + args[i] + '="' + args[i+1] + '"';
			if (embedNameAttr == "")
				embedNameAttr = ' name="' + args[i+1] + '"';
		}else if (currArg == "name"){
			objStr += ' ' + args[i] + '="' + args[i+1] + '"';
			embedNameAttr = ' ' + args[i] + '="' + args[i+1] + '"';
		}else if (currArg == "codebase"){
		}else{
			paramStr += '<param name="' + args[i] + '" value="' + args[i+1] + '"' + closer + '\n';
			embedStr += ' ' + args[i] + '="' + args[i+1] + '"';
		}
	}

	if (!srcFound){
		alert(AC_sprintf(MSG_SrcRequired,callingFn));
		return;
	}

	if (embedNameAttr)
		embedStr += embedNameAttr;
	if (pluginsPage)
		embedStr += ' pluginspage="' + pluginsPage + '"';
	if (mimeType)
		embedStr += ' type="' + mimeType + '"';

	objStr += '>\n';
	embedStr += '></embed>\n';

	tagStr = objStr + paramStr + embedStr + "</object>\n";

		
	if (isOverlay) {
		document.getElementById("divVHSS").innerHTML = tagStr;
	} else {
		document.write(tagStr);
	}
}

function VHSS_DoFSCommand(eventName, args) {
	//alert(eventName+"    "+args);
	if (eventName == "onSlideBegin" || eventName == "sceneLoaded" || eventName == "vh_sceneLoaded") {
		if (window.vh_sceneLoaded != null){
			vh_sceneLoaded(args);
		}
	}
	else if (eventName=="hostLoaded" || eventName=="vh_hostLoaded") {
		if (window.vh_hostLoaded != null)	vh_hostLoaded();
	}
	else if (eventName=="talkStarted" || eventName=="vh_talkStarted") {
		if (window.vh_talkStarted != null)	vh_talkStarted();
	}
	else if (eventName=="talkEnded" || eventName=="vh_talkEnded") {
		if (window.vh_talkEnded != null)	vh_talkEnded();
	}
	else if (eventName=="audioLoaded" || eventName=="vh_audioLoaded"){
		if (window.vh_audioLoaded != null)	vh_audioLoaded(args);
	}
	else if (eventName == "ttsLoaded" || eventName == "vh_ttsLoaded"){
		if (window.vh_ttsLoaded != null)	vh_ttsLoaded(args);
	}
	else if (eventName=="aiResponse" || eventName=="vh_aiResponse"){
		if (window.vh_aiResponse != null)	vh_aiResponse(unescape(args));
	}
	else if (eventName == "audioProgress" || eventName == "vh_audioProgress"){
		if (window.vh_audioProgress !=null) vh_audioProgress(args);
	}
	else if (eventName == "vh_followOnPage"){
		if (window.mousemoveCapture != null && ((args == 1 && followCursor == 1) || args == 4)){
			//alert("start mouse follow on page");
			mousemoveCapture();
		}
		else if (window.mousemoveRelease != null && (args == 0 || args == 2)){
			//alert("stop mouse follow on page");
			mousemoveRelease();
		}
	}
}

// --- End VHSS player events ---

function setStatus(interruptMode, audioProgress, lookSpeed, randomMvmt){
	useFlashLC("setStatus", interruptMode+"~"+audioProgress+"~"+lookSpeed+"~"+randomMvmt);
}

// --- Speech Functions ---

function sayText(ttsText, voice, lang, engine, fx_type, fx_level){
	useFlashLC("sayText", escape(ttsText)+"~"+voice+"~"+lang+"~"+engine+"~"+fx_type+"~"+fx_level+"~js");
}

function sayAIResponse(ttsText, voice, lang, engine, botid, fx_type, fx_level){
	useFlashLC("sayAIResponse", escape(ttsText)+"~"+voice+"~"+lang+"~"+engine+"~"+botid+"~"+fx_type+"~"+fx_level+"~js");
}

function sayAudio(audioName, stTime){
	useFlashLC("sayAudio", audioName+"~"+stTime);
}

function loadText(ttsText, voice, lang, engine, fx_type, fx_level){
	useFlashLC("loadText", escape(ttsText)+"~"+voice+"~"+lang+"~"+engine+"~"+fx_type+"~"+fx_level+"~js");
}

function loadAudio(audioName){
	useFlashLC("loadAudio", audioName);	
}

function loadShow(showIndex){
	useFlashLC("loadShow", showIndex);
}

function loadScene(sceneIndex){
	loadShow(sceneIndex);
}

function setBackground(bgName){
	useFlashLC("setBackground", bgName);
}

function setInterruptMode(_mode){
	useFlashLC("setInterruptMode", _mode);
}

function replay(_val){
	useFlashLC("replay", _val);
}

function stopSpeech(){
	useFlashLC("stopSpeech");
}

function saySilent(init_time){
	useFlashLC("saySilent", init_time);
}


function setPlayerVolume(in_vol){
	useFlashLC("setPlayerVolume", in_vol);
}

// --- End Speech Functions ---


// --- Look Functions ---

function followCursor(newMouseMode){
	if (newMouseMode == 2)
		mousemoveCapture();
	else
		mousemoveRelease();
	
	useFlashLC("followCursor", newMouseMode+"~");
}

function recenter(){
	useFlashLC("recenter");
}

function setGaze(deg, dur, rad, pageReq){
	useFlashLC("setGaze", deg+"~"+dur+"~"+rad+"~"+pageReq);
}

function freezeToggle(){
	useFlashLC("freezeToggle");
}

function setLookSpeed(in_lookSp){
	useFlashLC("setLookSpeed", in_lookSp);
}

// --- End Look Functions ---

// --- Host Appearance Functions ---

function setColor(part, clr){
	useFlashLC("setColor", part+"~"+clr);
}

// --- End Host Appearance Functions ---

// --- Slide Functions ---


// --- Embed Overlay api ---
function overlayOpen(_play){
	if (window.showVhost != null)	showVhost(_play);
}

function overlayClose(){
	if (window.closeVhost != null)	closeVhost();
}

function overlayMaximize(_play){
	if (window.maximizeVhost != null)	maximizeVhost(_play);
}

function overlayMinimize(){
	if (window.minimizeVhost != null)	minimizeVhost();
}
// --- End Embed Overlay api ---

/*
*deprecated
*/
function SetLink(href, targetName){
	setLink(href, targetName);
}

function SetTarget(targetName){
	useFlashLC("SetTarget", targetName);
}
/*
*deprecated
*/

function setLink(href, targetName){
	useFlashLC("setLink", href+"~"+targetName);
}

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();
}

function setBackground(in_bg_name){
	useFlashLC("setBackground", in_bg_name);
}

// --- End Slide Functions ---


// --- Local connection queue and functions ---
var lc_busy = 0;
var lcQueue = new Array();

function vhss_lc_DoFSCommand(command, args) {
	lcLoaded();
}

function lcLoaded(){
	lc_busy =0;
	checkQueue();
}

function useFlashLC(meth, args){
	lcQueue[lcQueue.length]=meth;
	lcQueue[lcQueue.length]=args;
	checkQueue();
}

function checkQueue(){
	if (lc_busy || lcQueue.length == 0) return;
	var lc_temp1 = lcQueue[0];
	var lc_temp2 = lcQueue[1];
	var t_ar = new Array();
	for (var act = 2; act<lcQueue.length; ++act){
		t_ar[act-2] = lcQueue[act];
	}
	lcQueue = t_ar;
	loadFromQueue(lc_temp1, lc_temp2);
}

function loadFromQueue(meth, args){
	lc_busy = 1;
	var divcontainer = "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;
}

// --- End Local connection queue and functions ---


// --- hidden and in development functions ---

function sayAIResponseExported(ttsText,voice,lang,engine,account){
	useFlashLC("sayAIResponseExported", escape(ttsText)+"~"+voice+"~"+lang+"~"+engine+"~"+account);
}

function sayAudioExported(audioName, stTime, account){
	useFlashLC("sayAudioExported", audioName+"~"+stTime+"~"+account);
}

function sayTextExported(ttsText,voice,lang,engine,account){
	useFlashLC("sayTextExported", escape(ttsText)+"~"+voice+"~"+lang+"~"+engine+"~"+account);
}

function sayTextEmo(ttsText,voice,lang,engine,emo){
	useFlashLC("sayTextEmo", escape(ttsText)+"~"+voice+"~"+lang+"~"+engine+"~"+emo);
}

function hostSleep(_state){
	useFlashLC("hostSleep", _state);
}


function getAnchorPosition(anchorname) {
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;

	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }

	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}

function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}

function mousemoveCapture() {
	//alert("mouse capture");
	document.captureEvents(Event.MOUSEMOVE)
	if (document.onmousemove == null) document.onmousemove = updateMousePosition;
}

function mousemoveRelease() {
	//alert("stop mouse capture");
	document.releaseEvents(Event.MOUSEMOVE)
	document.onmousemove = null;
}



var tempX = 0;
var tempY = 0;
var milSeconds = 200;
var lastCallTime = getMicroTime();

function getMicroTime(){
	var d = new Date();
	return d.getTime();
}

function updateMousePosition(e) {
    tempX = e.pageX;
    tempY = e.pageY;

    if (tempX < 0){tempX = 0}
  	if (tempY < 0){tempY = 0}
  
	obj = getAnchorPosition('VHSS');
	
	hostX = obj.x + objWidth/2;
	hostY = obj.y - objHeight/2;
	
	w = tempX - hostX;
	h = tempY - hostY;

	if((tempX>obj.x && tempX<(obj.x+objWidth)) && (tempY>obj.y && tempY<obj.y)){
		return true;
	}	
	
	radius	= Math.sqrt(w*w + h*h);
	deg		= Math.atan(w/h)/0.017453293;
	
	if(w>=0&&h<=0){
		deg = Math.abs(deg);
	}else if(w>=0&&h>0){
		deg = 180 - deg;
	}else if(w<0&&h>0){
		deg = Math.abs(deg)+180;
	}else if(w<0&&h<=0){
		deg = 360 - deg;
	}
	
	if(radius>100)	radius = 100;
	
	if((getMicroTime()-lastCallTime)>milSeconds){
		setGaze(deg, 1, radius, 1);
		lastCallTime = getMicroTime();
	}
	
	return true
}
function setNextSceneIndex(sceneRange){
	useFlashLC("setNextSceneIndex", sceneRange);
}

function gotoScene(sceneIndex){
	useFlashLC("gotoScene", sceneIndex);
}

function gotoNextScene (){
	useFlashLC("gotoNextScene");
}

function gotoPrevScene(){
	useFlashLC("gotoPrevScene");
}
//embed overlay code
var eo_width, eo_height, eo_vhostX, eo_vhostY, eo_horzRef, eo_vertRef, eo_scroll, eo_closeBtn, eo_drag, eo_minimize, eo_customThumb, eo_thumb, eo_thumbnail, eo_tooltip, eo_loadMin, eo_minimizeTo, eo_appear, eo_hide, eo_hideAfter, eo_contentWinWidth;
var dv, dvHTML, re, positionVhostOn, dragObj, contentWidth, leftMarg, margOffset, showMargOffset, thumbWidth, thumbHeight, isMinimized;

function getElementStyle(IEStyleProp, CSSStyleProp) {
    var elem = document.body;
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
    return "";
}

function checkIt(string) {
	var place = navigator.userAgent.toLowerCase().indexOf(string) + 1;
	return place;
}

function initOverlay(overlayStr) {
	var cssMarg = parseInt(getElementStyle('marginLeft','margin-left'));
	var htmlMarg = parseInt(document.body.getAttribute('leftMargin'));
	if (isNaN(htmlMarg)) {htmlMarg = 0;}
	leftMarg = cssMarg + htmlMarg;
	if(checkIt('msie')) {
		margOffset = leftMarg/2;
	} else {
		margOffset = 0;
	}

	dv = document.getElementById('divVHSS');
	dv.style.display 	= "none";
	dv.style.position	= "absolute";
	dv.style.zIndex		= 1000;
	dvHTML 				= dv.innerHTML;
	positionVhostOn 	= true;
	showMargOffset		= true;
	isMinimized			= false;

	var eo_properties = overlayStr.split("|");
	eo_width	= parseInt(eo_properties[0]);
	eo_height	= parseInt(eo_properties[1]);
	eo_vhostX	= parseInt(eo_properties[2]);
	eo_vhostY	= parseInt(eo_properties[3]);
	eo_horzRef	= eo_properties[4];
	eo_vertRef	= eo_properties[5];
	if (eo_properties[6] == "false") eo_scroll = false;
		else eo_scroll = true;
	eo_drag 	= parseInt(eo_properties[7]);
	eo_closeBtn	= parseInt(eo_properties[8]);
	eo_minimize	= parseInt(eo_properties[9]);
	eo_customThumb = parseInt(eo_properties[10]);
	eo_thumb	= unescape(eo_properties[11]);
	eo_tooltip	= unescape(eo_properties[12]);
	eo_loadMin	= parseInt(eo_properties[13]);
	eo_minimizeTo = eo_properties[14];
	eo_appear	= parseInt(eo_properties[15]);
	eo_hide		= parseInt(eo_properties[16]);
	eo_hideAfter = parseInt(eo_properties[17]);
	eo_contentWinWidth = parseInt(eo_properties[18]);

	var tables = document.getElementsByTagName('table');
	var divs = document.getElementsByTagName('div');
	if(tables[0]) {
		contentWidth = parseInt(tables[0].offsetWidth);
	} else {
		contentWidth = parseInt(divs[0].offsetWidth);
	}

	eo_thumbnail = new Image();
	eo_thumbnail.src = eo_thumb;
	if (eo_customThumb && eo_thumbnail.width != 0) {
		thumbWidth = eo_thumbnail.width;
		thumbHeight = eo_thumbnail.height;
	} else {
		thumbWidth = 50;
		thumbHeight = 50;
	}

	if (eo_drag) {createDrag();}
	if (eo_minimize) {createMinimize();}
	if (eo_closeBtn) {createClose();}

	positionVhost();
	re = window.setInterval('positionVhost()', 10);

	if (eo_loadMin && eo_appear > -1) {
		showMaximize();
	} else {
		if (eo_appear == -1) {
			if (checkIt('msie')) {
				dv.innerHTML = "";
			} else {
				dv.style.display = "none";
			}
		} else {
			dv.style.display = "block";
		}
	}
}

function overlay_talkEnded_internal() {
	if (eo_hide) {
		if (eo_hide == 1) {
			window.setTimeout('dv.style.display = "none";', eo_hideAfter * 1000);
		} else if (eo_hide == 2) {
			if(!document.getElementById("maximize")) {
				var maximize = makeMaximize();
				document.body.appendChild(maximize);
			}
			showMaximize();
		}
	}
}

//positioning functions
function getWinWidth() {
	if (self.innerWidth) {
		return self.innerWidth;
	} else if (document.documentElement.clientWidth) {
		return document.documentElement.clientWidth;
	} else {
		return document.body.clientWidth;
	}
}

function getWinHeight() {
	if (self.innerHeight) {
		return self.innerHeight;
	} else if (document.documentElement.clientHeight) {
		return document.documentElement.clientHeight;
	} else {
		return document.body.clientHeight;
	}
}

function detectScroll(dimension) {
	if (eo_scroll) return 0;
	var eo_scrollY, eo_scrollX;

	if (document.documentElement) {
		eo_scrollX = document.documentElement.scrollLeft + document.body.scrollLeft;
		eo_scrollY = document.documentElement.scrollTop + document.body.scrollTop;
	}

	if (window.scrollX) {
		eo_scrollX = window.scrollX;
		eo_scrollY = window.scrollY;
	}

	if (dimension == 'X') {
		return eo_scrollX;
	} else if (dimension == 'Y') {
		return eo_scrollY;
	} else {
		return 0;
	}
}

function positionVhost() {
	if(!showMargOffset) margOffset = 0;
	if(positionVhostOn) {
		switch (eo_horzRef) {
			case "C":
				if (eo_scroll) {
					if (parseInt(getWinWidth()) > contentWidth) {
						dv.style.left	= (parseInt(getWinWidth())/2) + eo_vhostX + margOffset + "px";
					} else {
						dv.style.left	= (contentWidth/2) + eo_vhostX + margOffset + "px";
					}
				} else {
					dv.style.left = (parseInt(getWinWidth())/2) + eo_vhostX + detectScroll('X') + margOffset + "px";
				}
				break;
			case "R":
				dv.style.left	= parseInt(getWinWidth()) + eo_vhostX + detectScroll('X') + "px";
				break;
			default:	// case "L"
				dv.style.left	= eo_vhostX + detectScroll('X') + "px";
				break;
		}

		switch (eo_vertRef) {
			case "B":
				if (isMinimized) {
					document.getElementById("maximize").style.top = parseInt(getWinHeight()) + eo_vhostY + detectScroll('Y') + "px";
					break;
				} else {
					dv.style.top = parseInt(getWinHeight()) + eo_vhostY + detectScroll('Y') + "px";
					break;
				}
			case "M":
				dv.style.top = (parseInt(getWinHeight())/2) + eo_vhostY + detectScroll('Y') + "px";
				break;
			default:	// case "T"
				if (isMinimized) {
					document.getElementById("maximize").style.top = eo_vhostY + detectScroll('Y') + "px";
					break;
				} else {
					dv.style.top = eo_vhostY + detectScroll('Y') + "px";
					break;
				}
		}
	}
}

function resetPosition(newX,newY) {
	var winWidth	= parseInt(getWinWidth());
	var winHeight	= parseInt(getWinHeight());
	switch (eo_horzRef)	{
		case "C":
			eo_vhostX	= newX - (winWidth/2);
			break;
		case "R":
			eo_vhostX	= newX - winWidth;
			break;
		default:	// case "L"
			eo_vhostX	= newX;
			break;
	}

	switch (eo_vertRef) {
		case "B":
			eo_vhostY	= newY - winHeight - detectScroll('Y');
			break;
		case "M":
			eo_vhostY	= newY - (winHeight/2) - detectScroll('Y');
			break;
		default:	// case "T"
			eo_vhostY	= newY - detectScroll('Y');
			break;
	}
}

//drag bar functions
function createDrag() {
	dragObj = new Object();
	dragObj.zIndex = 10;
	if(!document.getElementById("dragBar")) {
		var dragBar = makeDragBar();
		dv.appendChild(dragBar);
	} else {
		var dragBar = document.getElementById("dragBar");
	}
	dragBar.onmousedown = function (e) {dragStart(e,'divVHSS');}
	eo_vhostY = eo_vhostY + 21;
}

function createMinimize() {
	if(!document.getElementById("dragBar")) {
		var dragBar = makeDragBar();
		dv.appendChild(dragBar);
	} else {
		var dragBar = document.getElementById("dragBar");
	}
	var minimize = makeMinimize();
	dragBar.appendChild(minimize);
	var maximize = makeMaximize();
	document.body.appendChild(maximize);
	minimize.onclick = showMaximize;
}

function createClose() {
	if(!document.getElementById("dragBar")) {
		var dragBar = makeDragBar();
		dv.appendChild(dragBar);
	} else {
		var dragBar = document.getElementById("dragBar");
	}
	var closeBtn = makeCloseBtn();
	dragBar.appendChild(closeBtn);
	closeBtn.onclick = closeVhost;
}

function makeDragBar() {
	var dragBar = document.createElement('div');
	dragBar.id = "dragBar";
	dragBar.style.position = "absolute";
	dragBar.style.left = "0px";
	dragBar.style.top =  "-21px";
	dragBar.style.height = "19px";
	dragBar.style.width = eo_width - 2 + "px";
	dragBar.style.zIndex = 1000;
	dragBar.style.padding = "0px";
	dragBar.style.backgroundImage = "url(http://vhost.oddcast.com/admin/images/overlay_dragbar_back.gif)";
	dragBar.style.backgroundRepeat = "repeat-x";
	dragBar.style.borderTop = "1px solid #636363";
	dragBar.style.borderLeft = "1px solid #636363";
	dragBar.style.borderRight = "1px solid #212121";
	dragBar.style.borderBottom = "1px solid #212121";
	dragBar.style.cursor = "move";
	dragBar.style.textAlign = "right";
	return dragBar;
}

function makeCloseBtn() {
	var closeBtn = document.createElement('a');
	closeBtn.innerHTML = "<img src='http://vhost.oddcast.com/admin/images/overlay_close_button.gif' />";
	closeBtn.style.width = "18px";
	closeBtn.style.height = "19px";
	closeBtn.style.backgroundColor = "#3e3e3e";
	closeBtn.style.cursor = "pointer";
	return closeBtn;
}

function makeMinimize() {
	var minimize = document.createElement('a');
	minimize.innerHTML = "<img src='http://vhost.oddcast.com/admin/images/overlay_minimize_button.gif' />";
	minimize.style.width = "18px";
	minimize.style.height = "19px";
	minimize.style.backgroundColor = "#3e3e3e";
	minimize.style.cursor = "pointer";
	return minimize;
}

function makeMaximize() {
	var maximize = document.createElement('div');
	maximize.id = "maximize";
	maximize.innerHTML = "<a title='" + eo_tooltip + "'><img src='" + eo_thumb + "' width='" + thumbWidth + "' height='" + thumbHeight + "' alt='" + eo_tooltip + "' /></a>";
	maximize.style.position = "absolute";
	maximize.style.border = "1px solid black";
	maximize.style.width = thumbWidth + "px";
	maximize.style.height = thumbHeight + "px";
	maximize.style.cursor = "pointer";
	maximize.style.zIndex = 1000;
	maximize.style.display = "none";
	maximize.style.overflow = "hidden";
	return maximize;
}

function showMaximize() {
	if(!document.getElementById("maximize")) return;
	var maximize = document.getElementById("maximize");
	if (eo_minimizeTo == "T") {
		var newX = parseInt(dv.style.left, 10);
		var newY = parseInt(dv.style.top, 10) - 21;
	} else {
		var newX = parseInt(dv.style.left, 10) + (eo_width / 2) - (thumbWidth/2);
		var newY = parseInt(dv.style.top, 10) + (eo_height / 2) - (thumbHeight/2) - 21;
	}
	if (newX < 0) {newX = 0;}
	if (newY < 21) {newY = 21;}
	resetPosition(newX,newY);
	maximize.style.left = newX + "px";
	maximize.style.top = newY + "px";
	dv.style.display = "none";
	if (checkIt('msie')) {dv.innerHTML = "";}
	maximize.style.display = "block";
	maximize.onmousedown = function (e) {dragStart(e,'maximize');}
	maximize.ondblclick = function () {showVhost();}
	isMinimized = true;
	stopSpeech();
}

function showVhost() {
	if(!document.getElementById("maximize")) {
		dv.style.display = "block";
	} else {
		var maximize = document.getElementById("maximize");
		if (eo_minimizeTo == "T") {
			var newX = parseInt(maximize.style.left, 10);
			if (checkIt('msie')) {
				var newY = parseInt(maximize.style.top, 10);
			} else {
				var newY = parseInt(maximize.style.top, 10) + 21;
			}
		} else {
			var newX = parseInt(maximize.style.left, 10) - (eo_width / 2) + (thumbWidth/2);
			var newY = parseInt(maximize.style.top, 10) - (eo_height / 2) + (thumbHeight/2);
		}
		if (newX < 0) {newX = 0;}
		if (newY < 21) {newY = 21;}
		resetPosition(newX,newY);
		dv.style.left = newX + "px";
		dv.style.top = newY + "px";
		maximize.style.display = "none";
		if (checkIt('msie')) {
			dv.innerHTML = dvHTML;
			if (eo_drag) {createDrag();}
			if (eo_minimize) {createMinimize();}
			if (eo_closeBtn) {createClose();}
		}
		dv.style.display = "block";
		isMinimized = false;
		replay();
	}
}

function closeVhost() {
	if (checkIt('msie')) {
		dv.innerHTML = "";
	} else {
		dv.style.display = "none";
	}
}

//drag functions
var mouseX, mouseY;
function getMousePos(e) {
	if(!e) e = window.event;
	if (e.srcElement) {
		mouseX = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		mouseY = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	if (e.target) {
		mouseX = e.clientX + window.scrollX;
		mouseY = e.clientY + window.scrollY;
	}
}

function dragStart(e, id) {
	if(!e) e = window.event;
	positionVhostOn = false;
	showMargOffset = false;
	var el;

	// If an element id was given, find it. Otherwise use the element being clicked on.
	if (id) {
		dragObj.elNode = document.getElementById(id);
	} else {
		if (e.srcElement) {dragObj.elNode = window.event.srcElement;}
		if (e.target) {dragObj.elNode = event.target;}

		// If this is a text node, use its parent element.
		if (dragObj.elNode.nodeType == 3) {dragObj.elNode = dragObj.elNode.parentNode;}
	}
	
	// Get cursor position with respect to the page.
	getMousePos(e);

	// Save starting positions of cursor and element.
	dragObj.cursorStartX = mouseX;
	dragObj.cursorStartY = mouseY;
	dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
	dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

	if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
	if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

	// Update element's z-index.
	dragObj.elNode.style.zIndex = ++dragObj.zIndex;

	// Capture mousemove and mouseup events on the page.
	if (e.srcElement) {
		document.attachEvent("onmousemove", dragGo);
		document.attachEvent("onmouseup",   dragStop);
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (e.target) {
		document.addEventListener("mousemove", dragGo,   true);
		document.addEventListener("mouseup",   dragStop, true);
		e.preventDefault();
	}
}

function dragGo(event) {
	// Get cursor position with respect to the page.
	getMousePos(event);

	// Move drag element by the same amount the cursor has moved.
	dragObj.elNode.style.left = (dragObj.elStartLeft + mouseX - dragObj.cursorStartX) + "px";
	dragObj.elNode.style.top  = (dragObj.elStartTop  + mouseY - dragObj.cursorStartY) + "px";
	dragObj.elNode.style.zIndex = 1000;

	if (event.srcElement) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (event.target) {
		event.preventDefault();
	}
}

function dragStop(event) {
	// Stop capturing mousemove and mouseup events.
	if (event.srcElement) {
		document.detachEvent("onmousemove", dragGo);
		document.detachEvent("onmouseup",   dragStop);
	}
	if (event.target) {
		document.removeEventListener("mousemove", dragGo,   true);
		document.removeEventListener("mouseup",   dragStop, true);
	}
	var newX = parseInt(dragObj.elNode.style.left, 10);
	var newY = parseInt(dragObj.elNode.style.top,  10);
	dragObj.elNode.style.zIndex = 1000;
	resetPosition(newX,newY);
	positionVhostOn = true;
}



