var homepath="http://www.friendly-places.com/tours/code";
var winwidth=400;
var winheight=240;
var increment=.75;

var ar=0;
var status1=0;
var status2=0;
var TimerID3=null;

var newvr=start;
var pointeron=new Image();
var pointeroff=new Image();

pointeron.src=homepath+"/arrow.gif";
pointeroff.src=homepath+"/noarrow.gif";

var havejava=false;
var havenet=false;
var haveqt=false;
var ismac=false;
var macexplorer=false;
var currentn=start;

if (navigator.plugins && navigator.plugins.length > 0) {
	for (i=0; i < navigator.plugins.length; i++ ) {

		test=navigator.plugins[i].name.toUpperCase();
		testname=test.indexOf("QUICKTIME");
			
		test=navigator.plugins[i].description.toUpperCase();
		testdesc=test.indexOf("QUICKTIME");
			
		if ((testname >= 0) || (testdesc >= 0)) {
			haveqt=true;
			break;
			}
		}
	}
	
if (navigator.userAgent.indexOf("Mac") >= 0) {
	ismac=true;
	}
	
if (document.layers) {
	havenet=true;
	}
	
if ((!(havenet) && (ismac))) {
	macexplorer=true;
	}
	
function loadmovie(n) {
	newvr=n;
	if ((haveqt) || (macexplorer)) {
		if (havenet) {
			gopath=thispath+"/"+scenes[newvr];
			document.viewer.SetURL(gopath);
			}
		else {
			iviewer.document.location=homepath+"/splash.html";
			}
		}
	else {
		if (havenet) {
			document.viewer.newPanoFromList(newvr);
			}
		else {
			iviewer.document.viewer.newPanoFromList(newvr);
			}
		}
	document['BB'+currentn].src=pointeroff.src;
	document['BB'+n].src=pointeron.src;
		
	currentn=n;
	}
	
function loadframe() {
	iviewer.document.writeln ("<html><head><title>movie</title></head><body bgcolor='#ffffff' background='"+homepath+"/splash.gif'>");
	if (haveqt) {
		iviewer.document.writeln ('<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" WIDTH='+winwidth+' HEIGHT='+winheight+'>');
		iviewer.document.writeln ('<PARAM name="qtsrc" value="'+thispath+'/'+scenes[newvr]+'">');
		iviewer.document.writeln ('<PARAM name="src" value="'+homepath+'/uneedqt4.pntg">');
		iviewer.document.writeln ('<PARAM name="type" value="image/x-macpaint">');
		iviewer.document.writeln ('<PARAM name="pluginspage" value="http://www.apple.com/quicktime/download/">');
		iviewer.document.writeln ('<PARAM name="name" value="viewer">');
		iviewer.document.writeln ('<PARAM name="AUTOPLAY" value="false">');
		iviewer.document.writeln ('<PARAM name="CONTROLLER" value="false">');
		iviewer.document.writeln ('<EMBED qtsrc="'+thispath+'/'+scenes[newvr]+'" src="'+homepath+'/uneedqt4.pntg" type="image/x-macpaint" pluginspage="http://www.apple.com/quicktime/download/" name="viewer" HEIGHT='+winheight+' WIDTH='+winwidth+' AUTOPLAY=false CONTROLLER=false></EMBED>');
		iviewer.document.writeln ('</OBJECT>');
		}
	else {
		iviewer.document.writeln ("<APPLET name='viewer' archive=ptviewer.jar codebase='"+homepath+"' code='ptviewer.class' width='"+winwidth+"' height='"+winheight+"' mayscript=true>");
		iviewer.document.writeln ("<PARAM name=wait		value='"+homepath+"/splash.gif'>");
		iviewer.document.writeln ("<PARAM name=file		value='"+thispath+"/"+scenes[newvr]+"'>");
		for (i=0; i<numscenes; i++) {
			iviewer.document.writeln ("<PARAM name=pano"+i+"		value='{file="+thispath+"/"+scenes[i]+"}'>");
			}
		iviewer.document.writeln ("</APPLET>");
		}
	iviewer.document.writeln ("</body></html>");
	}
	
function autospin() {
	if (haveqt) {autorotate();}
	else {ptautorotate();}
	}

function autorotate() {
	ar++;
	if (ar==2) {ar=0;}
	panangle=document.viewer.GetPanAngle();
	if (ar==1) {autorotatestart();}
	else {
		clearTimeout(TimerID2);
		}
	}
	
function autorotatestart() {
	currentpanangle=document.viewer.GetPanAngle();
	distance=(panangle-currentpanangle);
	distance=Math.abs(distance);
	if ((distance<1) || (distance>359)) {
		panangle=panangle-increment;
		if (panangle<0) {panangle=360;}
		document.viewer.SetPanAngle(panangle);
		TimerID2=setTimeout('autorotatestart()',123);
		}
	else {
		clearTimeout(TimerID2);
		ar=0;
		}
	}
	
function ptautorotate() {
	clearTimeout(TimerID3);
	if (havenet) {status1 = document.viewer.pan().toString();}
	else {status1 = iviewer.document.viewer.pan().toString();}
	TimerID3=setTimeout('scanchange()',200);
	}

function scanchange() {
	if (havenet) {status2=document.viewer.pan().toString();}
	else {status2 = iviewer.document.viewer.pan().toString();}
	if (status1 == status2) {
		if (havenet) {document.viewer.startAutoPan( 0.75, 0.0, 1.0 );}
		else {
			iviewer.document.viewer.startAutoPan( 0.75, 0.0, 1.0 );
			}
		}
	else {
		if (havenet) {document.viewer.stopAutoPan();}
		else {iviewer.document.viewer.stopAutoPan();}
		}
	}
	
function instructions() {
	whichinstr=homepath+"/instructions2.html";
	if (haveqt) {
		whichinstr=homepath+"/instructions1.html";
		}
	iwindow=window.open(whichinstr,"iwindow","width="+winwidth+",height="+winheight+",toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=0");
	}

function runcheck() {
	if (!(haveqt)) {
		if (!(havejava)) {
			yn=confirm ('Neither Quicktime nor the Java Virtual Machine is apparently installed on your system. One or the other is required to view this tour. With Quicktime you will have a better viewing experience and is a smaller download. It is recommended that you click [Okay] to download it now, or click [Cancel] to exit and attempt to view the VR anyway.');
			if (yn) {document.location.href="http://www.apple.com/quicktime";}
			}
		else {
			yn=confirm ('Quicktime is not detected on your system! You can click [Okay] to download Quicktime now or click [Cancel] to use the applet-based PTViewer and simply view the tour now.');
			if (yn) {document.location.href="http://www.apple.com/quicktime";}
			}
		}
	}


