
var lc_name;
var showURL;
var objWidth;
var objHeight;
var curSpot=0;
var ThisURL=''; // should be found at the beginning
var OddcastDomain='http://vhss-a.oddcast.com';

var agt=navigator.userAgent.toLowerCase();
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);

var JSGroup = is_ie&&is_win?1:2;


function getURLParam( name ){  

	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( ThisURL );
	if( results == null )    
		return '';  
	else    
		return results[1];
}

function getThisURL(){
	arr = document.getElementsByTagName("script");
	for(i=0;i<arr.length;i++){
		if(arr[i].src && arr[i].src.match(/vhost_embed_functions.*\.php(\?.*)?$/)){
			ThisURL = arr[i].src;
			break;
		}
	}
}

getThisURL();

var followCursorFlag = getURLParam('followCursor');
var JSFlag = getURLParam('js');
var accId = getURLParam('acc');

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){
		showURL = showURL+"&playOnLoad=1";
	}

	if(JSGroup==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(JSGroup==1){
		if(!vh_mc) return;
		vh_mc.LoadMovie(0,tempShowURL);
	}else{
		useFlashLC("loadMovie", tempShowURL+"~_level0");
	}
	vh_mc = null;

	curSpot = spot;
}

function loadExtraJS(JS_URL){
	var head = document.getElementsByTagName('head')[0];
	var elementOverLay = document.createElement('script');
	elementOverLay.src = JS_URL;
	elementOverLay.type = 'text/javascript';
	head.appendChild(elementOverLay);	
}


//	domainName = document.location.hostname;
function domainOfPage() {
	domainName = '207.210.93.201';
	if(domainName.length<=0)
		domainName = 'not_found';
	return domainName;
}

// sets a cookie if doesn't exist
loadExtraJS('http://vhost.oddcast.com/setCookie.php');

var fname = 'AC_VHost_Embed_'+accId;

window[fname] = function() {
	AC_VHost_Embed (accId,arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9], arguments[10], arguments[11]);
}

var isOverlay = false;
var globalOverlayString = '';
function AC_VHost_Embed (accountID, height, width, bgcolor, firstslide, loading, ss, sl, transparent, minimal, embedId, flashVersion, overlayStr, embedName) {
	flashVersion 	=  (flashVersion =='' || typeof flashVersion == 'undefined' || flashVersion < 9) ? 8 : flashVersion;
	objWidth		= width;
	objHeight		= height;
	lc_name 		= '1239693697';
	embedId 		= embedId==''?'nothing':embedId;
	embedName 		= (embedName =='' || typeof embedName == 'undefined') ? 'VHSS' : embedName;
	
	if (transparent ==1){
		bgcolor = '';
	}
	
	// flash 9
	xmlScr			= (flashVersion==9) ? 'playScene' : 'getshow';
	player			= (flashVersion==9) ? 'vhss_v5' : 'vhss_v3';
	PlayerServer		= (flashVersion==9) ? 'http://content.oddcast.com/vhss' : 'http://vhss-a.oddcast.com';
	
	domString 		= '&pageDomain='+domainOfPage();

	emb			= (overlayStr && overlayStr != "_OVERLAYSTR_") ? 9 : 8;
		
	playScene 		= 'http%3A%2F%2Fvhss-d.oddcast.com%2Fphp%2F'+xmlScr+'%2Facc%3D'+accountID+'%2Fss%3D'+ss+'%2Fsl%3D'+sl;
	playScene		= playScene + (flashVersion<9 ? '%3Fembedid%3D'+embedId : '');	// appends embedid if less than flash 9
	
	url 			= PlayerServer+'/'+player+'.swf?doc='+playScene+'&acc='+accountID+'&bgcolor=0x'+bgcolor+domString+'&lc_name='+lc_name+'&fv='+flashVersion+'&is_ie='+(JSGroup==1?1:0)+(followCursorFlag>0?'&followCursor='+followCursorFlag:'')+'&emb='+emb;
	url			= url + (flashVersion>8 ? '&embedid='+embedId : '');	// appends embedid if it's flash 9
	
	showURL 		= url;
	loading 		= 1; // done after request not to allow admin not to have a loader

	if (overlayStr && overlayStr != "_OVERLAYSTR_"){
		globalOverlayString = overlayStr;
		loadExtraJS(OddcastDomain+'/admin/includes/vhss_embedOverlayFunctions.js');
		isOverlay = true;
	}

	if (transparent != 1){
		AC_RunFlContentX( 'height',height,'swliveconnect','true','src',url,'scale','noborder','id',embedName,'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', embedName,'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');
	}
	
	SWFFormFix('VHSS');
}

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

	);

}

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('error args',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"){
			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('error',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);
	}
}

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');
}

if(JSFlag>0){	
	loadExtraJS(OddcastDomain+'/admin/includes/vhss_api_v2.js');
			
	if(!is_mac){
		loadExtraJS(OddcastDomain+'/admin/includes/vhss_api_cursor_'+(JSGroup==1?'pcie':'other')+'.js');
	}
}

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16.push(key+"="+_18[key]);}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();SWFFormFix(this.getAttribute("id"));return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}return _23;};deconcept.PlayerVersion=function(_27){this.major=_27[0]!=null?parseInt(_27[0]):0;this.minor=_27[1]!=null?parseInt(_27[1]):0;this.rev=_27[2]!=null?parseInt(_27[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_29){var q=document.location.search||document.location.hash;if(q){var _2b=q.substring(1).split("&");for(var i=0;i<_2b.length;i++){if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){return _2b[i].substring((_2b[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2d=document.getElementsByTagName("OBJECT");for(var i=_2d.length;i>0;i--){_2d[i].style.display="none";for(var x in _2d[i]){if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);}if(Array.prototype.push==null){Array.prototype.push=function(_30){this[this.length]=_30;return this.length;};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
/**********End SWFObject*************/


/**
 * mikelee 08/18/2008
 * I've removed the documentation and the autofix code to reduce size.
 * also modified not to use document.forms[name] syntax so we can proceed with forms that have no name.
 * go to http://www.teratechnologies.net/stevekamerman/index.php?category=8 for details about this script.
 *
 * SWFFormFix v2.1.0: SWF ExternalInterface() Form Fix - http://http://www.teratechnologies.net/stevekamerman/
 *
 * SWFFormFix is (c) 2007 Steve Kamerman and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Project sponsored by Tera Technologies - http://www.teratechnologies.net/
 */

SWFFormFix = function(swfname){
	if(navigator.appName.toLowerCase() != "microsoft internet explorer")return false;
	var testnodename = "SWFFormFixTESTER";
	document.write('<div id="'+testnodename+'" onclick="SWFFormFixCallback(this,\''+swfname+'\');return false;" style="display:none">&nbsp;</div>');
	document.getElementById(testnodename).onclick();
}
SWFFormFixCallback = function (obj,swfname){
	var path = document;
	var error = false;
	var testnode = obj;
	while(obj = obj.parentNode){
		if(obj.nodeName.toLowerCase() == "form"){
				path = obj;
		}
	}
	testnode.parentNode.removeChild(testnode);
	if(error) return false;
	window[swfname]=path[swfname];
	return true;
}
/**********End SWFFormFix*************/
