// 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";}
	var popwin = window.open(URL, winName,"top=0,left=30,width="+W+",height="+H+",resizable=no,"+scroll+"");
	popwin.focus();
	}	
// /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 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
	*/
	
	var pagecontainer = document.getElementById('pagecontainer');
	
	var box0 = document.getElementById('pagebox0');
	var box0bot = document.getElementById('pagebox0bottom');
	var box1 = document.getElementById('pagebox1');
	var box1bot = document.getElementById('pagebox1bottom');
	var box2 = document.getElementById('pagebox2');
	var box2bot = document.getElementById('pagebox2bottom');
	var box3 = document.getElementById('pagebox3');
	var box3bot = document.getElementById('pagebox3bottom');
	var boxfull = document.getElementById('pageboxfull');
	var boxfullbot = document.getElementById('pageboxfullbottom');
	
	if (boxfull && !box0 && !box1 && !box2 && !box3) {return;}
	
	var boxes = new Array();

	boxes[0] = 0;
	if (box0bot != null) {
		box0_H = box0bot.offsetTop;//alert(box0_H);
		boxes[0] = box0_H;
		}
	boxes[1] = 0;
	if (box1bot != null) {
		box1_H = box1bot.offsetTop;//alert(box1_H);
		boxes[1] = parseInt(box1_H)+105;
		}
	boxes[2] = 0;
	if (box2bot != null) {
		box2_H = box2bot.offsetTop;//alert(box2_H);
		boxes[2] = box2_H;
		}
	boxes[3] = 0;
	if (box3bot != null) {
		box3_H = box3bot.offsetTop;//alert(box3_H);
		boxes[3] = box3_H;
		}
	boxes[4] = 0;
	if (boxfullbot != null) {
		boxfull_H = boxfullbot.offsetTop;//alert(boxfull_H);
		boxes[4] = boxfull_H;
		}
	
	// find out who's longest =====
	function numberorder(a,b) {return a-b;}
	boxes.sort(numberorder);//alert(boxes);
	var longest = boxes[(boxes.length-1)];//alert(longest);
	if (longest < 400) {longest = 400;}
	// /find out who's longest =====
	
	// reset all containers to the longest value =====
	if (box0bot != null) {box0.style.minHeight = longest+'px';}
	if (box1bot != null) {box1.style.minHeight = longest+'px';}
	if (box2bot != null) {box2.style.minHeight = longest+'px';}
	if (box3bot != null) {box3.style.minHeight = longest+'px';}
	if (boxfullbot != null) {boxfull.style.minHeight = longest+'px';}
	pagecontainer.style.minHeight = longest+'px';
	if (document.all) {
 		if (box0bot != null) {box0.style.setExpression("height",'"'+longest+'px"');}
 		if (box1bot != null) {box1.style.setExpression("height",'"'+longest+'px"');}
 		if (box2bot != null) {box2.style.setExpression("height",'"'+longest+'px"');}
 		if (box3bot != null) {box3.style.setExpression("height",'"'+longest+'px"');}
 		if (boxfullbot != null) {boxfull.style.setExpression("height",'"'+longest+'px"');}
 		pagecontainer.style.setExpression("height",'"'+longest+'px"');
	  document.recalc(true);
		}
	// reset all containers to the longest value =====
	
	return true;
	}
