// debug thru #1

//var isIE = (navigator.appName.indexOf("Internet Explorer") != -1);
//var isGecko = (navigator.userAgent.indexOf("Gecko") != -1);
//alert("morfdoc.js #1: isIE " + isIE + ", isGecko " + isGecko);

var bg_color = "black";
var stereo = false;
var animating = true;
var centering = false;
var child_spt = "";

var iframetarg;

var animate_loop_spt =
"restrict none\n\
restrict model=1\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=1\n\
wireframe 0.3\n\
select model=1 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=1 and hetero\n\
spacefill\n\
\n\
delay 1.0\n\
\n\
restrict none\n\
restrict model=2\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=2\n\
wireframe 0.3\n\
select model=2 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=2 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=3\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=3\n\
wireframe 0.3\n\
select model=3 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=3 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=4\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=4\n\
wireframe 0.3\n\
select model=4 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=4 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=5\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=5\n\
wireframe 0.3\n\
select model=5 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=5 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=6\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=6\n\
wireframe 0.3\n\
select model=6 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=6 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=7\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=7\n\
wireframe 0.3\n\
select model=7 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=7 and hetero\n\
spacefill\n\
\n\
delay 0.1\n\
\n\
restrict none\n\
restrict model=8\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=8\n\
wireframe 0.3\n\
select model=8 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=8 and hetero\n\
spacefill\n\
\n\
delay 0.2\n\
\n\
restrict none\n\
restrict model=9\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=9\n\
wireframe 0.3\n\
select model=9 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=9 and hetero\n\
spacefill\n\
\n\
delay 0.2\n\
\n\
restrict none\n\
restrict model=10\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=10\n\
wireframe 0.3\n\
select model=10 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=10 and hetero\n\
spacefill\n\
\n\
delay 1.1\n\
\n\
restrict none\n\
restrict model=9\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=9\n\
wireframe 0.3\n\
select model=9 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=9 and hetero\n\
spacefill\n\
\n\
delay 0.2\n\
\n\
restrict none\n\
restrict model=8\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=8\n\
wireframe 0.3\n\
select model=8 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=8 and hetero\n\
spacefill\n\
\n\
delay 0.2\n\
\n\
restrict none\n\
restrict model=7\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=7\n\
wireframe 0.3\n\
select model=7 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=7 and hetero\n\
spacefill\n\
\n\
delay 0.1\n\
\n\
restrict none\n\
restrict model=6\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=6\n\
wireframe 0.3\n\
select model=6 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=6 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=5\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=5\n\
wireframe 0.3\n\
select model=5 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=5 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=4\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=4\n\
wireframe 0.3\n\
select model=4 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=4 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=3\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=3\n\
wireframe 0.3\n\
select model=3 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=3 and hetero\n\
spacefill\n\
\n\
delay 0.05\n\
\n\
restrict none\n\
restrict model=2\n\
backbone 0.2\n\
select (74,76,78,80,85) and model=2\n\
wireframe 0.3\n\
select model=2 and (thr80.o,asp74.od1,asp78.o,asp78.od2,asn76.od1,glu85.oe?)\n\
spacefill 0.9\n\
select model=2 and hetero\n\
spacefill\n\
\n\
refresh\n\
loop 0.02\n\
";


function init()
{
	if (isIE || isGecko)
	iframetarg=document.getElementsByName("invisible")[0];

	if (isIE)
		iframetarg = iframetarg.contentWindow.document;
	if (isGecko)
		iframetarg = iframetarg.contentDocument;
	if (isNetscape4)
		iframetarg = document.invisible;
	
	do_child_spt3();
}

function do_child_spt(s)
{
	forkspt('interrupt');

	child_spt = s;
	setTimeout('do_child_spt2()', 200);
}

function do_child_spt2()
{
	var ms = 200;
	if (child_spt.indexOf("move") != -1)
		ms = 1000;
	forkspt(child_spt);
	setTimeout('do_child_spt3()', ms);
}

function do_child_spt3()
{
//	alert("morfdoc.js #3 do_child_spt3()\n" +
//		"top.animating " + top.animating + "\n" +
//		"top.centering " + top.centering + "\n");

	if (!top.animating || top.centering)
		return;
	var s3 = animate_loop_spt;
	s3 = "javascript animating=true\n" + s3;

	forkspt(s3);
}

function forkspt(s)
{
//	alert("morfdoc.js #2 forkspt()\n" + s);
	if (top.isIE || top.isGecko)
		IMBIF(s);
	else
		document.auto_form.chime_nmr_autodemo.executeScript(s);	
}

function toggle_bg()
{
	if (bg_color == "white")
		bg_color = "black";
	else
		bg_color = "white";
	do_child_spt("background " + bg_color);
}

function toggle_stereo()
{
	var cmd;
	if (stereo)
	{
		cmd = "stereo off";
		stereo = false;
	}
	else
	{
		cmd = "stereo 5";
		stereo = true;		
	}
	do_child_spt(cmd);
}

function no_input()
{
	alert('The model number reporting slot\ndoes not accept input.');
}

function do_center()
{
	alert("Click on atom to center.");
 centering = true;
	do_child_spt("set picking center");
}

// can't get ident report to stay in status line w/ pickcallback.

function do_pick(p1, p2)
{
	if (p2.indexOf("Rotating") == -1)
	{
		alert(p2);
		return;
	}
	var ss = "set picking identify;move 0 0 0 +1 0 0 0 0 0.5 30;";
	centering = false;
	do_child_spt(ss);
}

// IMBIF() sends a script to IE (not used for Netscape)
function IMBIF(s) // Immediate Mode Button in the Invisible Frame
{
//	if (!confirm("morfdoc.js #1: IMBIF\n" + s))
//		return;

	with (iframetarg)
	{
		open();

		var ib = "<html><body>\n";
		ib += "<embed type=\"application/x-spt\" hidden=true\n";
		ib += " width=10 height=10 button=push\n";
		ib += " target=\"chime_nmr_autodemo\"\n";
		ib += " script='" + s + "'\nimmediate=1>\n";
		ib += "</body></html>";
		writeln(ib);

		close();
	}
	return true;
}

// ButtonCallback is called twice for depressing, twice for releasing.
// p2 is false before the script executes, and true afterwards.
function button_pressed(p1, p2) // p3 is undefined
{
	if (!p2) return;
	animating = (!animating);
}

