//Menu Code Copyright 2002 by Harold Blackorby/SCORE Interactive
//May not be reused without written permission

function Is() {
  var agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
  this.ns4up = (this.ns && (this.major >= 4));
  this.ns4 = (this.ns && (this.major == 4));
  this.ns6up = (this.ns && (this.major >= 5));
  this.ns7up = (this.ns && (this.major >= 7));
  this.ie = (agent.indexOf("msie") != -1);
  this.ie4up = (this.ie && (this.major >= 4));
  this.win = (agent.indexOf("win")!=-1);
  this.mac = (agent.indexOf("mac")!=-1);
}

var is = new Is();
var screen_width;
var screen_height;
var available_width;
var available_height;
var doc;
var sty;
var htm;
var xdiff;
var ydiff;
var allready;
var prevMenu = "";
var prevSubMenu = "";
var numMenus = -1;
var numSubs = 0;
var aryMenu = new Array();
var arySub = new Array();
var lastTimeout = "";
var rollColor = "#5a9cd6";
var baseColor = "ffffff";
var rollSubColor = "#5a9cd6";
var baseSubColor = "ffffff";

// added by Rudi to resolve issues with Netscape 4 in Mac
var NaN;
var undefined;


function roll(obj) {
	hideMenu();
}
function rollBack(obj) {
}
function showMenu(menu,x,y)
{
	//hideMenu();
	if (allready)
	{
		if (lastTimeout != "")
		{
			clearTimeout(lastTimeout);
			lastTimeout = "";
		}
		lastTimeout = setTimeout("hideMenu();",4000);
		//the following code creates an xoffset for use with a centered page design
		if(is.ns) {
			available_width=innerWidth;
		} 
		else if(is.ie4up) {
			available_width=document.body.clientWidth;
		}
		available_width = available_width - 760;
		xoffset = parseInt(available_width / 2,10);
		
		if (document.getElementById(menu + 'button'))
		{
			document.getElementById(menu + 'button').style.backgroundImage = "url('/mir.wustl.edu/graphics/mir_menubtn_bg.gif')";
		}
		
		if (document.getElementById(menu + 'button2'))
		{
			document.getElementById(menu + 'button2').style.backgroundImage = "url('/mir.wustl.edu/graphics/mir_menubtn_int.gif')";
		}
		
		if (menu.indexOf("sub") == -1)
		{
			menuID = menu.substring(4,menu.length);
//			alert(menuID);
			x = aryMenu[menuID - 1][2];
			y = aryMenu[menuID - 1][3];
		}
		else
		{
			menuID = menu.substring(3,menu.length);
			x = arySub[menuID][3];
			y = arySub[menuID][4];
			if(is.ns4) {
				y = y-4;
			}

		}
		
		if (x == "" || x == null)
			x = 0;
		
		if (y == "" || y == null)
			y = 0;

		if (is.ie4up || is.ns4up)
		{
			myLyr = eval(doc + menu + sty);
			if (myLyr)
			{
				myLyr.top = y + ydiff;
				myLyr.left = x + xdiff + xoffset;
				myLyr.visibility = "visible";
				
			}
		}
	}
	prevMenu = menu;
	
}

function hideSubs()
{
	if (allready) {
	if (is.ie4up || is.ns4up) {
		j = 1
		while (j <= numSubs)
		{
			myLyr = eval(doc + arySub[j][1] + sty);
			myLyr.visibility = "hidden";
			j++;
		}
	}
	}
	return true;
}

function hideMenu()
{
		if (allready) {
			j = 0
			while (j <= numMenus)
			{
				myLyr = eval(doc + aryMenu[j][1] + sty);
				myLyr.visibility = "hidden";				
				if (document.getElementById(aryMenu[j][1] + 'button'))
				{
					document.getElementById(aryMenu[j][1] + 'button').style.backgroundImage = "";
				}
				if (document.getElementById(aryMenu[j][1] + 'button2'))
				{
					document.getElementById(aryMenu[j][1] + 'button2').style.backgroundImage = "";
				}
				j++;
			}
			hideSubs();
		}
		return true;
}

function hideMenuOne(menu)
{
	if (menu != "" && allready) {
		myLyr = eval(doc + menu + sty);
		myLyr.visibility = "hidden";
		if (document.getElementById(menu + 'button'))
		{
			document.getElementById(menu + 'button').style.backgroundImage = "";
		}
		if (document.getElementById(menu + 'button2'))
		{
			document.getElementById(menu + 'button2').style.backgroundImage = "";
		}
	}
	return true;
}

function changeColor(menu,color)
{
	if (allready) {
		menu = menu.id;	
		myLyr = eval(doc + menu + sty);
		myLyr.background = eval(color);
		if (color == "rollColor")
		{
			document.getElementById(menu + "atag").style.color = "white";
		}
		else
		{
			document.getElementById(menu + "atag").style.color = "#6071AE";
		}
	}
}

function changeAColor(menu,color)
{
	if (allready) {
		myLyr = eval(doc + menu + sty);
		myLyr.background = eval(color);
	}
}

function writeMenus()
{
	j = 0;
	while (j <= numMenus)
	{
		document.write("<div name='" + aryMenu[j][1] + "' id='" + aryMenu[j][1] + "' class='menu' ");
		document.write("onMouseOver='showMenu(\"" + aryMenu[j][1] + "\");' ");
		document.write("onMouseOut='hideMenuOne(\"" + aryMenu[j][1] + "\");'>");
		document.write("<TABLE CELLPADDING='0' CELLSPACING='0' BORDER='0' WIDTH='142' class='mainmenu'>");
		k = 4;
		while (k <= (aryMenu[j].length-1))
		{
			document.write("<TR>");
			document.write("<TD class='white' id='" + aryMenu[j][1] + "sub" + k + "' name='" + aryMenu[j][1] + "sub" + k + "' ");
			document.write("onMouseOver='changeColor(this,\"rollColor\");' onMouseOut='changeColor(this,\"baseColor\");'><a id='" + aryMenu[j][1] + "sub" + k + "atag' class='textBlue'");
			strhref = new String(aryMenu[j][k+2]);
			splithref = strhref.split(":new:");
			aryMenu[j][k+2] = splithref[0];
			if (strhref.indexOf(":new:") > 0)
			{
				document.write(" HREF='" + aryMenu[j][k+2] + "' target='_blank'");
			}
			else
			{
				document.write(" HREF='" + aryMenu[j][k+2] + "'");
			}
			
			SubMenuID = parseInt(aryMenu[j][k+1],10);
			if ((SubMenuID > 0) && (SubMenuID != NaN))
			{
				document.write(" onmouseover='hideSubs();");
				document.write(" showMenu(\"" + arySub[SubMenuID][1] + "\",");
				document.write(arySub[SubMenuID][2] + "," + arySub[SubMenuID][3] + ")'");
			}
			else
				document.write(" onmouseover='hideSubs();'");
			document.write(">" + aryMenu[j][k] + "</A></TD></TR>");
			k = k + 3;
		}
		document.write("</TABLE>");
		document.write("</div>");
		j++
	}

	j = 1;
	while (j <= numSubs)
	{
		document.write("<div name='" + arySub[j][1] + "' id='" + arySub[j][1] + "' class='menu'");
		document.write(" onMouseOver='showMenu(\"" + arySub[j][1] + "\"); showMenu(\"menu" + arySub[j][0] + "\");'");
		document.write(" onMouseOut='hideMenu();hideSubs();'>");
		document.write("<TABLE CELLPADDING='0' CELLSPACING='0' BORDER='0' WIDTH='140' class='submenu'>");
		k = 5;
		while (k <= (arySub[j].length-1))
		{
			document.write("<TR>");
			document.write("<TD class='blue' id='" + arySub[j][1] + "sub" + k + "' name='" + arySub[j][1] + "sub" + k + "' ");
			document.write("onMouseOver='changeColor(this,\"rollSubColor\");' onMouseOut='changeColor(this,\"baseSubColor\");'><A class='textBlue'");
			
			strsubhref = new String(arySub[j][k+1]);
			splitsubhref = strsubhref.split(":new:");
			arySub[j][k+1] = splitsubhref[0];
			if (strsubhref.indexOf(":new:") > 0)
			{
				document.write(" HREF='" + arySub[j][k+1] + "' target='_blank'");
			}
			else
			{
				document.write(" HREF='" + arySub[j][k+1] + "'");
			}
			
		//	document.write(" HREF='" + arySub[j][k+1] + "'");
			document.write(">" + arySub[j][k] + "</A></TD></TR>");
			k = k + 2;
		}
		document.write("</TABLE>");
		document.write("</div>");
		j++
	}
}

function makeMenu()
{
	numMenus += 1;
	numItems = arguments.length;
	aryMenu[numMenus] = new Array(numItems-1);
	aryMenu[numMenus][0] = arguments[0]
	aryMenu[numMenus][1] = "menu" + arguments[0]
	j = 2;
	while (j <= arguments.length)
	{		
		aryMenu[numMenus][j] = arguments[j-1];
		j++;
	}
}

function makeSub()
{
	numSubs += 1;
	numItems = arguments.length;
	arySub[numSubs] = new Array(numItems-1);
	arySub[numSubs][0] = arguments[1] //the parent menu ID
	arySub[numSubs][1] = "sub" + arguments[0]
	j = 3;
	while (j <= arguments.length)
	{		
		arySub[numSubs][j] = arguments[j-1];
		j++;
	}
}

function startup()
{
	//Basically determines what Document Object Model to use.
	//Note there is one for Netscape 6 >, and IE 4 >.
	//You can also specify a xdifferency and a ydifference to
	//add to the x and y coordinates (to compensate for browser differences)
	screen_width = screen.width;
	screen_height = screen.height;
	if(is.ns4up) {
		available_width=innerWidth;
		available_height=innerHeight;
	} 
	else if(is.ie4up) {
		available_width=document.body.clientWidth;
		available_height=document.body.clientHeight;
	}
	//alert("Netscape 6!");
	doc = 'document.getElementById("';
	sty = '").style';
	htm = "";
	xdiff = -7;
	ydiff = 10;
	allready = true;
}

//this is for the hp image animation
var num1 = 0;
var num2 = 0;
var num3 = 0;
var num4 = 0;
var totalNews = 0;
function animate()
{
    window.setTimeout('showPic()',500);
    window.setTimeout('showNews()',2000);
    
}
function animateAndShowSurvey()
{
    window.setTimeout('showPic()',500);
    window.setTimeout('showNews()',2000);
    showSurvey();
}

function showSurvey()
{
   
	surveyCounter=getCookie('surveyCounter');
	if (surveyCounter!=null && surveyCounter!="")
	  {
	  if (surveyCounter == '1')
		{
			setCookie('surveyCounter','2',365);
			window.open('survey/survey.asp', 'Survey', 'width=420,height=600,scrollbars=yes');
		}
	  }
	  else 
	  {
		setCookie('surveyCounter','1',365);
		window.open('survey/survey.asp', 'Survey', 'width=420,height=600,scrollbars=yes');
	  }
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function showNews()
{
    num4++;
    if (num4 > totalNews)
        num4 = 1;
    if (num4 > 1)
        Effect.Fade('LeftNews' + (num4 - 1));
    else
        Effect.Fade('LeftNews' + totalNews);
    window.setTimeout("Effect.Appear('LeftNews' + num4);",500);
    window.setTimeout('showNews()',7000);
}
function hideNews()
{
    for (j=2; j<=(totalNews-1); j++)
    {
        document.getElementById('LeftNews' + j).style.display = "none";
    }
    Effect.Fade('LeftNews' + totalNews);
}
function showPic()
{   
    //increment the current pic number
    num1++;
    num2++;
    num3++;
    //if we've shown all 7 pics, reset counter 
    if (num1 > 9) {
        num1 = 1;
        hidePics1();
    }
    else
        Effect.Appear('PatientCare' + num1);
        
    if (num2 > 6) {
        num2 = 1;
        hidePics2();
    }
    else
        Effect.Appear('Education' + num2);
        
    if (num3 > 11) {
        num3 = 1;
        hidePics3();
    }
    else
        Effect.Appear('Research' + num3);
    window.setTimeout('showPic()',4000);
}
function hidePics1()
{
    for (j=2; j<=8; j++)
    {
        document.getElementById('PatientCare' + j).style.display = "none";
    }
    Effect.Fade('PatientCare9');
}
function hidePics2()
{
    for (j=2; j<=5; j++)
    {
        document.getElementById('Education' + j).style.display = "none";
    }
    Effect.Fade('Education6');
}
function hidePics3()
{
    for (j=2; j<=10; j++)
    {
        document.getElementById('Research' + j).style.display = "none";
    }
    Effect.Fade('Research11');
}