/* AH: this code was part of all pages; extracted here and modified
	to avoid some of the dvrblite.js and dvrblite.css  and make it 
	possible to use automatically resizable panels.
	
	Some CSS parameters that were set in dvrblite.js, dvrblite.css and the page itself 
	are here ovewritten.
	I am not changing other styling set in dvrblite.css (although they might be integrated here)
*/

	var JmolWidth = 60	//meaning percent of available window; substitutes the functionality of jmol_w in dvrblite.js
	var JmolHeight = 100   //percent; not sure if it can be changed effectively
	var TextHeight = 100
	
	document.write( '<style type="text/css" media="all">' );

	document.write( 		/* AH */
	'html, body {' + 
		'height:100%; overflow:hidden; margin:0; padding:0;' + 
	'}' );

	document.write( 
	'body {' + 
		'color: ' + getTextColor('css') + ';' + 
		'background-color: ' + getTextBackground('css') + ';' + 
	'}' );

	document.write(
	'.text {' + 
		'font-family: ' + getTextFontFace() + ';' + 
		'font-size: ' + getTextFontSize() + ';' + 
		'font-style: ' + getTextFontStyle() + ';' + 
		'font-weight: ' + getTextFontWeight() + ';' + 
		'color: ' + getTextColor('css') + ';' + 
			/* // changed by AH:
		'height: ' + getTextHeight() + 'px;' + 
		'width: ' + getTextWidth() + 'px;' + 
		'float: ' + getTextLayout() + ';' + 
		'overflow: auto;' + 
			*/
		'left: ' + ( (getJmolLayout()=="left") ? (JmolWidth+"%") : "0" ) + '; width:' + (100-JmolWidth) + '%; top:0px; height:' + TextHeight + '%;' +
		'position: absolute;' +
		'overflow: auto;' +
		'margin: 0;' +
		'padding: 0;' +
				/* suppresses parameters set in dvrblite.css (automatic percent sizing) */
			// end AH 
		'background-color: ' + getTextBackground('css') + ';' + 
		'border-left: 1px solid gray;' + 
		//border, link colors added by Frieda
	'}' );

	document.write( 
	'.jmol {' + 
		'font-family: ' + getJmolFontFace() + ';' + 
		'font-size: ' + getJmolFontSize() + 'px;' + 
		'font-style: ' + getJmolFontStyle() + ';' + 
		'font-weight: ' + getJmolFontWeight() + ';' + 
		'color: ' + getJmolColor('css') + ';' + 
			/* // AH:
		'height: ' + getJmolHeight() + 'px;' + 
		'width: ' + getJmolWidth() + 'px;' + 
			*/
		'float: ' + getJmolLayout() + ';' + 
		'height: ' + JmolHeight + '%;' + 
		'width: ' + JmolWidth + '%;' + 
		'overflow: hidden;' +
		'margin: 0;' +
		'padding: 0;' +
				/* suppresses parameters set in dvrblite.css (automatic percent sizing) */		
			// end AH 
		'background-color: ' + getJmolBackground('css') + ';' + 
	'}' );

	document.write( 
	'a.navlink {' + 
		'font-family: ' + getNavFontFace() + ';' + 
		'font-size: ' + getNavFontSize() + 'px;' + 
		'font-style: ' + getNavFontStyle() + ';' + 
		'font-weight: ' + getNavFontWeight() + ';' + 
		'color: ' + getNavColor('css') + ';' + 
		'background-color: ' + getNavBackground('css') + ';' + 
	'}' );
	
	
	document.write( '<\/style>' );



	/* AH: patches functions present in (old) Jmol.js
		so that percent sizes are accepted for the applet.
		These patches should be unnecessary when using a newer version of Jmol
		that has already included them.
	*/
	
function _jmolGetAppletSize(size) {		// AH copied from 11.1.22 or so
  var width, height;
  var type = typeof size;
  if (type == "object" && size != null) {
    width = size[0]; height = size[1];
  } else {
    width = height = size;
  }
  if (typeof width == "number") {
        width = (width >= 25 && width <= 2000 ? width + "px"
	 : width < 1 && width > 0 ? (width * 100)+"%":"300px")
  }
  if (typeof height == "number") {
        height = (height >= 25 && height <= 2000 ? height + "px"
	 : height < 1 && height > 0 ? (height * 100)+"%":"300px")
  }
  return [width, height];
}

function _jmolApplet(size, inlineModel, script, nameSuffix) {
  with (_jmol) {
    if (! nameSuffix)
      nameSuffix = appletCount;
    appletSuffixes.push(nameSuffix);
    ++appletCount;
    if (! script)
      script = "select *";
    var sz = _jmolGetAppletSize(size);
    var widthAndHeight = " width='" + sz[0] + "px' height='" + sz[1] + "px' ";

    var tHeader, tFooter;

    if (useIEObject || useHtml4Object) {
      params.name = 'jmolApplet' + nameSuffix;
      params.archive = archivePath;
      params.mayscript = 'true';
      params.codebase = codebase;
    }
    if (useIEObject) { // use MSFT IE6 object tag with .cab file reference
      winCodebase = (windowsCabUrl ? " codebase='" + windowsCabUrl + "'\n" : "");
      tHeader = 
        "<object name='jmolApplet" + nameSuffix +
        "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
	" classid='" + windowsClassId + "'\n" + winCodebase + widthAndHeight + ">\n";
        params.code = 'JmolApplet';
      tFooter = "</object>";
    } else if (useHtml4Object) { // use HTML4 object tag
      tHeader = 
        "<object name='jmolApplet" + nameSuffix +
        "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
	" classid='java:JmolApplet'\n" +
        " type='application/x-java-applet'\n" +
        widthAndHeight + ">\n";
      tFooter = "</object>";
    } else { // use applet tag
      tHeader = 
        "<applet name='jmolApplet" + nameSuffix +
        "' id='jmolApplet" + nameSuffix +
        "' " + appletCssText +
        " code='JmolApplet'" +
        " archive='" + archivePath + "' codebase='" + codebase + "'\n" +
        " width='" + sz[0] + "' height='" + sz[1] +
        "' mayscript='true'>\n";
      tFooter = "</applet>";
    }

    var visitJava;
    if (isIEWin || useHtml4Object) {
			// AH
		var szX = "width:" + sz[0]
		if ( szX.indexOf("%")==-1 ) szX+="px" 
		var szY = "height:" + sz[1]
		if ( szY.indexOf("%")==-1 ) szY+="px" 
      visitJava =
        "<p style='background-color:yellow;" +
		szX + ";" + szY + ";" +
			// end AH
        // why doesn't this vertical-align work?
	"text-align:center;vertical-align:middle;'>\n" +
        "You do not have Java applets<br />\n" +
        "enabled in your web browser.<br />\n" +
        "Install the Java Runtime Environment<br />\n" +
        "from <a href='http://www.java.com'>www.java.com</a><br />" +
        "and/or enable Java applets in<br />\n" +
        "your web browser preferences." +
        "</p>";
    } else {
      visitJava =
        "<table bgcolor='yellow' width='" + sz[0] + "'><tr>" +
        "<td align='center' valign='middle' height='" + sz[1] + "'>\n" +
        "You do not have the<br />\n" +
        "Java Runtime Environment<br />\n" +
        "installed for applet support.<br />\n" +
        "Visit <a href='http://www.java.com'>www.java.com</a>" +
        "</td></tr></table>";
    }
    params.loadInline = (inlineModel ? inlineModel : "");
    params.script = (script ? _jmolSterilizeScript(script) : "");
    var t = tHeader + _jmolParams() + visitJava + tFooter;
    jmolSetTarget(nameSuffix);
    ready["jmolApplet" + nameSuffix] = false;
    if (_jmol.debugAlert)
      alert(t);
    return _jmolDocumentWrite(t);
  }
}
