var currentDiv = [];
var arrPreload = [];
var curSub = "none";
var intSub = "none";
var curSrc = "none";
var curId = "none";
var curPop = "";

function init() {
  if(window.curMainSec) {
    document.getElementById(curMainSec).className = "subactive";
  }
  var arrDivs = document.getElementsByTagName("div");
  for(i=0;i<arrDivs.length;i++) {
    if(arrDivs[i].className=="showitem") {
	  currentDiv[currentDiv.length] = arrDivs[i];
	}
  }
  var arrAnchors = document.getElementsByTagName("a");
  for(i=0;i<arrAnchors.length;i++) {
    arrAnchors[i].onfocus = new Function("doFocus(this)");
    if(arrAnchors[i].rel=="rollover") {
	  arrAnchors[i].onmouseover = new Function("rollOver(this)");
	  arrAnchors[i].onmouseout = new Function("rollOut(this)");
	  arrAnchors[i].imgObj = arrAnchors[i].getElementsByTagName("img")[0];
	  arrAnchors[i].origSrc = arrAnchors[i].imgObj.src;
	  arrAnchors[i].overSrc = arrAnchors[i].imgObj.src.replace("_0.","_1.");
	  preLoad(arrAnchors[i].overSrc);
	}
	if(arrAnchors[i].rel=="mainnav") {
	  arrAnchors[i].onmouseover = new Function("showSub(this)");
	  arrAnchors[i].onmouseout = new Function("subRollOut(this)");
	}
	if(arrAnchors[i].rel=="subroll") {
	  arrAnchors[i].onmouseover = new Function("subRollOver(this)");
	  arrAnchors[i].onmouseout = new Function("subRollOut(this)");
	  /*if(arrAnchors[i].href==location) {
	    arrAnchors[i].className = "subactive";
	  }*/
	}
  }
  preLoad("../images/shared/top_nav_bg_1.gif","../images/shared/drop_nav_bg_0.gif","../images/shared/drop_nav_bg_1.gif","../images/shared/sub_nav_bg_1.gif","../images/shared/sub_nav_bg_end_1.gif");
  posNav();
}

// init() is now called in footer include to avoid error when user clicks nav before page loaded
//window.onload = init;

function preLoad() {
  for(j=0;j<arguments.length;j++) {
    imgTemp = new Image();
    imgTemp.src = arguments[j];
    arrPreload[arrPreload.length] = imgTemp;
  }
}

function showHideMult() {
  var showStatus = (arguments[0]=="hide") ? "hideitem" : "showitem";
  for(i=0;i<currentDiv.length;i++) {
    currentDiv[i].className = "hideitem";
  }
  currentDiv = [];
  for(i=1;i<arguments.length;i++) {
    if(showStatus=="showitem") {
      currentDiv[currentDiv.length] = document.getElementById(arguments[i]);
	}
    document.getElementById(arguments[i]).className = showStatus;
  }
}

function rollOver(objTemp) {
  objTemp.imgObj.src = objTemp.overSrc;
}

function rollOut(objTemp) {
  objTemp.imgObj.src = objTemp.origSrc;
}

function showSub(objTemp) {
  if(curSub!="none") {
    document.getElementById(curSub).style.display = "none";
  }
  if(intSub!="none") {
    clearInterval(intSub);
  }
  curSub = "sub"+objTemp.id;
  if((curSub=="subcompany") || (curSub=="sublocations")) {
    if(document.getElementById("areadropdown")!=null) {
	  document.getElementById("areadropdown").style.visibility = "hidden";
	}
  } else {
    if(document.getElementById("areadropdown")!=null) {
	  document.getElementById("areadropdown").style.visibility = "visible";
	}
  }
  /*
  if (navigator.userAgent.indexOf("Firefox")!=-1) {
    tmpInt = Math.round((document.getElementById("holder").offsetWidth - 782) / 2) + objTemp.offsetParent.offsetLeft + 17;
  } else {
    tmpInt = (document.getElementById("holder").offsetLeft + objTemp.offsetParent.offsetLeft + 18);
  }*/
//  document.getElementById(curSub).style.left = tmpInt + "px";
  //document.getElementById(curSub).style.left = (((document.getElementById("holder").offsetParent.offsetWidth - 782)/2) + objTemp.offsetParent.offsetLeft) + "px";
  //document.getElementById(curSub).style.left = (document.getElementById("holder").offsetLeft + objTemp.offsetParent.offsetLeft + 18) + "px";
  document.getElementById(curSub).style.display = "block";
}

function hideSub() {
  document.getElementById(curSub).style.display = "none";
  if((curSub=="subcompany") || (curSub=="sublocations")) {
    if(document.getElementById("areadropdown")!=null) {
	  document.getElementById("areadropdown").style.visibility = "visible";
	}
  }
  if(intSub!="none") {
    clearInterval(intSub);
	intSub = "none";
  }
}

function subRollOver(objTemp) {
  if(intSub!="none") {
    clearInterval(intSub);
	intSub = "none";
  }
}

function subRollOut(objTemp) {
  intSub = setInterval("hideSub()",50);
}

function confirmDelete(strHref) {
  if(confirm("Are you sure you want to delete this item?")) {
    location = strHref;
  } else {
	return false;
  }
}

function writeEmail(strDomain,strAddress,strContact) {
  document.write('<a href="mailto:'+strAddress+'@'+strDomain+'" class="text">');
  if(strContact!=null) {
    document.write(strContact+'</a>');
  } else {
    document.write(strAddress+'@'+strDomain+'</a>');
  }
}

function doOffsetOver(strId,strSrc) {
  curId = strId;
  curSrc = document.getElementById(strId).src;
  document.getElementById(strId).src = strSrc;
}
function doOffsetOut() {
  document.getElementById(curId).src = curSrc;
}

function openWin(strUrl,strWidth,strHeight,strParams) {
  strTempParam = "width="+strWidth+",height="+strHeight;
  if(strParams!=null) strTempParam+=","+strParams;
  curPop = window.open(strUrl,'newwin',strTempParam);
  curPop.focus();
  //curPop.onblur = hideWin;
}

function hideWin() {
  this.close();
  }

function closeWin() {
  if(typeof(curPop)=="object") {
    if(!curPop.closed) {
      curPop.close();
	}
  }
  return true;
  }

function doFocus(tmpObj) {
  if(tmpObj.blur) tmpObj.blur();
}

function horizonBay(obj) {
	objUri = obj.href;
	horizonWindow = window.open(objUri, 'horizonWindow', 'width=520, height=580, resizable=yes, menubars=no, status=yes, scrollbars=yes');
	return false;
}

managed0 = new Image();
managed0.src = 'images/managedby_0.gif';
managed1 = new Image();
managed1.src = 'images/managedby_1.gif';

function switchManaged(state, obj) {
	if (state == 0) {
		obj.firstChild.src = eval('managed'+state+'.src');
	}
	if (state == 1) {
		obj.firstChild.src = eval('managed'+state+'.src');
	}
}

function posNav() {
	ie = document.all;
	
	if (ie) {
		iw = document.body.clientWidth;
	}
	else {
		iw = document.body.offsetWidth;
	}
	
	centre = Math.floor(iw / 2);
	
	if (navigator.userAgent.indexOf('AppleWebKit') >= 0) {
		centre--;
	}
	document.getElementById('subcompany').style.left = centre - 373 +'px';
		
	document.getElementById('sublocations').style.left = centre - 227 +'px';
		
	document.getElementById('subliving').style.left = centre - 81 +'px';
		
	document.getElementById('subsenior').style.left = centre + 65 +'px';
		
	document.getElementById('subcontact').style.left = centre + 211 +'px';
}

document.onresize = function() {
	posNav();
}

window.onresize = function() {
	posNav();
}