// session constants

var DOC_WIDTH = 790;
var DOC_HEIGHT = 400;

var MIN_TEXT_WIDTH = 20;
var MAX_TEXT_WIDTH = 700;

var MIN_MODEL_WIDTH = 100;
var MAX_MODEL_WIDTH = 5000;

var MIN_APPLET_WIDTH = 50;
var MAX_APPLET_WIDTH = 5000;



// page variables

var text_h = 400;
var text_w = 200;

var model_h = 400;
var model_w = 400;

var applet_h = 360;
var applet_w = 390;



// functions

function initSessionConstants() {

	if (typeof window.innerWidth != "undefined") {
		DOC_WIDTH = window.innerWidth;
		DOC_HEIGHT = window.innerHeight;
	}

	else if (typeof document.documentElement.offsetWidth != "undefined") {
		DOC_WIDTH = document.documentElement.offsetWidth; 
		DOC_HEIGHT = document.documentElement.offsetHeight; 
	}

	else {
		DOC_WIDTH = document.body.offsetWidth; 
		DOC_HEIGHT = document.body.offsetHeight; 
	}
	
}


function initPageVariables( pct_text, model_rows, model_cols ) {

	text_h = DOC_HEIGHT - 20;
	text_w = pct_text * DOC_WIDTH;

	if ( text_w > MAX_TEXT_WIDTH ) 
		text_w = MAX_TEXT_WIDTH;
		
	if ( text_w < MIN_TEXT_WIDTH ) 
		text_w = MIN_TEXT_WIDTH;
	
	
	model_h = text_h;
	model_w = DOC_WIDTH - text_w - 45;

	if ( model_w > MAX_MODEL_WIDTH ) 
		model_w = MAX_MODEL_WIDTH;
		
	if ( model_w < MIN_MODEL_WIDTH ) 
		model_w = MIN_MODEL_WIDTH;
		

	applet_h = ( model_h / model_rows ) - 70; 
	applet_w = ( model_w / model_cols ) - 24;

	if ( applet_w > MAX_APPLET_WIDTH ) 
		applet_w = MAX_APPLET_WIDTH;
		
	if ( applet_w < MIN_APPLET_WIDTH ) 
		applet_w = MIN_APPLET_WIDTH;
			
}


function getTextHeight() {
	return text_h;
}


function getTextWidth() {
	return text_w;
}


function getModelHeight() {
	return model_h;
}


function getModelWidth() {
	return model_w;
}


function getAppletHeight() {
	return applet_h;
}


function getAppletWidth() {
	return applet_w;
}




function getResetSpt() {

	var spt = 
	'restrict none;select all;color white;' + 
	'dots off;monitors off;hbonds off;ssbonds off;' + 
	'labels off;measurements off;set labeloffset 0 0;' + 
	'set display normal;set bondmode and;';
	
	return spt;

}


function getReorientSpt() {

	var spt = 'reset;';
	return spt;
	
}


function getDisplaySpt() {

	var spt = 
	'set specular 5;' + 
	'set ambient 35;' + 
	'set diffuse 50;' + 
	'background white;' + 
	'font labels 12 courier bold;' + 
	'color labels black;';

	return spt;
	
}


function getDefaultSpt() {

	var spt = 
	'select protein;color chain;backbone 0.5;' + 
	'select nucleic;color cpk;wireframe 0.4;' + 
	'select (a and not backbone);color blue;' + 
	'select (c and not backbone);color red;' + 
	'select (t and not backbone);color yellow;' + 
	'select (g and not backbone);color green;' + 
	'select (u and not backbone);color brown;' + 
	'select (hetero and not solvent);color cpk;wireframe 0.4;spacefill 40%;' + 
	'select solvent;color bluetint;wireframe 0.4;spacefill 40%;';

	return spt;
	
}


function _setAutoHeight() {

	text_h = DOC_HEIGHT - height_offset - 20;
	jmol_h = text_h;
	
}



function sendScriptToJmol( target, script ) {

	//alert( target );
	//alert( script );
	
	//document.applets[target].script( script );
	eval( 'document.' + target  + '.script( "' + script + '" )' );

}



