// Sanger JavaScript Document

//workaround for array.push on IE5
if(typeof Array.prototype.push == "undefined")
 	Array.prototype.push = function(){
  	 var i=0;
  	 b=this.length,a=arguments;
  	 for(i;i<a.length;i++)this[b+i]=a[i];
  	 return this.length
 	}

//REDIRECTION SCRIPT
//set browser variables
var IE5 = (document.all && document.getElementById);
var w3c = (!document.all && document.getElementById);
var safari = navigator.userAgent.indexOf('Safari');
var mac = navigator.userAgent.indexOf('Mac'); 
var IE = navigator.userAgent.indexOf('MSIE');
var macIE = (mac != -1) && (IE != -1);
var NN6 = navigator.userAgent.indexOf('Netscape6');

if(IE5 && (mac == -1)){}
else if(macIE){}
else if(w3c){}
else{window.location.href="redirect.htm";}


//****************set kiosk variable if in kiosk mode in  kiosk.js
var kiosk;
function setKiosk(){
	kiosk = 0;
}


//BEGIN NAVIGATION FUNCTIONS
//set navigation variables used across functions
var state = 0;
var pause = 300;
//main navigation headers that have subMenus
var menu = new Array()
	menu[0] = 'service';
	menu[1] = 'physician';
	menu[2] = 'location';
	menu[3] = 'appointment';
	menu[4] = 'wellness';
	menu[5] = 'about';
	menu[6] = 'heart';
	menu[7] = 'career';
	menu[8] = 'contact';

//main navigation headers that do not have subMenus
var noMenu = new Array()

//secondary level subMenus link IDs
var secMenu = new Array()

//primary subMenu link IDs
// 'abSubAct', took out January 8, 2008
var pMenu = new Array( 'sSubAdu','sSubPed','sSubVas','sSubSur','sSubTra','sSubSup','sSubEdu','pSubLoc','pSubSpe','pSubPhy','lSubBoo','lSubCha','lSubSha','lSubCon','lSubCor','lSubDav','lSubFom','lSubGap','lSubHic','lSubHun','lSubLak','lSubLin','lSubLiv','lSubMon','lSubMor','lSubRoc','lSubRut','lSubSal','lSubShe','lSubShp','lSubSou','lSubUni','lSubPed','apSubReq','apSubSch','apSubFor','apSubIns','wSubHec','wSubRis','wSubPre','wSubDis','wSubWom','abSubMis','abSubHis','abSubCom','abSubNew','abSubHip','abSubSto','abSubFaq','hSubCon','hSubTre','hSubRes','hSubAtr','hSubWom','caSubPhy','caSubSta','coSubDep','coSubFee')

			
//displays and positions primary menus under respective menu headers
//hides primary menus
function openPMenu(obj) {
	for(i=0; i<9; i++){document.getElementById(menu[i]+'Sub').style.display = 'none';}
	
	var pDOM = document.getElementById(obj);
	var priMenu = obj+'Sub';
	var left = document.getElementById('header').offsetLeft;
	var top = document.getElementById('header').offsetTop;
	var leftPri = pDOM.offsetLeft;
	var pMenuID = document.getElementById(priMenu);
	var pMenuLeft = leftPri+0;
	if(NN6 != -1){pMenuLeft = leftPri;}
	var pMenuTop = top+38;
	if(NN6 != -1){pMenuTop = top+31;} 

	pMenuID.style.top = pMenuTop; //alert(pMenuID.style.top);
	pMenuID.style.left = pMenuLeft; //alert(pMenuID.style.left);
	pMenuID.style.position = 'absolute';// alert(pMenuID.style.position);
	pMenuID.style.zIndex = 800; //alert(pMenuID.style.zIndex); 
	var test = document.getElementById('aboutSub').style;
	pMenuID.style.display = 'block'; 
	if(pMenuID.offsetWidth <= 82){
		pMenuID.style.width = 85+'px';
	}
	if(macIE){
		pMenuID.style.width = 150+'px';
		document.getElementById('contactSub').style.width = 85+'px';
	}
}


//based on state variable initiated in init()
//hides menus or kills the function (state == 2)
function closeMenu() {
	if(state == 0){
		for(i=0; i<9; i++){
			document.getElementById(menu[i]+'Sub').style.display = 'none';
			document.getElementById(menu[i]).style.backgroundColor = '#339999';
		}
		return false;		
	}
	if(state == 1){
		for(i=0; i<9; i++){
			document.getElementById(menu[i]+'Sub').style.display = 'none';
			document.getElementById(menu[i]).style.backgroundColor = '#339999';
		}
		return false;		
	}
	if(state == 2){
		return false;		
	}
}

//initiates all menu states
//initiates positioning of navigation
//sets most event handlers in refrence to navigation menus
//pause sets the delay before function runs
function init(){ 
	//headers
	for(i=0; i<9; i++){
		var obj = document.getElementById(menu[i]);
		obj.onmouseout = function() {state = 1; setTimeout('closeMenu('+state+')',pause);}
	}
	//primary subMenu divs		
	for(i=0; i<9; i++){
		var obj = document.getElementById(menu[i]+'Sub');
		obj.onmouseover = function() {state = 2;}
		obj.onmouseout = function() {state = 1; setTimeout('closeMenu('+state+')',pause);}
		obj.style.whiteSpace = 'nowrap';
	}
	//primary menu links
	for(i=0; i<pMenu.length; i++){
		var obj = document.getElementById(pMenu[i]);
		obj.onmouseover = function(){
												state = 2;
											}
		obj.onmouseout = function() {state = 1; setTimeout('closeMenu('+state+')',pause); }
		obj.onclick = function() {state = 0; closeMenu();}
	}
	document.getElementById('header').style.visibility = "visible";
	
	var sitemap = window.document.getElementById('siteMap');
	sitemap.onmouseover = function(){sitemap.style.backgroundColor = "#339999";} // old color #AECB7C
	sitemap.onclick = function(){window.location.href = "sitemap.php";}
	sitemap.onmouseout = function(){sitemap.style.backgroundColor = "#339999";} // was 339999 (no #)
	
	//runs for kiosk mode
	if (kiosk == 0){
		kioskMode();
	}
}
//END NAVIGATION FUNCTIONS

function backgroundDefault(obj){
	for(i=0; i<9; i++){
		document.getElementById(menu[i]).style.backgroundColor = '#339999';
	}
	document.getElementById(obj).style.backgroundColor='#339999'; // old color #AECB7C
}

onload = init;
