/* define variables for "if n4 (Netscape 4), if IE (IE 4.x), 
and if n6 (if Netscape 6/W3C-DOM compliant)" */

var n4, ie, n6;

/* detecting browser support for key objects/methods and 
assembling a custom document object */


/* document.layers detects Netscape 4.* */
/* document.all works for IE */
/* document. GetElementById() works for W3C DOM compliant browsers 
(Netscape 6 and 7 and future ones */



var doc,doc2,doc3,sty;

if (document.layers) {
  doc = "document.";
  doc2 = ".document.";
  doc3 = "";
  sty = "";
  n4 = true;
  //alert("n4")
  }
else if (document.all) {
  doc = "document.all.";
  doc2 = "";
  doc3 = "";
  sty = ".style";
  ie = true;
  //alert("ie")
}

else if (document.getElementById) {
  doc = "document.getElementById('";
  doc2 ="')";
  doc3 ="')";
  sty = "').style";
  n6 = "true";
  //alert("n6")
 }
/* Set up for menu gifs */ 
  if (document.images)
   {
     topaboutusonsrc="imgs/TopNavigation/aboutus_on.gif"; 
     topaboutusoffsrc="imgs/TopNavigation/aboutus_off.gif";
     topaboutusbsrc="imgs/TopNavigation/aboutus_b.gif";
     topaboutusbonsrc="imgs/TopNavigation/aboutus_bon.gif";
     topregionalmaponsrc="imgs/TopNavigation/regionalmap_on.gif";
     topregionalmapoffsrc="imgs/TopNavigation/regionalmap_off.gif";
     topregionalmapbsrc="imgs/TopNavigation/regionalmap_b.gif";
     topregionalmapbonsrc="imgs/TopNavigation/regionalmap_bon.gif";
     topmembershiponsrc="imgs/TopNavigation/membership_on.gif"; 
     topmembershipoffsrc="imgs/TopNavigation/membership_off.gif";
     topmembershipbsrc="imgs/TopNavigation/membership_b.gif";
     topmembershipbonsrc="imgs/TopNavigation/membership_bon.gif";
     topcalendarofeventsonsrc="imgs/TopNavigation/calendarofevents_on.gif"; 
     topcalendarofeventsoffsrc="imgs/TopNavigation/calendarofevents_off.gif";
     topcalendarofeventsbsrc="imgs/TopNavigation/calendarofevents_b.gif";
     topcalendarofeventsbonsrc="imgs/TopNavigation/calendarofevents_bon.gif";
     topwhatisasthmaonsrc="imgs/TopNavigation/whatisasthma_on.gif"; 
     topwhatisasthmaoffsrc="imgs/TopNavigation/whatisasthma_off.gif";
     topwhatisasthmabsrc="imgs/TopNavigation/whatisasthma_b.gif";
     topwhatisasthmabonsrc="imgs/TopNavigation/whatisasthma_bon.gif";
     topasthmaresourcesonsrc="imgs/TopNavigation/asthmaresources_on.gif"; 
     topasthmaresourcesoffsrc="imgs/TopNavigation/asthmaresources_off.gif";
     topasthmaresourcesbsrc="imgs/TopNavigation/asthmaresources_b.gif";
     topasthmaresourcesbonsrc="imgs/TopNavigation/asthmaresources_bon.gif";
   }

	function lightup(imgName,topic,clas)
	 {
	   //alert(imgName + " - " + topic + " - " + clas);
	   if (document.images)
	    {
	      mod = "";
	      if(topic == "region")
	      {
			mod = "../";
		  }
	      imgOn=eval(imgName + "onsrc");
		  if(clas == "menuNavOn"){
			imgOn=eval(imgName + "bonsrc");
		  }
	      document[imgName].src = mod  + imgOn;
	    }
	 }

	function turnoff(imgName,topic,clas)
	 {
	   //alert(imgName + " - " + topic + " - " + clas);
	   if (document.images)
	    {
	      mod = "";
	      if(topic == "region")
	      {
			mod = "../";
		  }
		  imgOff=eval(imgName + "offsrc");
		  if(clas == "menuNavOn"){
			imgOff=eval(imgName + "bsrc");
		  }
	      //alert(topic + " - "  + imgOff);
	      document[imgName].src = mod  + imgOff;
//throw new Error("turnoff");
	    }
	 } 
 
 

// the variables for the window dimensions
var win_width,win_height;
var centerhor, centerver;


//Get dimensions of the window
function dimensions() {
if(n4 || n6){
 win_width=window.innerWidth;
 win_height=window.innerHeight;
}

else if(ie) {
  win_width=document.body.clientWidth;
  win_height=document.body.clientHeight;
     }

centerhor = win_width/2;
centerver = win_height/2;
}


//position the element on the page.

function moveit(elem,leftPos,topPos) {
//alert("2");
docObj = eval(doc + elem + sty);
if (n4 || n6) {
docObj.left = leftPos;
docObj.top= topPos;
 }
if (ie) {
docObj.pixelLeft = leftPos;
docObj.pixelTop = topPos;
 }
}

// preload navigation images

// This could be improved using and Array but it works fine this way also.

var loaded = 0;
var navdir = GetRootPath() + "mnasthma1/imgs/Topnavigation/";

function preload() {

loaded = 1;
}

// img src swap function
function onoff (elemparent,elem,state) {
if (loaded) {
newstate = eval(elem+"_"+state);
if (n4) {
menuObj = eval (doc + elemparent + doc2 + elem);
 }
else if (ie || n6) {
menuObj = eval (doc + elem + doc2);
 }
menuObj.src = newstate.src;
 }
}


// mouse over (on) and mouseoff(off) color values
var oncolor = "#234c7d";
var offcolor = "#d9eafa";
var ontxcolor = "#fbf100";
var offtxcolor = "#ffffff";

function changecolor(divname,colorname) {
stopall();
	//alert(divname + " - " + colorname);
if (!n4) {
menuObj = eval(doc + divname + sty);
menuObj.backgroundColor = colorname;
  }
}

function changetextcolor(divname,colorname) {
stopall();
if (!n4) {
menuObj = eval(doc + divname + sty);
menuObj.color = colorname;
  }
}

// show or hide DIV element
function showhide(divname,state) {
if (n4) {
divObj = eval (doc + divname);
 }
else {
divObj = eval (doc + divname + sty);
}
divObj.visibility = state;
}


// variables that hold the value of the currently active (open) menu
var active_submenu1 = null;
var active_submenu2 = null;
var active_menuelem = null;
var active_topelem = null;

// function closes all active menus and turns back to 'off' state
function closeallmenus() {
if(active_submenu1 != null) {
  showhide(active_submenu1,'hidden');
  }
if(active_submenu2 != null) {
  showhide(active_submenu2,'hidden');
  }
if(active_menuelem != null) {
  changecolor(active_menuelem,offcolor);
  }
if(active_topelem != null) {
  onoff('mainmenu',active_topelem,'off');
  }
}

// the menu close timeout variable
var menu_close_timeout = 0;

// delay in miliseconds until the open menus are closed
var delay = 100;

// function calls the closeallmenus() function after a delay
function closeall() {

menu_close_timeout = setTimeout('closeallmenus()',delay);
}

// stop all timeout functions (stops menus from closing)
function stopall() {
clearTimeout(menu_close_timeout);
}

// function controls submenus 
function controlsubmenu(submenu1,submenu2,menuelem,topelem) {
//alert(submenu1 + " - " + submenu2 + " - " + menuelem + " - " + topelem);
stopall();
closeallmenus();
if (submenu1 != null) {
  showhide(submenu1,'visible');
  active_submenu1 = submenu1;
  }
if (submenu2 != null) {
 showhide(submenu2,'visible');
 active_submenu2 = submenu2;
  }
if (menuelem != null) {
 changecolor(menuelem,oncolor);
 active_menuelem = menuelem;
 }
if (topelem != null) {
 onoff('mainmenu',topelem,'on');
 active_topelem = topelem;
 }
}


function initialize() {
	preload();
	closeallmenus();
	stopall();
	dimensions();
	plat = navigator.platform;
	//alert(plat);
	if (win_width < 800) {
		mainmenuleft = centerhor - 385;
		memoff = mainmenuleft;
	 }
	else {
		mainmenuleft = centerhor - 372;
		memoff = mainmenuleft - 125;
	     }	
	base = mainmenuleft + 334;
	gap = 140;
	mnheight = 50;
	mnheight1 = mnheight + 22;
	rbase = base -240;
	rheight = mnheight + 185;
	reg = 25;
	if(n4 || n6){
		mnheight = 45;
		mnheight1 = mnheight + 25;
		rheight = mnheight + 162;
	}
	if(plat == "MacPPC"){
		base = mainmenuleft + 272;
		mnheight = 43;
		mnheight1 = mnheight + 20;
		rheight = mnheight + 150;
	}
	moveit("aboutus",base,mnheight);
	moveit("membership",base + gap,mnheight);
	moveit("regionalmap",base + 2*gap,mnheight);
	moveit("calendarofevents",base,mnheight1);
	moveit("whatisasthma",base + gap,mnheight1);
	moveit("asthmaresources",base + 2*gap,mnheight1);
/*	moveit("Central",rbase,rheight);
	moveit("NorthEast",rbase,rheight + reg);
	moveit("NorthWest",rbase,rheight + 2* reg);
	moveit("SouthCentral",rbase,rheight + 3* reg);
	moveit("SouthEast",rbase,rheight + 4* reg);
	moveit("SouthWest",rbase,rheight + 5* reg);
	moveit("Metro",rbase,rheight + 6* reg);
	moveit("WestCentral",rbase,rheight + 7* reg);
	moveit("EastCentral",rbase,rheight + 8* reg);*/
}
