// Variables
var OBJX = 0
var OBJY = 0
var winW;
var winH;

//Functions
/* ===========================================================*\
findPosX - 	Call with object for which coordinate is desired
			Returns the X coordinate of the object
\*============================================================*/
function findPosX(obj)
{
	//IE
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	//NS Navigator
	else if (obj.x)
	{
		curleft += obj.x;
	}
	OBJX = curleft ;
	return curleft;
}

/* ===========================================================*\
findPosY - 	Call with object for which coordinate is desired
			Returns the Y coordinate of the object
\*============================================================*/
function findPosY(obj)
{
	//IE
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	//NS Navigator
	else if (obj.y)
	{
		curtop += obj.y;
	}
	OBJY = curtop;
	return curtop;
}

/* ===========================================================*\
getWindowSize - Sets vars to window size (considers browser 
										  types and scrollbars)
\*============================================================*/
function getWindowSize(){
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth-16;
  winH = window.innerHeight-16;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth-20;
  winH = document.body.offsetHeight-20;
 }
}
};

/* ================================================================*\
setLayerReltiveTo - Sets a layer relative to a given object
					Call with:
					- name of object to position
					- name of object to refernce from
					- x ,y offset coordinates position from refernce object
\*==================================================================*/
function setLayerReltiveTo(objToPosition, objToReferenceFrom, offsetX, offsetY){
var _objToPosition = document.getElementById(objToPosition);
var _objToReferenceFrom = document.getElementById(objToReferenceFrom);

findPosX(_objToReferenceFrom);
findPosY(_objToReferenceFrom);

OBJX = OBJX + (offsetX);
OBJY = OBJY + (offsetY);

_objToPosition.style.left = OBJX + 'px';
_objToPosition.style.top = OBJY + 'px';
}

/* ===========================================================*\
layerShowHide - Hides a visible layer OR Shows a hidden layer
				Call with layer name to show or hide
\*============================================================*/
function layerShowHide(LayerName){
getWindowSize()
PosLayerCenter(LayerName)

var obj = document.getElementById(LayerName);
if (obj.style.visibility == "visible"){
obj.style.visibility = 'hidden';
}
else
{
obj.style.visibility = 'visible';
}

};

/* ===========================================================*\
PosLayerCenter - Position a layer in screen center. 
\*============================================================*/
function PosLayerCenter(LayerName){
getWindowSize()
var obj = document.getElementById(LayerName);
var objH = obj.style.height
objH = objH.toString();
objH = objH.substring(0,objH.indexOf("px",0));

var objW = obj.style.width
objW = objW.toString();
objW = objW.substring(0,objW.indexOf("px",0));

var midY = (winH /2) - (objH /2);
var midX = (winW /2) - (objW /2);

obj.style.left = midX + 'px';
obj.style.top = midY + 'px'
};

/* ===========================================================*\
showIng - Position a layer in screen center. and shows it.
\*============================================================*/

function showIng(LayerName)
{
	PosLayerCenter(LayerName);
	layerShowHide(LayerName);
};
