//
//**		Layer Handling Utility Functions Subset
//
//**	OIL, Incorporated
//

//	Set browser specific variables for different browsers
var ie4=document.all;var net4=document.layers;var dom=false;if(document.getElementById)dom=true;

//	Find Object Functions:
//	Stack object to track where objects are found
function StackObj(){
	this.stackArray = new Array();
	this.stackPos=null;
	this.traceStr="";
	};
function StackObj_initStack(){for(i=0; i<this.stackArray.length; i++)this.stackArray[i]="";this.stackPos = -1;this.traceStr = "";};
function StackObj_pushStack(obj){this.stackPos++;this.stackArray[this.stackPos]=obj;this.traceStr+="Push at " + this.stackPos + " is " + this.stackArray[this.stackPos] + " typeof=" + (typeof this.stackArray[this.stackPos]) + "\n";};
function StackObj_popStack(){if(this.stackPos < 0){this.traceStr+="Error, null while popping at "+ this.stackPos +"\n";return null;}this.traceStr+=" poping position " + this.stackPos + " = " + this.stackArray[this.stackPos] + "\n";this.stackPos--;return this.stackArray[this.stackPos+1];};
function StackObj_getStack(index){if((index>this.stackPos)||(index<0))return null;return this.stackArray[index];};
function StackObj_getStackSize(){return (this.stackPos+1);};
function StackObj_listStack(){var retStr="";for(i=0;i<=this.stackPos;i++){if(this.get(i)!= null){retStr+=this.get(i);}retStr+="\n";}return retStr;};
function StackObj_hasNext(){if(this.stackPos>-1)return true;else return false;};
function StackObj_trace(){return this.traceStr;};
StackObj.prototype.init = StackObj_initStack;StackObj.prototype.push = StackObj_pushStack;StackObj.prototype.pop = StackObj_popStack;StackObj.prototype.get = StackObj_getStack;
StackObj.prototype.size = StackObj_getStackSize;StackObj.prototype.toString = StackObj_listStack;StackObj.prototype.trace = StackObj_trace;StackObj.prototype.hasNext = StackObj_hasNext;
if(net4)var stack = new StackObj();
var overrun = 0;// Static variable for findObj function

//	Enhanced FindObj Functions
//	findObj Start Function
function findObj(d,objsNames){
	overrun = 0;foSearchStr="";
	if(net4)stack = new StackObj();
	if(typeof objsNames=='string'){
		if(dom)return findObjs_SearchDoc(d,objsNames);
		else if(d.all)return findObjs_SearchDoc(d.all,objsNames);
		return findObjs_Loop(d,objsNames);
		}
	else if(typeof objsNames=='object'){
		//	use document.all for ie, don't need loop
		if(dom)return findObjs_SearchDoc(d,objsNames);
		if(d.all)return objsNames=findObjs_SearchDoc(d.all,objsNames);
		return objsNames=findObjs_Loop(d,objsNames);
		}
	};

var foSearchStr="";

//	findObj_Loop Function: loops through layers and searches for objects using the findObj_SearchDoc function
function findObjs_Loop(d,objects){
	if(overrun>=50)return null;
	overrun++;
	var name=objects;
	//	Search Root Document Itself
	objects=findObjs_SearchDoc(d,objects);
	//	Check if all objects found, if so, return
	foSearchStr+="  checking base object, found " + objects + "\nwith checkFound returning " + findObjs_checkFound(objects)+"\n";
	if(findObjs_checkFound(objects)){foSearchStr+="\nReturning " + objects + "\n";return objects;}
	for(var i=0;d.layers&&i<d.layers.length;i++){
		foSearchStr+="Checking layer " + d.layers[i].name + "\n";
		//	If Stack is being used, push layer object onto stack
		if(stack)stack.push(d.layers[i]);
		objects=findObjs_SearchDoc(d.layers[i].document,objects);
		if(d.layers[i].document.layers&&(d.layers[i].document.layers.length>0)){
			foSearchStr+="  stepping into " + d.layers[i].name + "\n";
			if(stack)stack.push(d.layers[i]);
			objects=findObjs_Loop(d.layers[i].document,objects);
			//	If all of the objects were found, return return object
			if(findObjs_checkFound(objects))return objects;
			else if(stack)stack.pop();//	Else if stack, pop stack
			foSearchStr+="  coming back from " + d.layers[i].name + "\n";
			}
		}
	return objects;
	};

//	findObj_SearchDoc Function: searches the passed document for object references
function findObjs_SearchDoc(d,objects){
	if(typeof objects=="object"){
		for(obj in objects){
			if(!objects[obj]){
				if(d[obj])objects[obj]=d[obj];
				else if(dom && d.getElementById(obj))objects[obj]=d.getElementById(obj);
				else if((d.images)&&(d.images[obj]))objects[obj]=d.images[obj];
				else if((d.embeds)&&(d.embeds[obj]))objects[obj]=d.embeds[obj];
				//	If net4, object now found, and is image, add custom offsetParent 
				//	prop to object pointing to the document that contains it, used by
				//	getPosition(), getAbsTop(), getAbsLeft() functions
				if(net4&&objects[obj]&&(typeof objects[obj]=="object")&&objects[obj].complete)objects[obj].offsetParent=stack.get(stack.size()-1);
				}
			}
		}
	else if((typeof objects=="string")&&(objects!="")){
		if(d[objects])objects=d[objects];
		else if(dom && d.getElementById(objects))objects=d.getElementById(objects);
		else if((d.images)&&(d.images[objects]))objects=d.images[objects];
		else if((d.embeds)&&(d.embeds[objects]))objects=d.embeds[objects];
		//	If net4, object now found, and is image, add custom offsetParent 
		//	prop to object pointing to the document that contains it, used by
		//	getPosition(), getAbsTop(), getAbsLeft() functions
		if(net4&&objects&&(typeof objects=="object")&&objects.complete)objects.offsetParent=stack.get(stack.size()-1);
		}
	return objects;
	};

//	Utility function that can verify if all items being looked for are found,
//	whether it is a single object or a collection of objects
function findObjs_checkFound(obj){
	//	If obj is string, lookin for string and still not found
	if(typeof obj=='string')return false;
	else if(typeof obj=='object'){
		//	If object is a layer, div, embed, or img, it will have one of these properties
		if(obj.layers||obj.nodeType||obj.all)return true;
		//	Else, obj is list of layer references, step through sub-objects 
		//	and check if any are null, if so, return false
		for(subObj in obj)if(obj[subObj]==null)return false;
		}
	else return false;
	//	If reached end, all objects must be found...
	return true;
	};

//
//		Getting functions
//


//	Functions to get width and height of layer
function getHeight(obj){
	if(net4){
		if(obj.clip)return obj.clip.height;
		else if(obj.height)return obj.height;
		}
	if(ie4)return obj.clientHeight;
	if(dom)return obj.offsetHeight;
	return 0;
	};

function getWidth(obj){
	if(net4){
		if(obj.clip)return obj.clip.width;
		else if(obj.width)return obj.width;
		}
	if(ie4)return obj.clientWidth;
	if(dom)return obj.offsetWidth;
	return 0;
	};

//	Get distance from top relative to parent object
function getTop(layerObj){
	if(ie4||dom)return layerObj.offsetTop;
	if(net4)return layerObj.top;
	return null;
	};

//	Get distance from left relative to parent object
function getLeft(layerObj){
	if(ie4||dom)return layerObj.offsetLeft;
	if(net4)return layerObj.left;
	return null;
	};


//
//		Setting Functions
//

//	Functions to show/hide a layer
function showLayer(layerObj){
	if(!layerObj)return;
	if(net4)layerObj.visibility="show";
	if(ie4||dom)layerObj.style.visibility="visible";
	};
function hideLayer(layerObj){
	if(!layerObj)return;
	if(net4)layerObj.visibility="hide";
	if(ie4||dom)layerObj.style.visibility="hidden";
	};
function inheritVisibility(layerObj){
	if(!layerObj)return;
	if(net4)layerObj.visibility="inherit";
	if(ie4||dom)layerObj.style.visibility="inherit";
	};

	
//	Function for Setting a Layer's Relative Position.  posArray is optional, if passed, use it instead of posX, posY
function setPosition(layerObj,posX,posY,posArray){
	if(posArray)
		if(posArray.length==2){
			posX=posArray[0];
			posY=posArray[1]
			}
	if(net4)layerObj.moveTo(posX,posY);
	else if(ie4||dom){
		layerObj.style.left=posX + "px";
		layerObj.style.top=posY + "px";
		}
	};

//	Set Relative Position
function setTop(layerObj,topVal){
	if(!isNaN(topVal)){
		if(ie4||dom)layerObj.style.top=topVal + "px";
		else if(net4)layerObj.top=topVal;
		}
	};
function setLeft(layerObj,leftVal){
	if(!isNaN(leftVal)){
		if(ie4||dom)layerObj.style.left=leftVal + "px";
		else if(net4)layerObj.left=leftVal;
		}
	};
