// Global 'corrector' for IE/Mac et al., but doesn't hurt others
var fudgeFactor = {top:-1, left:-1};

function centerItHoriz(layerName) {
	//alert("centerIt() about to run")
    // 'obj' is the positionable object
    var obj = getRawObject(layerName);
    // set fudgeFactor values only first time
    if (fudgeFactor.top == -1) {
        if ((typeof obj.offsetTop == "number") && obj.offsetTop > 0) {
            fudgeFactor.top = obj.offsetTop;
            fudgeFactor.left = obj.offsetLeft;
        } else {
            fudgeFactor.top = 0;
            fudgeFactor.left = 0;
        }
        if (obj.offsetWidth && obj.scrollWidth) {
            if (obj.offsetWidth != obj.scrollWidth) {
                obj.style.width = obj.scrollWidth;    
            }
        }
    }
	//alert("centerIt() about to calc x and y")
    var x = Math.round((getInsideWindowWidth()/2) - (getObjectWidth(obj)/2));
	//alert("calc for x: getInsideWindowWidth() = " + getInsideWindowWidth());
	//alert("calc for x: getObjectWidth(obj) = " + getObjectWidth(obj));
	//alert("centerIt() got x, about to get y")	
	//alert("getObjectTop(obj): " + getObjectTop(obj))
    var y = 0;
	x = x - fudgeFactor.left;
	if (x < 0) x = 0;
	//alert("x: " + x + "\n" + "y: " + y + "\n")
    shiftTo(obj, x, y);
	//alert("centerIt() about to show obj")
    //show(obj);
	//alert("centerIt() ran")
	//alert("fudgeFactor.left: " + fudgeFactor.left + "\n" + "fudgeFactor.top: " + fudgeFactor.top + "\n")
}

// Special handling for CSS-P redraw bug in Navigator 4
function handleResize() {
    if (isNN4) {
        // causes extra re-draw, but gotta do it to get banner object color drawn
        location.reload();
    } else {
        //centerItHoriz('menu_div');
		//showMenu('hide_last');
		initMenus();
    }
}

function getPos(el,sProp) {
	var iPos = 0
	var alertTxt = ""
		while (el!=null) {
			alertTxt+="el: " + el + "\n"
			//alertTxt+="el.offsetWidth: " + el.offsetWidth + "\n" + "el.offsetHeight: " + el.offsetHeight + "\n"
			alertTxt+="el.offset" + sProp + ": " + el["offset" + sProp] + "\n"
			//alertTxt+="el." + sProp + ": " + el[sProp] + "\n"
			//alertTxt+="el.style." + sProp + ": " + el["style." + sProp] + "\n"
			iPos+=el["offset" + sProp]
			el = el.offsetParent
		}
	alertTxt+="iPos = " + parseInt(iPos) + "\n"
	//alert(alertTxt)
	return iPos
}

/* old 
var macIE = {left:0, top:0};
var cm=null; //holds the currently shown menu later on in the showMenu() function
var imgLocationPrefix = "/images/GlobalNavMenu/"
var imgFileSuffix = ".gif"
function showMenu(img) {
	if (img != null && img != 'hide_last') { //if img has been passed and we're not hiding on a resize event
		el = getRawObject(img + "_span")
		m = getRawObject(img + "_menu")
		if (m) {
			if (m.style.display != '') {
				m.style.display='';
				//alert("navigator.userAgent: " + navigator.userAgent)
				//if (navigator.userAgent.indexOf("MSIE 5.22") != -1) macIE = {left:10, top:15};
				if (navigator.userAgent.indexOf("MSIE 5.22") != -1) macIE = {left:0, top:8};
				//if (navigator.userAgent.indexOf("Safari") != -1) macIE = {left:-8, top:0};
				if (navigator.userAgent.indexOf("Safari") != -1) macIE = {left:0, top:8};
				//m.style.pixelLeft = getPos(el,"Left") + 2 + macIE.left
				//m.style.pixelTop = getPos(el,"Top") + el.offsetHeight + macIE.top
				shiftTo(m, getPos(el,"Left") + 2 + macIE.left, getPos(el,"Top") + el.offsetHeight + macIE.top)
				MM_swapImage(img,'',imgLocationPrefix + img + '_Down' + imgFileSuffix,1)
				document.MM_sr[0].oSrc = imgLocationPrefix + img + '_Down' + imgFileSuffix
			} else {
				m.style.display='none';
				MM_swapImage(img,'',imgLocationPrefix + img + imgFileSuffix,1)
				document.MM_sr[0].oSrc = imgLocationPrefix + img + imgFileSuffix
			}
		}
		if ((img!=cm) && (cm)) { //hide the menu that was set as current the last time
			//menuTimer = setTimeout("showMenu('hide_last')", 5000);
			thisCM = getRawObject(cm + "_menu")
			thisCM.style.display = 'none'
			MM_swapImage(cm,'',imgLocationPrefix + cm + imgFileSuffix,1)
			document.MM_sr[0].oSrc = imgLocationPrefix + cm + imgFileSuffix
		}
		cm=img //set the current menu to the one we've just shown
	} else if ((img == 'hide_last') && (cm)) { //a hide has been called, probably on a resize event
		thisCM = getRawObject(cm + "_menu")
		thisCM.style.display = 'none'
		MM_swapImage(cm,'',imgLocationPrefix + cm + imgFileSuffix,1)
		document.MM_sr[0].oSrc = imgLocationPrefix + cm + imgFileSuffix
	}
}*/

/* New Menu code - 7/7/2004 */
/* Create the navigation arrays */
menus = new Array('aboutUs','ourMinistries','supportBGEA','contactBGEA'); // used for the initMenus() and hideAll() functions.

/* check browser */
var myBrowser = navigator.userAgent;
function checkBrowser(){
	ns4 = (document.layers) ? true : false;
	ie4 = (document.all && !document.getElementById) ? true : false;
	ie5 = (document.all && document.getElementById) ? true : false;
	ns6 = (!document.all && document.getElementById) ? true : false;
	isMac = false;
	if(myBrowser.indexOf('Mac') > -1){isMac = true;}
}

/* This Function gives you an object back by passing it an id - used in menu functions only */
function checkIn(id) {
	if(ie4){return document.all[id].style;}
	if(ie5 || ns6){return document.getElementById(id).style;}
	else{return document[id];}
}

/* change layer visibility */
function changeVisibility() {
	var status = arguments[0];
	var endInc = arguments.length;
	for(i=1; i<arguments.length; i++){
		obj = checkIn(arguments[i]);
		obj.visibility = status;
	}
}

/* Hides all layers in the navigation */
function hideAll(){
	for(i=0; i<menus.length; i++){
		//then proceed to turn off the layer.
		obj = checkIn(menus[i]);
		clearTimeout(obj.timer);
		expression = "changeVisibility('hidden','"+ menus[i] +"')";
		obj.timer = setTimeout(expression,150);
	}
	
}

/* Shows a certain layer with a timer */
function showNavMenu(id){
	p = eval(id + ".parent");
	obj = checkIn(id);
	clearTimeout(obj.timer);
	expression = "changeVisibility('visible','"+ id +"')";
	obj.timer = setTimeout(expression,150);
	if(p != "main"){
		//then turn it on.
		expression = "changeVisibility('visible','"+ p +"')";
		p = checkIn(p);
		clearTimeout(p.timer);
		p.timer = setTimeout(expression,150);
	}
}

/* This function works as a link for on mouse clicks - use only if needed */
function linkTo(url){
	window.location = url;
}

/* Swap images in the specified object with the specified replacement image */
function imageSwap(daImage, daSrc){
  var objStr,obj;
  if(document.images){
    // Check to see whether you are using a name, number, or object
    if (typeof(daImage) == 'string') {
      // This whole objStr nonsense is here solely to gain compatability
      // with ie3 for the mac.
      objStr = 'document.' + daImage;
      obj = eval(objStr);
      obj.src = daSrc;
    } else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
      daImage.src = daSrc;
    }
  }
}

//////////////////////////////////////////////////////////////
// Initialize Menus
//////////////////////////////////////////////////////////////
var macIE = {left:0, top:0};
if (navigator.userAgent.indexOf("MSIE 5.2") != -1) macIE = {left:0, top:8};
if (navigator.userAgent.indexOf("Safari") != -1) macIE = {left:0, top:8};
function initMenus(){
	centerItHoriz('menu_div'); //centers the Nav Header div on the page
	if(!ns4){
		for(i=0; i<menus.length; i++) {
			parentObj = getRawObject(menus[i] + '_main');
			menuObj = getRawObject(menus[i]);
			shiftTo(menuObj, getPos(parentObj,"Left") + 2 + macIE.left, getPos(parentObj,"Top") + parentObj.offsetHeight + macIE.top);
		}
	}
	show('menu_div'); //shows the Nav Header div
}

checkBrowser();
/* End New Menu code - 7/7/2004 */
