//Layer Show-Hide Script
//Alan Murphy
//2004

var activeSub=0;
var SubNum=0;

//NS4-only resize css bug workaround:
if(document.layers){
	origWidth=innerWidth;
	origHeight=innerHeight;
	onresize=function(){
		if(innerWidth!=origWidth||innerHeight!=origHeight){
			window.location.reload();
			//alert('NN4 re-sizing!');
		}
	}
}

    //Define global variables

	    var timerID = null;
		var timerOn = false;
		var timecount = 1000;
		var what = null;
		var newbrowser = true;
		var check = false;
		var i = 0;

function init() {
    	//alert ("Running Init");
		 if (document.layers) {
                      		//alert ("Running Netscape 4");
                        		layerRef="document.layers";
                        		styleSwitch="";
                        		visibleVar="show";
			screenSize = window.innerWidth;
			what ="ns4";
		}else if(document.getElementById) {
                     		//alert ("Running DOM1");
                       		 layerRef="document.getElementByID";
                       		 styleSwitch=".style";
                       		visibleVar="visible";
			what="moz";
		}else if(document.all) {
                     		 //alert ("Running IE");
                       		 layerRef="document.all";
                      		  styleSwitch=".style";
                      		  visibleVar="visible";
			screenSize = document.body.clientWidth + 18;
			what ="ie";
		}else {
		  	//alert("Older than 4.0 browser.");
			what="none";
			newbrowser = false;
		  }
 
		//window.status='Please Select a Snippet Option';
		check = true;
}
//PUT ALL DYNAMIC LAYERS USED IN THE NAV HERE:
myArray = new Array('aboutUsPop','brokerPop','groupPop','indivPop','dentistPop');
//PUT ALL LAYERS USED IN THE MENU HERE:
myArray2=new Array('aboutUs','brokers','group','indiv','dentists');

var menuPos1=null;
var menuPos2=null;
tHeight=null;

function getAbsX(elt) {//NS6-only absolute position:
	 return (elt.x) ? elt.x : getAbsPos(elt,"Left"); 
}
function getAbsY(elt) { 
	return (elt.y) ? elt.y : getAbsPos(elt,"Top"); 
}

function getAbsPos(elt,which) {
	 iPos = 0;
	 while (elt != null) {
		  iPos += elt["offset" + which];
		  elt = elt.offsetParent;
	 }
	return iPos;
}

function menuPos(){
	for (i=0;i<5;i++){
		if ((!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)){
			//alert('NS6');
			menuPos1=(getAbsY(document.getElementById('table2'))-2)+'px';
			menuPos2=(getAbsX(document.getElementById(myArray2[i])))+'px';
			//alert(myArray2[i]+' :: '+menuPos1+' :: '+menuPos2);
			document.getElementById(myArray[i]).style.top=menuPos1;
			document.getElementById(myArray[i]).style.left=menuPos2;
		}else if(document.getElementById){
			//alert('W3C DOM');
			tHeight=(document.getElementById('table1').offsetHeight);
			//alert(tHeight);
			//mHeight=document.getElementById('mainNav').offsetHeight;	
			//menuPos1=tHeight+mHeight;
			if(document.all){
				//IE
			menuPos2=document.getElementById(myArray2[i]).offsetLeft;
					}
			else{
				//mozilla
			menuPos2=document.getElementById(myArray[i]).offsetLeft;
				}
			//alert(myArray2[i]+' :: '+menuPos1+' :: '+tHeight);
			document.getElementById(myArray[i]).style.top=(tHeight-2);
			document.getElementById(myArray[i]).style.left=menuPos2;
		}
	}
}

function showLayer(layerName){
	//alert('Showing Layer Now');
	layr=layerName;
	menuPos();	//first set position
        	if(check){
        		if (what =="none"){	// then turn the layer on
        			return;
        		}else if (what == "moz"){
        			document.getElementById(layerName).style.visibility="visible";
        		}else{
                 		 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
                  	}
	}else {
		// alert ("Please wait for the page to finish loading.");
        		return;
	}
}

function hideLayer(layerName){
	//alert('Hiding Layer Now');
        	if(check){
        		if (what =="none"){
        			return;
        		}else if (what == "moz"){
        			document.getElementById(layerName).style.visibility="hidden";
        		}else{
                  	eval	(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
			}
            }else {
		// alert ("Please wait for the page to finish loading.");
        		return;
		}
}


function hideAll(){	
	for (i=0;i<5;i++){
		hideLayer(myArray[i]);
	}
}


function startTime() {
		if (timerOn == false) {
			timerID=setTimeout( "hideAll()" , timecount);
			timerOn = true;
		}
}

function stopTime() {
		if (timerOn) {
			clearTimeout(timerID);
			timerID = null;
			timerOn = false;
		}
}

function onLoad(){
	init();		
}

function m_over(btn){
	if(document.getElementById){
		document.getElementById(btn).className='inputbutton_hover';
	}
}

function m_down(btn){
	if(document.getElementById){
		document.getElementById(btn).className='inputbutton_active';
	}
}

function m_up(btn){
	if(document.getElementById){
		document.getElementById(btn).className='inputbutton_hover';
	}
}

function m_out(btn){
	if(document.getElementById){
		document.getElementById(btn).className='inputbutton';
	}
}