/* Eric changed the name of this file from resizable.js to resizabl.js.
Eric also changes some of the style code below.

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)

	Eric commented out colors for text and background to simplify their control.
	See util.js for overview of color control.
*/

	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

	// The following code (note it is not in a function) writes, inline when
	// resizable.js is loaded, into the header, a style tag.
	
	document.write( '<style type="text/css" media="all">' );

	document.write( 		/* AH */
	'html, body {\n' + 
		'height:100%; overflow:hidden; margin:0; padding:0;\n' + 
	'}\n\n' );

//	document.write( 
//	'body {\n' + 
//		'color: ' + getTextColor('css') + ';\n' + 
//		'background-color: ' + getTextBackground('css') + ';\n' + 
//	'}' );

	if (showSlabSlider || showZoomSlider)
	{
		textHeight = jmolDefaultHeight;
		if (_jmol.isIEWin)
			textHeight = jmolDefaultIEHeight;
	}

	var slabSliderHeight = 100 - textHeight - 0.3; // 0.3 is for bottom border
	// without 0.3, slabslider div covers bottom border of text div.

	document.write(
	'.text {\n' + 
		'font-family: ' + getTextFontFace() + ';\n' + 
		'font-size: ' + getTextFontSize() + ';\n' + 
		'font-weight: ' + getTextFontWeight() + ';\n' + 

		'left: ' + ( (getJmolLayout()=="left") ? (JmolWidth+"%") : "0" ) + ';\n' +
		'width:' + (100-JmolWidth) + '%;\n' +
		'top: 0px;\n' +
		'height: ' + textHeight + '%;\n' +
		'position: absolute;\n' +
		'overflow: auto;\n' +
		'margin: 0;\n' + // Margins here appear outside the division border.
		// Margins around text inside the division border are styled with <p>
		// in _cssutil/dvrblite.css.

		'border-left: 1px solid gray;\n' + 
		'border-bottom: 1px solid gray;\n' + 
	'}\n\n' );

	// slabslider class added by Eric, modeled after text class.

	document.write(
	'.slabsliderdivclass {\n' + 
		'font-family: ' + getJmolFontFace() + ';\n' + 
		'font-size: ' + getJmolFontSize() + 'px;\n' + 
		'font-style: ' + getJmolFontStyle() + ';\n' + 
		'font-weight: ' + getJmolFontWeight() + ';\n' + 

		'left: ' + ( (getJmolLayout()=="left") ? (JmolWidth+"%") : "0" ) + ';\n' +
		'width:' + (100-JmolWidth) + '%; \n' +
		'bottom: 0px;\n' +
		'height:' + slabSliderHeight + '%;\n' +
		'position: absolute;\n' +
//		'overflow: auto;\n' +
		'margin: 0;\n' +
		'padding: 0px;\n' +

//		'border-left: 1px solid gray;\n' + 
	'}\n\n' );

	document.write( 
	'.jmol {\n' + 
		'font-family: ' + getJmolFontFace() + ';\n' + 
		'font-size: ' + getJmolFontSize() + 'px;\n' + 
		'font-style: ' + getJmolFontStyle() + ';\n' + 
		'font-weight: ' + getJmolFontWeight() + ';\n' + 

		'float: ' + getJmolLayout() + ';\n' + 
		'height: ' + JmolHeight + '%;\n' + 
		'width: ' + JmolWidth + '%;\n' + 
		'overflow: hidden;\n' +
		'margin: 0;\n' +
		'padding: 0;\n' +

	'}\n\n' );

	document.write( 
	'a.navlink {\n' + 
		'font-family: ' + getNavFontFace() + ';\n' + 
		'font-size: ' + getNavFontSize() + 'px;\n' + 
		'font-style: ' + getNavFontStyle() + ';\n' + 
		'font-weight: ' + getNavFontWeight() + ';\n' + 
//		'color: ' + getNavColor('css') + ';\n' + 
//		'background-color: ' + getNavBackground('css') + ';\n' + 
	'}\n\n' );
	
	
	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);
  }
}
