var medianame; // a global variable to hold the name of the media file to show
var myslidingdiv=null; //global variable to hold the sliding div, which is changed from null  to "slidingdiv" when the function runs
var myslidingdivcontent=null; //global variable to hold the div inside the sliding div whose inner html is rewritten when the function runs
var currentmedia = ""; //global variable to hold the name of the current pano media file (minus the suffix)
var optionsstring=''; //string to write in option buttons for viewer selection
var optionscode= '<div id="options"><p>Select your preferred viewer:<br>';

//-------------------------SET THE MINIMUM REQUIRED VERSIONS
var minQTVersion = "5.0.0";			// minimal required version checked for QuickTime
var minDevalVRVersion = "0,5,0,0";  // minimal required version checked for DevalVR
var minFlashVersion = "9.0.28.0";		// minimal required version checked for Flash






var qualityForFlash = 200; //set the quality for the Flash Pureplayer

var pluginPriority_DevalVR=1;
var pluginPriority_Java=2;
var pluginPriority_Flash=3;
var pluginPriority_QuickTime=4;		// Set the order of Priority to use in each plugin 
		// when Autodetect option is selected. Change 
		// the number or priority for each plugin


var enableSizeLimits=0;				// 0: disable  1: enable  (size limits for QT, DevalVR and Spi-v)
var enableSizeLimitsJava=0;			// 0: disable  1: enable  (size limits for Java)
var enableSizeLimitsFlash=0;		// 0: disable  1: enable  (size limits for Flash)

var maxViewerWidth="1280";
var maxViewerHeight="1024";
var maxViewerWidthJava="900";
var maxViewerHeightJava="700";
var maxViewerWidthFlash="900";
var maxViewerHeightFlash="700";





var enableSizeRatio=0;				// 0: disable size ratio    1: enable size ratio
var sizeRatio=6/3;					// maximum aspect ratio, horizontal/vertical proportions

var enableLineUnderPanorama=1;		//Enable an adviser line under panorama
var writeLineUnderQuickTime="<p>This is the QUICKTIME viewer.<BR>Click and drag within the movie to look around<br>or use the control panel directly under the movie.<br><br><strong>[Note that this player does not offer a fullscreen mode]</strong>&nbsp;</p>";
var writeLineUnderDevalVR="<p>This is the DevalVR viewer, our preferred viewer.<BR>Click and drag within the movie to look around<br>or use the slide-out control panel at the bottom left of the movie.</p>";
var writeLineUnderJava="<p>This is the JAVA viewer.<BR>Click and drag within the movie to look around<br>or use the control panel directly under the movie.</p>";
var writeLineUnderFlash="<p>This is the FLASH viewer.<BR>Click and drag within the movie to look around<br>or use the control panel directly under the movie.</p>";


var usePurePlayer=1;						//0: PTViewer is used as Java player  1: PurePlayer is used (write correct names below)
var archivePurePlayer='PurePlayer.jar';		//Copy this file in the same folder
var codePurePlayer='PurePlayer.class';


/////////////////////////////////////////////////////////////////////////////////////////////////

//Internal variables
var isOpera=(navigator.userAgent.indexOf('Opera')!=-1);
var isIE=((navigator.appVersion.indexOf("MSIE") != -1) && !isOpera);
var isDOM=document.getElementById?1:0;
var isNS4=navigator.appName=='Netscape'&&!isDOM?1:0;
var isIE4=isIE&&!isDOM?1:0;
var isWindows=(navigator.platform.indexOf('Win')!=-1);
var isMac=(navigator.platform.indexOf('Mac')!=-1 || navigator.platform.indexOf('PowerPC')!=-1);
var favoriteViewer=getCookie("panorama_viewer"); //global variable to hold the favorite viewerparameters

if (!favoriteViewer||favoriteViewer==null) {
favoriteViewer="DETECT";  //DEVALVR , QT, FLASH, JAVA, SPIV, PANGEAVR, or DETECT


}

var detectableWithVB = false; 
var adviselineunderpano="";
var orgsizepluginx=new Array();
var orgsizepluginy=new Array();
var numberofplugins=0;
var sizepluginx;
var sizepluginy;
var writePluginVR=0;
var writeInstallPluginVR=0;

var auxparameters=new Array();
auxparameters['devalvr']=new Array();
auxparameters['qt']=new Array();
auxparameters['java']=new Array();
auxparameters['flash']=new Array();
auxparameters['spiv']=new Array();


//Use 'viewerparameters' function to define different parameters for each viewer
//Use "devalvr", "qt", "java", "flash", "spiv" or "pangeavr" in first parameter
//for example: viewerparameters("devalvr","resize","0","autoplay","3");

function viewerparameters(viewer)
{
	auxparameters[viewer]=new Array();
	for(var i=1;i<arguments.length;i++) 
	{
		auxparameters[viewer][i-1]=arguments[i];
	}
}



//----------------------Check for minimum version of plugin-----------------------------------------------------------------------
function checkMinVersion(version,min,num)
{
//here version is the version detected
//min is the minimum version required
//num is the number of sections to the version number (eg version 5.0.0.3 would give a num of 4
	var installed=0;
	for (var i = 0; i < num; i++)
	{
		if(parseInt(version[i])>parseInt(min[i])) 
		{
			installed=1;
			break;
		}
		else if(parseInt(version[i])<parseInt(min[i]))
		{
			break;
		}
		else if(parseInt(version[i])==parseInt(min[i]) && i==num-1)
			installed=1;
	}
	return installed;
}

//----------------------------------------------------------------------------------------------



function writecode(medianame)
{

currentmedia=medianame; //set the global variable which holds the value of the current media
var qtfile="./media/"+ medianame +".mov";
var ivp_package="./media/"+ medianame +".ivp";
var sizex="400px"; //width, height and ID of the pano movie
var sizey="300px";
var panoid="pano1";

	
	var priority=new Array();
	var existfile=new Array();
	writePluginVR=0;
	writeInstallPluginVR=0;
	

	
	existfile[1]=(qtfile!=null && qtfile!="");
	existfile[2]=(ivp_package!=null && ivp_package!="");
	

	if((favoriteViewer=="DEVALVR" && (!existfile[1] || !isWindows))
	|| (favoriteViewer=="QT" && !existfile[1])
	|| (favoriteViewer=="JAVA" && !existfile[2]) 
	|| (favoriteViewer=="FLASH" && !existfile[2]))
		favoriteViewer="DETECT";
		

	
	priority[1]=pluginPriority_DevalVR;
	priority[2]=pluginPriority_QuickTime;
	priority[3]=pluginPriority_Flash;
	priority[4]=pluginPriority_Java;

	if(favoriteViewer=="DETECT")
	{
		
		for(order=1;order<=4 && writePluginVR==0;order++)
		{
			for(n=1;n<=4;n++)
			{
				if(priority[n]==order && existfile[n] && IsPluginInstalled(n))
				{
					writePluginVR=n;
					
				
					break;
				}
			}
		}
	}
	else if(favoriteViewer=="DEVALVR" && isWindows)
	{
		if(IsPluginInstalled(1)) writePluginVR=1;
		else writeInstallPluginVR=1;
	
		
			
	}
	else if(favoriteViewer=="QT" && (isWindows || isMac))
	{
		if(IsPluginInstalled(2)) writePluginVR=2;
		else writeInstallPluginVR=2;
		
	}
	else if(favoriteViewer=="FLASH" && (isWindows || isMac))
	{
		if(IsPluginInstalled(3)) writePluginVR=3;
		else writeInstallPluginVR=3;
		
	}
	else if(favoriteViewer=="JAVA") 
	{
		if(IsPluginInstalled(4)) writePluginVR=4;
		else writeInstallPluginVR=4;
	
	}
	
	
	if(writeInstallPluginVR==0 && writePluginVR==0)
	{
		if(isWindows) writeInstallPluginVR=1;	//Install DevalVR if there is not any plugin (fastest installation)
		else if(isMac) writeInstallPluginVR=2;	//Install QT always in Mac
		else writeInstallPluginVR=4;			//Install Java always in Linux
	} 
	
	adviselineunderpano="";
	if(enableLineUnderPanorama)
	{
		if(writePluginVR==1 && writeLineUnderDevalVR!="") adviselineunderpano=writeLineUnderDevalVR;
		else if(writePluginVR==2 && writeLineUnderQuickTime!="") adviselineunderpano=writeLineUnderQuickTime;
		else if(writePluginVR==3 && writeLineUnderFlash!="") adviselineunderpano=writeLineUnderFlash;
		else if(writePluginVR==4 && writeLineUnderJava!="") adviselineunderpano=writeLineUnderJava;
		}

	if(sizex=="") sizex=defaultsizex;
	if(sizey=="") sizey=defaultsizey;


	orgsizepluginx[numberofplugins]=sizex;
	orgsizepluginy[numberofplugins]=sizey;



	idpano=panoid; //make this the variable sent from the html for the individual pano movie, which could be one of several on the page
	if(numberofplugins>0) idpano+=numberofplugins;
	numberofplugins++;
	
	if(writePluginVR==1)
	{
		p2q_EmbedDevalVR(qtfile,sizex,sizey,idpano,'filter','0');
	}
	else if(writePluginVR==2)
	{
		p2q_EmbedQuicktime(qtfile,sizex,sizey,idpano,'scale','tofit','autostart','true','kioskmode','true','controller', 'true');
	}
	else if(writePluginVR==3)
	{
		p2q_EmbedFlash(ivp_package,sizex,sizey,idpano, 'allowFullScreen', 'true');
	}
	else if(writePluginVR==4)
	{
		p2q_EmbedPurePlayer(ivp_package,sizex,sizey,idpano);
		}
	
	else if(writeInstallPluginVR==1)
	{
		optionsstring="";	
		var str='<DIV align=center><div id="panomovie"<p>';
		str+='<BR><BR><BR><BR><BR><BR>DevalVR plugin is required to see this content';
		str+='<BR><BR><A href="http://www.devalvr.com/install/">click here to install (250 KB, it only takes a few seconds)</A>';
		str+='<BR><BR>After installing, please close all browser windows<br>then revisit this page.';
		str+='</p></div></DIV>';
  
		myslidingdivcontent=document.getElementById? document.getElementById("slidingdivcontent") : document.all.slidingdivcontent; 
	ShowViewerSelection("horizontal,reload,detect,devalvr,flash,java,qt"); //set the global str variable to write the code for the option buttons
	myslidingdivcontent.innerHTML=str+optionscode +optionsstring;;
	}
	else
	{
		var pluginname,pluginurl;
		
		if(writeInstallPluginVR==2) 
		{
			pluginname="QuickTime Player"
			pluginurl="http://www.apple.com/quicktime/download/"
		}
		else if(writeInstallPluginVR==3) 
		{
			pluginname="Adobe Flash Player Version " + minFlashVersion + " or higher."
			pluginurl="http://www.adobe.com/go/getflash/"
		}
		else if(writeInstallPluginVR==4) 
		{
			pluginname="Java Software"
			pluginurl="http://java.com/en/download/"
		}
		
		optionsstring="";
		
		var str='<DIV align="center""><div id="panomovie"<p><BR><BR><BR><BR><BR><BR>';
		str+='This content requires '+ pluginname +'.';
		str+='<BR><BR><A href="'+ pluginurl +'">click here to install '+ pluginname +'</A>';
		str+='</p></div></DIV>';
		myslidingdivcontent=document.getElementById? document.getElementById("slidingdivcontent") : document.all.slidingdivcontent; 
	
	
	
	
	
	
	
	ShowViewerSelection("horizontal,reload,detect,devalvr,flash,java,qt"); //set the global str variable to write the code for the option buttons
	myslidingdivcontent.innerHTML=str +optionscode +optionsstring;
	
	}

	}

//------------------------------------------------------------------------------------------------------

function ShowViewerSelection(options)
{
		
	options.toLowerCase();
	var vertical='';
	var combobox=(options.indexOf("combobox")!=-1);
	

	if(options.indexOf("horizontal")==-1)
		vertical='<BR>';
	
viewer=favoriteViewer;


	if(combobox)
	{
		optionsstring+='<SELECT id=comboboxViewer style="WIDTH: 160px" width=160 name=comboboxViewer onchange="favoriteViewerChangedCombo()">';
	}
	if(options.indexOf("detect")!=-1)
	{
		if(combobox) optionsstring+='<OPTION value="DETECT" '+(viewer=="DETECT"?'selected':'')+'> Automatic detection</OPTION>';
		else optionsstring+='<INPUT id=radioViewer value=1 type=radio name=radioViewer OnClick="javascript:changeFavoriteViewer(\'DETECT\');" '+(viewer=="DETECT"?'CHECKED':'')+'>Automatic detection'+vertical;
	}
	if(options.indexOf("devalvr")!=-1)
	{
		if(combobox) optionsstring+='<OPTION value="DEVALVR" '+(viewer=="DEVALVR"?'selected':'')+'> DevalVR</OPTION>';
		else optionsstring+='<INPUT id=radioViewer value=2 type=radio name=radioViewer OnClick="javascript:changeFavoriteViewer(\'DEVALVR\');" '+(viewer=="DEVALVR"?'CHECKED':'')+'>DevalVR '+vertical;
	}
	
	if(options.indexOf("java")!=-1)
	{
		if(combobox) optionsstring+='<OPTION value="JAVA" '+(viewer=="JAVA"?'selected':'')+'> Java</OPTION>';
		else optionsstring+='<INPUT id=radioViewer value=5 type=radio name=radioViewer OnClick="javascript:changeFavoriteViewer(\'JAVA\');" '+(viewer=="JAVA"?'CHECKED':'')+'>Java '+vertical;
	}
	
	if(options.indexOf("flash")!=-1)
	{
		if(combobox) optionsstring+='<OPTION value="FLASH" '+(viewer=="FLASH"?'selected':'')+'> Flash</OPTION>';
		else optionsstring+='<INPUT id=radioViewer value=4 type=radio name=radioViewer OnClick="javascript:changeFavoriteViewer(\'FLASH\');" '+(viewer=="FLASH"?'CHECKED':'')+'>Flash '+vertical;
	}
	
	
	if(options.indexOf("qt")!=-1)
	{
		if(combobox) optionsstring+='<OPTION value="QT" '+(viewer=="QT"?'selected':'')+'> QuickTime</OPTION>';
		else optionsstring+='<INPUT id=radioViewer value=3 type=radio name=radioViewer OnClick="javascript:changeFavoriteViewer(\'QT\');" '+(viewer=="QT"?'CHECKED':'')+'>QuickTime '+vertical;
	}
	
		if(combobox)
	{
		optionsstring+='</SELECT><BR></div>';
	}
	else if(vertical=='') optionsstring+='<BR></div>';
	
}


//-------------------------------------------------------end of ShowViewerSelection function

function favoriteViewerChangedCombo()
{
	ref=getRef("comboboxViewer");
	if(ref) changeFavoriteViewer(ref.value);
}

function changeFavoriteViewer(viewer)
{

	if(favoriteViewer!=viewer)
	{
		setCookie("panorama_viewer",viewer); //this will set the cookie if cookies are enabled
	favoriteViewer=viewer; // This changes the global variable for the viewer which is retained until page is reloaded (or longer with cookie)	
	writecode(currentmedia); //this reloads the current media into the newly selected alternative viewer
	}
}



function IsPluginInstalled(numplugin)
{
	var installed=0;
	
	if(isWindows && isIE &&!isOpera)
	{
		if(detectableWithVB)
		{
			if(numplugin==1)
			{
				installed=detectActiveXControl('DevalVRXCtrl.DevalVRXCtrl.1');
			}
			else if(numplugin==2)
			{
				installed=detectQuickTimeActiveXControl();
			}
			else if(numplugin==3)
			{
				var flashVersion=minFlashVersion.split(".");
				installed =DetectFlashVer(parseInt(flashVersion[0]),parseInt(flashVersion[1]),parseInt(flashVersion[2])); 
			}
			else if(numplugin==4)
			{
				installed=detectActiveXControl('JavaPlugin') && navigator.javaEnabled();
			}
			else if(numplugin==5)
			{
				var strswversion=minShockwaveVersion.split(".");
				var strshockwave="";
				do{
					strshockwave="SWCtl.SWCtl."+strswversion[0]+"."+strswversion[1]+".1";
					strswversion[1]++;
					if(strswversion[1]>9)
					{
						strswversion[1]=0;
						strswversion[0]++;
					}
					installed=detectActiveXControl(strshockwave);
				}while(installed==0 && strswversion[0]<20);
			}
		}
	}
	else
	{
		if(numplugin==1)
		{
			if(navigator.mimeTypes && navigator.mimeTypes["application/x-devalvrx"] && navigator.mimeTypes["application/x-devalvrx"].enabledPlugin)
			{
				var words = navigator.plugins["DevalVR 3D Plugin"].description.split(" ");
				var version = words[3].split(",");
				var min = minDevalVRVersion.split(",");
				installed=checkMinVersion(version,min,4);
							
			}	
		}
		else if(numplugin==2)
		{
			if(navigator.mimeTypes && navigator.mimeTypes["video/quicktime"] && navigator.mimeTypes["video/quicktime"].enabledPlugin)
			{
				for (var i = 0; i < navigator.plugins.length && installed==0; i++)
				{
					if(navigator.plugins[i].name.indexOf("QuickTime Plug-in")!=-1)
					{
						var words = navigator.plugins[i].name.split(" ");
						var version = words[2].split(".");
						var min = minQTVersion.split(".");
						installed=checkMinVersion(version,min,3);
						break;
					}
				}
			}
		}
		else if(numplugin==3)
		{
			var flashVersion=minFlashVersion.split(".");
			installed = DetectFlashVer(parseInt(flashVersion[0]),parseInt(flashVersion[1]),parseInt(flashVersion[2])); 
		}
		else if(numplugin==4)
		{
			if (isOpera || (navigator.mimeTypes && navigator.mimeTypes['application/x-java-applet'] && navigator.mimeTypes["application/x-java-applet"].enabledPlugin))
			{
				installed=navigator.javaEnabled();
			}
		}
		else if(numplugin==5)
		{
			if(navigator.mimeTypes && navigator.mimeTypes["application/x-director"] && navigator.mimeTypes["application/x-director"].enabledPlugin)
			{
				var description=navigator.plugins["Shockwave for Director"].description;
				var pos=description.indexOf("version");
				if (pos!=-1)
				{
					var words=description.substr(pos+8);
					var version = words.split(".");
					var min = minShockwaveVersion.split(".");
					installed=checkMinVersion(version,min,2);
				}
			}
		}
		else if(numplugin==6)
		{
			if(navigator.mimeTypes && navigator.mimeTypes["graphics/pangeavr2"] && navigator.mimeTypes["graphics/pangeavr2"].enabledPlugin)
			{
				installed=1;
			}
		}
	}
	
	return installed;
}







function reloadPage()
{
	if(!isIE) navigator.plugins.refresh(true);
	window.location.reload();
}

function getCookie(nombre)
{
	var dcookie=document.cookie;
	var cname=nombre+"=";
	var longitud=dcookie.length;
	var inicio=0;
	while(inicio<longitud)
	{
		var vbegin=inicio+cname.length;
		if(dcookie.substring(inicio,vbegin)==cname)
		{
			var vend=dcookie.indexOf(";",vbegin);
			if(vend==-1) vend=longitud;
			return unescape(dcookie.substring(vbegin,vend));
		}
		inicio=dcookie.indexOf(" ",inicio)+1;
		if(inicio==0) break;
	}
	return null;
}

function setCookie(name, value, expires)
{
	if(!expires)
	{ 
		expires=new Date();
		expires.setTime(expires.getTime()+(24*3600*1000*365));
	}
	document.cookie=name+"="+escape(value)+"; expires=" + expires.toGMTString()+ "; path=/";
}



function IEGetSwfVer()
{
	flashVer=0;
		
	for(i=25;i>0 && flashVer==0;i--)
	{
		flashVer=VBGetSwfVer(i);
	}
	return flashVer;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer()
{
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
}
 
// If called with no parameters this function returns a floating point value 
// which should be the version of the Flash Player or 0.0 
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
  	if (isIE && isWindows && !isOpera) {
		versionStr = IEGetSwfVer();
	} else {
		versionStr = JSGetSwfVer();		
	}
	if (versionStr == -1 ) 
	{ 
		return false;
	} 
	else if (versionStr != 0) 
	{
		if(isIE && isWindows && !isOpera) {
			tempArray         = versionStr.split(" ");
			tempString        = tempArray[1];
			versionArray      = tempString .split(",");				
		} else {
			versionArray      = versionStr.split(".");
		}
		versionMajor      = versionArray[0];
		versionMinor      = versionArray[1];
		versionRevision   = versionArray[2];
			
		versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
		versionNum        = parseFloat(versionString);
    	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
			return true;
		} else {
			return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
		}
	}
	return (reqVer ? false : 0.0);
}

function p2q_EmbedQuicktime(sFile,sWidth,sHeight,sId) 
{
favoriteViewer=getCookie("panorama_viewer");
	optionsstring="";
	myslidingdivcontent=document.getElementById? document.getElementById("slidingdivcontent") : document.all.slidingdivcontent; 
	myslidingdivcontent.innerHTML="";
var mycontent="";
mycontent=mycontent+'<DIV align=center><div id="panomovie"><object id='+sId+' classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
mycontent=mycontent+' codebase="http://www.apple.com/qtactivex/qtplugin.cab"';
mycontent=mycontent+'  style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '" width="' + sWidth + '" height="' + sHeight + '" >';
mycontent=mycontent+'  <param name="src" value="' + sFile + '">';
	for(i=0;i<auxparameters['qt'].length;i+=2) {
		mycontent=mycontent+'  <param name="' + auxparameters['qt'][i] + '" value="' + auxparameters['qt'][i+1] + '">';
	}
	for(i=4;i<arguments.length;i+=2) 
	{
		var exists=0;
		for(j=0;j<auxparameters['qt'].length;j+=2) {
			if(auxparameters['qt'][j]==arguments[i]) exists=1;
		}
		if(exists==0)
		mycontent=mycontent+'  <param name="' + arguments[i] + '" value="' + arguments[i+1] + '">';
	}
	mycontent=mycontent+'<embed name='+sId+' width="' + sWidth + '" height="' + sHeight + '"';
	mycontent=mycontent+'	pluginspage="http://www.apple.com/quicktime/download/"';
	mycontent=mycontent+'	type="video/quicktime"';
	mycontent=mycontent+'	src="' + sFile + '"';
	for(i=0;i<auxparameters['qt'].length;i+=2) {
		mycontent=mycontent+'  ' + auxparameters['qt'][i] + '="' + auxparameters['qt'][i+1] + '"';
	}
	for(i=4;i<arguments.length;i+=2) 
	{
		var exists=0;
		for(j=0;j<auxparameters['qt'].length;j+=2) {
			if(auxparameters['qt'][j]==arguments[i]) exists=1;
		}
		if(exists==0)
			mycontent=mycontent+'  ' + arguments[i] + '="' + arguments[i+1] + '"';
	}
	mycontent=mycontent+'	/>';
	mycontent=mycontent+'</object>';
	
	
	mycontent=mycontent+'</div></DIV>';
	

	
		mycontent=mycontent+adviselineunderpano;

	
ShowViewerSelection("horizontal,reload,detect,devalvr,flash,java,qt"); //set the global str variable to write the code for the option buttons
	myslidingdivcontent.innerHTML=mycontent+optionscode+optionsstring;
	
	
}

//////////////////////////////////////////////////////////////////////////////////

function p2q_EmbedDevalVR(sFile,sWidth,sHeight,sId) 
{
	favoriteViewer=getCookie("panorama_viewer");
	optionsstring="";
	myslidingdivcontent=document.getElementById? document.getElementById("slidingdivcontent") : document.all.slidingdivcontent; 
	myslidingdivcontent.innerHTML="";
var mycontent="";
mycontent=mycontent+'<DIV align=center><div id = "panomovie"><object id='+sId+' classid="clsid:5D2CF9D0-113A-476B-986F-288B54571614"';
mycontent=mycontent+' codebase="http://www.devalvr.com/instalacion/plugin/devalocx.cab';
mycontent=mycontent+'#version='+minDevalVRVersion+'"';
mycontent=mycontent+'  style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '" width="' + sWidth + '" height="' + sHeight + '" >';
mycontent=mycontent+'  <param name="src" value="' + sFile + '">';
	for(i=0;i<auxparameters['devalvr'].length;i+=2) {
		mycontent=mycontent+'  <param name="' + auxparameters['devalvr'][i] + '" value="' + auxparameters['devalvr'][i+1] + '">';
	}
	for(i=4;i<arguments.length;i+=2) 
	{
		var exists=0;
		for(j=0;j<auxparameters['devalvr'].length;j+=2) {
			if(auxparameters['devalvr'][j]==arguments[i]) exists=1;
		}
		if(exists==0)
			mycontent=mycontent+'  <param name="' + arguments[i] + '" value="' + arguments[i+1] + '">';
	}
	mycontent=mycontent+'<embed name='+sId+' width="' + sWidth + '" height="' + sHeight + '"';
	mycontent=mycontent+'	pluginspage="http://www.devalvr.com/instalacion/plugin/install.html"';
	mycontent=mycontent+'	type="application/x-devalvrx"';
	mycontent=mycontent+'	src="' + sFile + '"';
	for(i=0;i<auxparameters['devalvr'].length;i+=2) {
		mycontent=mycontent+'  ' + auxparameters['devalvr'][i] + '="' + auxparameters['devalvr'][i+1] + '"';
	}
	for(i=4;i<arguments.length;i+=2) 
	{
		var exists=0;
		for(j=0;j<auxparameters['devalvr'].length;j+=2) {
			if(auxparameters['devalvr'][j]==arguments[i]) exists=1;
		}
		if(exists==0)
			mycontent=mycontent+'  ' + arguments[i] + '="' + arguments[i+1] + '"';
	}
	mycontent=mycontent+'	/>';
	mycontent=mycontent+'</object>';
	
	
	mycontent=mycontent+'</div></DIV>';
	
		mycontent=mycontent+adviselineunderpano;

	
	
		
ShowViewerSelection("horizontal,reload,detect,devalvr,flash,java,qt"); //set the global str variable to write the code for the option buttons
	myslidingdivcontent.innerHTML=mycontent+optionscode+optionsstring;
	
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////

function p2q_EmbedFlash(sFile,sWidth,sHeight,sId) 
{
favoriteViewer=getCookie("panorama_viewer");
	optionsstring="";
	myslidingdivcontent=document.getElementById? document.getElementById("slidingdivcontent") : document.all.slidingdivcontent; 
	myslidingdivcontent.innerHTML="";
var mycontent="";
mycontent=mycontent+'<DIV align=center><div id="panomovie"><object id='+sId+' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
mycontent=mycontent+' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab';
mycontent=mycontent+'  style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '" width="' + sWidth + '" height="' + sHeight + '" >';
mycontent=mycontent+'  <param name="src" value="PurePlayer.swf">';
mycontent=mycontent+'   <param name="flashvars" value="panorama=' + sFile + '&quality=' + qualityForFlash + '" />';

	
	for(i=0;i<auxparameters['flash'].length;i+=2) {
		mycontent=mycontent+'  <param name="' + auxparameters['flash'][i] + '" value="' + auxparameters['flash'][i+1] + '">';
	}
	for(i=4;i<arguments.length;i+=2) 
	{
		var exists=0;
		for(j=0;j<auxparameters['flash'].length;j+=2) {
			if(auxparameters['flash'][j]==arguments[i]) exists=1;
		}
		if(exists==0)
			mycontent=mycontent+'  <param name="' + arguments[i] + '" value="' + arguments[i+1] + '">';
	}
	mycontent=mycontent+'<embed name='+sId+' width="' + sWidth + '" height="' + sHeight + '"';
	mycontent=mycontent+'	pluginspage="http://www.macromedia.com/go/getflashplayer"';
	mycontent=mycontent+'	type="application/x-shockwave-flash"';
	mycontent=mycontent+'	src="PurePlayer.swf"';
	mycontent=mycontent+'	flashvars="panorama=' + sFile + '&quality=' + qualityForFlash + '"';
	
	
	for(i=0;i<auxparameters['flash'].length;i+=2) {
		mycontent=mycontent+'  ' + auxparameters['flash'][i] + '="' + auxparameters['flash'][i+1] + '"';
	}
	for(i=4;i<arguments.length;i+=2) 
	{
		var exists=0;
		for(j=0;j<auxparameters['flash'].length;j+=2) {
			if(auxparameters['flash'][j]==arguments[i]) exists=1;
		}
		if(exists==0)
			mycontent=mycontent+'  ' + arguments[i] + '="' + arguments[i+1] + '"';
	}
	mycontent=mycontent+'	/>';
	mycontent=mycontent+'</object>';
	

	
		
	mycontent=mycontent+'</div></DIV>';
	mycontent=mycontent+adviselineunderpano;
	
	
ShowViewerSelection("horizontal,reload,detect,devalvr,flash,java,qt"); 	
myslidingdivcontent.innerHTML=mycontent+optionscode+optionsstring;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////


function p2q_EmbedPurePlayer(sFile,sWidth,sHeight,sId) 
{
	
favoriteViewer=getCookie("panorama_viewer");
	optionsstring="";
	myslidingdivcontent=document.getElementById? document.getElementById("slidingdivcontent") : document.all.slidingdivcontent; 
	myslidingdivcontent.innerHTML="";
var mycontent="";
mycontent=mycontent+'<DIV align=center><div id ="panomovie"><applet name='+sId+' code="' + codePurePlayer + '" archive="' + archivePurePlayer + '"'; 
mycontent=mycontent+'  width="' + sWidth + '" height="' + sHeight + '" >';
mycontent=mycontent+'	<param name="panorama" value="' + sFile + '" >';
mycontent=mycontent+'	<param name="optimizememory" value="true" >';
	for(i=0;i<auxparameters['java'].length;i+=2) {
		mycontent=mycontent+'  <param name="' + auxparameters['java'][i] + '" value="' + auxparameters['java'][i+1] + '">';
	}
	for(i=4;i<arguments.length;i+=2) 
	{
		var exists=0;
		for(j=0;j<auxparameters['java'].length;j+=2) {
			if(auxparameters['java'][j]==arguments[i]) exists=1;
		}
		if(exists==0)
			mycontent=mycontent+'  <param name="' + arguments[i] + '" value="' + arguments[i+1] + '">';
	}
	mycontent=mycontent+'</applet>';
	

	mycontent=mycontent+'</div></DIV>';
	
	
		mycontent=mycontent+adviselineunderpano;

	

ShowViewerSelection("horizontal,reload,detect,devalvr,flash,java,qt"); 

	myslidingdivcontent.innerHTML=mycontent+optionscode+optionsstring;
	
	
		

	

}

//////////////////////////////////////////////////////////////////////



// Here we write out the VBScript block for MSIE Windows
if (isWindows && isIE) 
{
	myslidingdivcontent=document.getElementById? document.getElementById("slidingdivcontent") : document.all.slidingdivcontent; 
	
    document.writeln('<script language="VBscript" type="text/vbscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code \n');
    document.writeln('detectableWithVB = False \n');
    document.writeln('If ScriptEngineMajorVersion >= 2 then \n');
    document.writeln('  detectableWithVB = True \n');
    document.writeln('End If \n');

    document.writeln('\'this next function will detect most plugins \n');
    document.writeln('Function detectActiveXControl(activeXControlName) \n');
    document.writeln('  on error resume next \n');
    document.writeln('  detectActiveXControl = False \n');
    document.writeln('  If detectableWithVB Then \n');
    document.writeln('		set pControl = CreateObject(activeXControlName) \n');
    document.writeln('		If (IsObject(pControl)) then \n');
	document.writeln('			detectActiveXControl = True \n');
    document.writeln('		End If \n');
    document.writeln('  End If \n');
    document.writeln('End Function \n');

    document.writeln('\'and the following function handles QuickTime \n');
    document.writeln('Function detectQuickTimeActiveXControl() \n');
    document.writeln('  on error resume next \n');
    document.writeln('  detectQuickTimeActiveXControl = False \n');
    document.writeln('  If detectableWithVB Then \n');
    document.writeln('    detectQuickTimeActiveXControl = False \n');
    document.writeln('    hasQuickTimeChecker = false \n');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1") \n');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then \n');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(1) Then  \n');
    document.writeln('        detectQuickTimeActiveXControl = True \n');
    document.writeln('      End If \n');
    document.writeln('    End If \n');
    document.writeln('  End If \n');
    document.writeln('End Function \n');

    document.writeln('\'Visual basic helper required to detect Flash Player ActiveX control version information \n');
    document.writeln('Function VBGetSwfVer(i) \n');
    document.writeln('  on error resume next \n');
    document.writeln('  Dim swControl, swVersion \n');
    document.writeln('  swVersion = 0 \n');
    document.writeln('  If detectableWithVB Then \n');
    document.writeln('		set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) \n');
    document.writeln('		If (IsObject(swControl)) then \n');
    document.writeln('			swVersion = swControl.GetVariable("$version") \n');
    document.writeln('		End If \n');
    document.writeln('  End If \n');
    document.writeln('  VBGetSwfVer = swVersion \n');
    document.writeln('End Function \n');

    document.writeln('</scr' + 'ipt>');
}


//////////////// Special functions to create dynamic pages


function getRef(id) 
{
	return (isDOM ? document.getElementById(id) : (isIE4 ? document.all[id] : document.layers[id]));
}
function getStyle(id) 
{
	return (isNS4 ? getRef(id) : getRef(id).style);
}

var panoramadata=new Array();
var panoramanumdata=0;

function insertpanoramadata(name, panofile, title, description, date, jpgimage)
{
	var pano="pano"+panoramanumdata;
	panoramadata[pano]=name;
	panoramadata[name]=new Array();
	panoramadata[name]["movfile"]=panofile;
	panoramadata[name]["title"]=title;
	panoramadata[name]["description"]=description;
	panoramadata[name]["date"]=date;
	panoramadata[name]["jpgimage"]=jpgimage;
	
	panoramanumdata++;
}

///////////////////
