// shared.js script, version 2.1, 08-13-03

// global vars ======================================================
var loc = location.pathname.split('/');
loc.length = loc.length - 1; // removes filename 

var d = location.pathname.replace(/\/[^\/]*/g,'../'); // return one depth too deep, see next line for fix
d = d.substring(0,(d.length-3)); // turns this: ../../ into this ../
// /global vars ======================================================

// img preloads =====================================================
/*
hh = new Image(); hh.src = "/pix/hh.gif"; hh_roll = new Image(); hh_roll.src = "/pix/hh_roll.gif";
*/	
// /img preloads =====================================================

// popup window functions ==========================================
function popFlex(URL,winName,W,H,scroll) {
	if (scroll == "no")
		{scroll = "scrollbars=no";}
	else if (scroll == "yes")
		{scroll = "scrollbars";}
	window.open(URL, winName,"top=0,left=30,width="+W+",height="+H+",resizable=no,"+scroll+"");
	}	
// /popup window functions ==========================================

function showhide_v3() {
	divid = arguments[0];
	classes = arguments[1];
	onstate = arguments[2];
	force = ''; //stops toggling between on and off and forces either on or off whenever clicked 
	if (typeof arguments[3] != 'undefined') {force = arguments[3];}

	var state = 'none';
	if (document.getElementById(divid).className == classes+' none' || 
	document.getElementById(divid).className == 'none') {
		var state = onstate;
		}
	if (force != '') {state = force;}
	document.getElementById(divid).className = classes+' '+state;
	return divid;
	}

function flipper() {
	// call like this: <a id="openclose_1" class="cssroll_open" href="#" onclick="flipper('openclose_1','cssroll_open','cssroll_close');return false;"></a>
	var obj_id = arguments[0];
	var a_class = arguments[1];
	var b_class = arguments[2];
	var force = '';
	if (typeof arguments[3] != 'undefined') {force = arguments[3];} 
	var ab = document.getElementById(obj_id).className;
	if (ab == a_class) {var newclass = b_class;}
	if (ab == b_class) {var newclass = a_class;}
	if (force != '') {var newclass = force;}
	document.getElementById(obj_id).className = newclass;
	}

function load_functions() {
	/*
	NOTE: this function MUST be called from body onload, ex: <body onload="load_functions();">
	this avoids render timing issues in Safari
	*/

	// functions to be run on every page:
	detect_height();
	
	// functions run on a per/page basis. loadfunctions is an array declared in /folder/pagescript.js, each array object represents a function declared either in /shared.js or /folder/pagescript.js
	if (typeof loadfunctions !== 'undefined') {
		for (var n=0; n < loadfunctions.length; n++) {
			eval(loadfunctions[n]+'();');
			}
		}
	}

function detect_height() {
	/*
	NOTE: this function MUST be called from body onload, ex: <body onload="detect_height();">
	this avoids render timing issues in Safari
	*/

	function numberorder(a,b) {return a-b;}
	
	var minheight = 400;

	// page boxes =======================================================
	var pagecontainer = document.getElementById('pagecontainer');
	
	var box0 = document.getElementById('pagebox0');
	var box1 = document.getElementById('pagebox1');
	//var box2 = document.getElementById('pagebox2');
	var box2 = null;
	//var box3 = document.getElementById('pagebox3');
	var box3 = null;
	var boxfull = document.getElementById('pageboxfull');
	
	var boxes = new Array();

	boxes[0] = 0;
	if (box0 != null) {
		box0_H = box0.offsetHeight;//alert(box0_H);
		boxes[0] = box0_H;
		}
	boxes[1] = 0;
	if (box1 != null) {
		box1_H = box1.offsetHeight;//alert(box1_H);
		boxes[1] = box1_H;
		}
	boxes[2] = 0;
	if (box2 != null) {
		box2_H = box2.offsetHeight;//alert(box2_H);
		boxes[2] = box2_H;
		}
	boxes[3] = 0;
	if (box3 != null) {
		box3_H = box3.offsetHeight;//alert(box3_H);
		boxes[3] = box3_H;
		}
	boxes[4] = 0;
	if (boxfull != null) {
		boxfull_H = boxfull.offsetHeight;//alert(boxfull_H);
		boxes[4] = boxfull_H;
		}
	
	// find out who's longest =====
	boxes.sort(numberorder);//alert(boxes);
	var longest = boxes[(boxes.length-1)];//alert(longest);
	if (longest < minheight) {longest = minheight;}
	// /find out who's longest =====
	
	// reset all containers to the longest value =====
	try {// for IE8 which returns box0.style.setExpression as true but throws Not Implemented error
		if (document.all) {// for IE
		 	if (box0 != null) {box0.style.setExpression("height",'"'+longest+'px"');}
 			if (box1 != null) {box1.style.setExpression("height",'"'+longest+'px"');}
			if (box2 != null) {box2.style.setExpression("height",'"'+longest+'px"');}
			if (box3 != null) {box3.style.setExpression("height",'"'+longest+'px"');}
			if (boxfull != null) {boxfull.style.setExpression("height",'"'+longest+'px"');}
 			if (pagecontainer != null) {pagecontainer.style.setExpression("height",'"'+longest+'px"');}
	  	document.recalc(true);
			}
		}
	catch (err) {
		//alert(err);
		}
	// MUST come AFTER the above for IE7
	if (box0 != null) {box0.style.minHeight = longest+'px';}
	if (box1 != null) {box1.style.minHeight = longest+'px';}
	if (box2 != null) {box2.style.minHeight = longest+'px';}
	if (box3 != null) {box3.style.minHeight = longest+'px';}
	if (boxfull != null) {boxfull.style.minHeight = longest+'px';}
	if (pagecontainer != null) {pagecontainer.style.minHeight = longest+'px';}
	// reset all containers to the longest value =====
	// /page boxes =======================================================

	// shell boxes =======================================================
/*
	var shellcontainer = document.getElementById('shellcontainer');
	
	var shellbox0 = document.getElementById('shellbox0');
	var shellbox1 = document.getElementById('shellbox1');
	var shellbox2 = document.getElementById('shellbox2');
*/
	var shellcontainer = null;
	var shellbox0 = null;
	var shellbox1 = null;
	var shellbox2 = null;
	
	var shellboxes = new Array();

	shellboxes[0] = 0;
	if (shellbox0 != null) {
		shellbox0_H = shellbox0.offsetHeight;//alert(shellbox0_H);
		shellboxes[0] = shellbox0_H;
		}
	shellboxes[1] = 0;
	if (shellbox1 != null) {
		shellbox1_H = shellbox1.offsetHeight;//alert(shellbox1_H);
		shellboxes[1] = shellbox1_H;
		}
	shellboxes[2] = 0;
	if (shellbox2 != null) {
		shellbox2_H = shellbox2.offsetHeight;//alert(shellbox2_H);
		shellboxes[2] = shellbox2_H;
		}
	
	// find out who's longest =====
	shellboxes.sort(numberorder);//alert(boxes);
	var longest = shellboxes[(shellboxes.length-1)];//alert(longest);
	if (longest < minheight) {longest = minheight;}
	// /find out who's longest =====
	
	// reset all shellboxes to the longest value =====
	try {// for IE8 which returns box0.style.setExpression as true but throws Not Implemented error
		if (document.all) {// for IE
	 		if (shellbox0 != null) {shellbox0.style.setExpression("height",'"'+longest+'px"');}
 			if (shellbox1 != null) {shellbox1.style.setExpression("height",'"'+longest+'px"');}
 			if (shellbox2 != null) {shellbox2.style.setExpression("height",'"'+longest+'px"');}
 			if (shellcontainer != null) {shellcontainer.style.setExpression("height",'"'+longest+'px"');}
	 	 document.recalc(true);
			}
		}
	catch (err) {
		//alert(err);
		}
	// MUST come AFTER the above for IE7
	if (shellbox0 != null) {shellbox0.style.minHeight = longest+'px';}
	if (shellbox1 != null) {shellbox1.style.minHeight = longest+'px';}
	if (shellbox2 != null) {shellbox2.style.minHeight = longest+'px';}
	if (shellcontainer != null) {shellcontainer.style.minHeight = longest+'px';}
	// reset all shellboxes to the longest value =====
	// /shell boxes =======================================================

	return true;
	}
