//********************************************************************
//*	File:	layer.js
//*
//* Desc:		This file contains javascript routines for
//*				creating, managing, and showing/hiding
//*				layers while encapsulating browser differences.	
//*
//********************************************************************

var layerList = new Array();

// Global variables used by entire site.
var dirUp = 0;
var dirDown = 1;

var scrollStep = 20;
var scrollSpeed = 10;

var whatsNewStep = 1;
var whatsNewSpeed= 50;

var visTime = 500;
var isAnimated = 1;

//********************************************************************
//*	Routine:	errRecovery()
//*
//* Desc:		This procedure is responsible for Error Recovery.
//*				Initially, all it does is redirect to a generic
//*				error page (HTML).
//*
//********************************************************************
function errRecovery() {
	// Simply redirect to the generic error page.
	// This routine should be developed, adding 
	// error numbers and numerous recovery options.
	this.document.location.replace('general_error.htm');
}


//********************************************************************
//*	Routine:	createLayer()
//*
//* Desc:		This procedure creates a new layer based on the
//*				parameters passed in.
//*
//********************************************************************
function createLayer(doc, name, left, top, width, height, visible, content) {

  var z = layerList.length;
  var layer;

  layerList[z] = name;

  if (doc.layers) {			// Netscape
    doc.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height +  ' clip="0,0,' + width + ',' + height + '" visibility=' + (visible ? '"show"' : '"hide"') + ' z-index=' + z + '>');
    doc.writeln(content);
    doc.writeln('</layer>');
    layer = getLayer(doc, name);
    layer.width = width;
    layer.height = height;
  } else if (doc.all) {		// Microsoft IE
    doc.writeln('<div id="' + name + '" style="background:transparent; position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px; clip:rect(0px,' + width + 'px,' + height + 'px,0px); visibility:' + (visible ? 'visible;' : 'hidden;') + ' z-index=' + z + '">');
    doc.writeln(content);
    doc.writeln('</div>');
  } else {
	errRecovery();
  }
}

//********************************************************************
//*	Routine:	createLayer()
//*
//* Desc:		This procedure creates a new layer based on the
//*				parameters passed in.
//*
//********************************************************************
function createLayerZ(doc, name, left, top, width, height, visible, content, z) {
  doc.writeln('<div id="' + name + '" style="background:transparent; position:absolute; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px; visibility:' + (visible ? 'visible;' : 'hidden;') + ' z-index=' + z + '">');
  doc.writeln(content);
  doc.writeln('</div>');
}
//********************************************************************
//*	Routine:	createLayerClip()
//*
//* Desc:		This procedure creates a new layer based on the
//*				parameters passed in.
//*
//********************************************************************
function createLayerClip(doc, name, left, top, width, height, visible, content) {

  var z = layerList.length;
  var layer;

  layerList[z] = name;

  if (doc.layers) {			// Netscape
    doc.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height +  ' clip="' + left + ',' + top + ',' + width + ',' + height + '" visibility=' + (visible ? '"show"' : '"hide"') + ' z-index=' + z + '>');
    doc.writeln(content);
    doc.writeln('</layer>');
    layer = getLayer(doc, name);
    layer.width = width;
    layer.height = height;
  } else if (doc.all) {		// Microsoft IE
    doc.writeln('<div id="' + name + '" style="position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px; clip:rect(' + top + 'px,' + width + 'px,' + height + 'px,' + left + 'px); visibility:' + (visible ? 'visible;' : 'hidden;') + ' z-index=' + z + '">');
    doc.writeln(content);
    doc.writeln('</div>');
  } else {
	errRecovery();
  }
}

//********************************************************************
//*	Routine:	hideLayer()
//*
//* Desc:		This procedure hides the given layer.
//*
//********************************************************************
function hideLayer(doc, name) {

  var layer = getLayer(doc, name);

  if (doc.layers)
    layer.visibility = "hide";
  else if (doc.all)
    layer.visibility = "hidden";
  else if (doc.getElementById)
  	layer.visibility = "hidden";
  else
    errRecovery();
}

//********************************************************************
//*	Routine:	showLayer()
//*
//* Desc:		This procedure makes visible the given layer.
//*
//********************************************************************
function showLayer(doc, name) {

  var layer = getLayer(doc, name);

  if (doc.layers)
    layer.visibility = "show";
  else if (doc.all)
    layer.visibility = "visible";
  else if (doc.getElementById)
  	layer.visibility = "visible";
  else
    errRecovery();
}

//********************************************************************
//*	Routine:	scrollMenu()
//*
//* Desc:		This procedure scrolls a given layer in the
//*				given direction.
//*
//********************************************************************
function scrollMenu(doc, doc_str, name, dir, cur_height) {

	// Call moveLayer:
	moveLayer(doc, name, scrollStep, dir);

	if (dir == dirDown) {
		cur_height += scrollStep;
	} else {
		cur_height -= scrollStep;
	}
	
	if ((cur_height <= arMenuDims[name]['height'])&&(cur_height >=0))
		setTimeout("scrollMenu(" + doc_str + ", '" + doc_str + "', '" + name + "', "  + dir + ", " + cur_height + ")", scrollSpeed);
	else {
		// Move last bit if neccessary.
		//if (dir == dirUp)
		//	moveLayer(doc, name, cur_height, dir);
		//else
		//	moveLayer(doc, name, arMenuDims[name]['height'] - cur_height, dir);

		if (cur_height < 0)
			hideLayer(doc, name);
	}
}

//********************************************************************
//*	Routine:	hideLayerAni()
//*
//* Desc:		This procedure hides the named layer, but
//*				animates the process.
//*
//********************************************************************
function hideLayerAni(doc, doc_str, name) {

	var lh = getLayer(doc, name);

	// Now call recursive routine:
	scrollMenu(doc, doc_str, name, dirUp, arMenuDims[name]['height']);

}

//********************************************************************
//*	Routine:	showLayerAni()
//*
//* Desc:		This procedure displays the named layer, but
//*				animates the process.
//*
//********************************************************************
function showLayerAni(doc, doc_str, name) {

	var lh = getLayer(doc, name);

	// Always make sure layer starts in proper position.
	lh.top = arMenuDims[name]['top'] - arMenuDims[name]['height'];

	// Show the layer.
	if (doc.layers) {
		lh.visibility = "show";
	} else if (doc.all) {
		lh.visibility = "visible";
	} else {
		errRecovery();
	}
		
	// Now call recursive routine:
	scrollMenu(doc, doc_str, name, dirDown, scrollStep);
	
}




//********************************************************************
//*	Routine:	getLayer()
//*
//* Desc:		This procedure retrieves the layer handle
//*				based on the document and layer name as
//*				parameters.
//*
//********************************************************************
function getLayer(doc, name) {

  	// Returns a handle to the named layer.
  	if (doc.layers) {
    	return(doc.layers[name]);
  	} else if (doc.getElementById) {
  		return(doc.getElementById(name).style);
  	} else if (doc.all) {
    	layer = eval('doc.all.' + name + '.style');
    	return(layer);
  	} else {
    	return(null);
	}
}

//********************************************************************
//*	Routine:	getLayerVis()
//*
//* Desc:		This procedure returns 0 or 1 representing 
//*				whether or not the given layer is currently
//*				visible.
//*
//********************************************************************
function getLayerVis(doc, name) {
	var isVisible = null;
	
	if (doc.layers){
		if (getLayer(doc, name).visibility == "show") {
			isVisible = 1;
		} else {
			isVisible = 0;
		}
	} else if (doc.all) {
		if (getLayer(doc, name).visibility == "visible") {
			isVisible = 1;
		} else {
			isVisible = 0;
		}
	} else {
		isVisible = null;
	}
	
	return(isVisible);
	
}

//********************************************************************
//*	Routine:	moveLayer()
//*
//* Desc:		This procedure moves the given layer in the given
//*				direction, the given amount of pixels.
//*
//********************************************************************
//function moveLayer(doc, name, amt, dir, useClip) {
function moveLayer(doc, name, amt, dir) {

	var lh = getLayer(doc, name);
	
	if (doc.layers) {
		// move the layer lh by amt in the dir direction.
		if (dir == 0) {
			lh.top -= amt;
			
		//	if (useClip)
		//		lh.clip.top -= amt;
				
		} else {
			lh.top += amt;

		//	if (useClip)
		//		lh.clip.top += amt;

		}
	} else if (doc.all) {
		if (dir == 0) {
			lh.top = eval(lh.top.substring(0, lh.top.indexOf('px'))) - amt;

		//	if (useClip)
				//clip:rect(0px,' + width + 'px,' + height + 'px,0px)

		} else {
			lh.top = eval(lh.top.substring(0, lh.top.indexOf('px'))) + amt;

			//if (useClip)
				//clip:rect(0px,' + width + 'px,' + height + 'px,0px)

		}
	} else {
		errRecovery();
	}

}

//********************************************************************
//*	Routine:	moveLayerABS()
//*
//* Desc:		This procedure moves the given layer to the
//* 			absolute position as defined by the parameters
//*				passed in.
//*
//********************************************************************
function moveLayerABS(doc, name, left, top) {

	var lh = getLayer(doc, name);
	
	if (doc.layers) {
		lh.left = left;
		lh.top = top;
	} else if (doc.all) {
		lh.left = left + 'px';
		lh.top = top + 'px';
	} else if (doc.getElementById) {
		lh.left = left + 'px';
		lh.top = top + 'px';
	} else {
		errRecovery();
	}
}


//********************************************************************
//*	Routine:	clearNav()
//*
//* Desc:		This procedure clears out the submenus that may
//*				be visible.	
//*
//********************************************************************
function clearNav(doc, doc_str, animate) {
	var i;
	
	//
	// This is a cluge because I can't control a variable (timerID)
	// in another window!
	//
	if (doc.HdnForm.hdnHideMenu.value == 1) {
		for (i=1; i <=num_sub_layers;i++) {
			if (animate)
				hideLayerAni(doc, doc_str, 'sub' + i);
			else
				hideLayer(doc, 'sub' + i);

			//hideLayer(doc, 'bck' + i);
		}
	}
	
}

//********************************************************************
//*	Routine:	showSubMenu()
//*
//* Desc:		This procedure displays the submenu as it is mouse
//*				overed.	
//*
//********************************************************************
function showSubMenu(doc, doc_str, mainMenu, subMenu, animate)  {

  	clearTimeout(timerID);

	if (mainMenu) {
		clearNav(doc, doc_str, 0);
	}
	
	if (subMenu > 0) {
		//showLayer(doc, 'sub' + subMenu);
		if (animate)
			showLayerAni(doc, doc_str, 'sub' + subMenu);
		else
			showLayer(doc, 'sub' + subMenu);
		//showLayerAni.scrollMenu(200);
		//showLayer(doc, 'bck' + subMenu);
	}
	  
}

//********************************************************************
//*	Routine:	setTimer()
//*
//* Desc:		This procedure sets the timer to clear out the
//*				submenus.	
//*
//********************************************************************
function setTimer(doc_str, pause_len, animate) {

    timerID = setTimeout("clearNav(" + doc_str + ", '" + doc_str + "', " + animate + ")", pause_len);

}



