
//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------


function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_openWindow(theURL,winName,launchWin,features) { //v1.0
  if (launchWin == ''){
    window.open(theURL,winName,features);
  }
  else{
    var controller = window.open(theURL,winName,features);
    if (controller.opener == null){
      controller.opener = self;
    }
    controller.opener.name = launchWin;
    return controller;
  }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
 // var btnX = getPosition(args[0]).x;
 // var btnY = getPosition(args[0]).y;
  for (i=0; i<(args.length-2); i+=3) {
  	if ((obj=MM_findObj(args[i]))!=null) { 
		v=args[i+2];
    	if (obj.style) { 
			obj=obj.style; 
			v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		}
    	obj.visibility=v; 
		//obj.left = btnX + 'px';
		//obj.top = btnY + 48 + 'px';
	}
  }
}

function P7_OpResizeFix(a) { //v1.1 by PVII
if(!window.opera){return;}if(!document.p7oprX){
 document.p7oprY=window.innerWidth;document.p7oprX=window.innerHeight;
 document.onmousemove=P7_OpResizeFix;
 }else{if(document.p7oprX){
  var k=document.p7oprX-window.innerHeight;
  var j=document.p7oprY - window.innerWidth;
  if(k>1 || j>1 || k<-1 || j<-1){
  document.p7oprY=window.innerWidth;document.p7oprX=window.innerHeight;
  location.reload();}}}
}
P7_OpResizeFix();

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Dept_Forms_Cancel_Clicked() {
	window.location="http://www.hhp.umd.edu/dpch/people/faculty.html";
}

function getElementPosition(theElement){  
	var posX = 0;  var posY = 0;               
	while(theElement != null){    
		posX += theElement.offsetLeft;    
		posY += theElement.offsetTop;    
		theElement = theElement.offsetParent;  
	}                        		         

	return {x:posX, y:posY};
}

function getPosition(elementId) {

var element = document.getElementById(elementId);
var left = 0;
var top = 0;

if (element != null)
{
    // Try because sometimes errors on offsetParent after DOM changes.
    try
    {
        while (element.offsetParent)
        {
            // While we haven't got the top element in the DOM hierarchy
            // Add the offsetLeft
            left += element.offsetLeft;
            // If my parent scrolls, then subtract the left scroll position
            if (element.offsetParent.scrollLeft) {left -= element.offsetParent.scrollLeft; }

            // Add the offsetTop
            top += element.offsetTop;
            // If my parent scrolls, then subtract the top scroll position
            if (element.offsetParent.scrollTop) { top -= element.offsetParent.scrollTop; }

            // Grab
            element = element.offsetParent;
        }
    }
    catch (e)
    {
        // Do nothing
    }

    // Add the top element left offset and the windows left scroll and subtract the body's client left position.
    left += element.offsetLeft + document.body.scrollLeft - document.body.clientLeft;

    // Add the top element topoffset and the windows topscroll and subtract the body's client top position.
    top += element.offsetTop + document.body.scrollTop - document.body.clientTop;
}
return {x:left, y:top};
}

function MM_HideMenu(id)
{
	document.getElementById(id).style.visibility = 'hidden';
}

function changeImg(id, highlight) 
{
	var obj = document.getElementById(id+'img');
	if (highlight) 
	{	
		obj.src = "../image/"+id+"blue.gif";
	} else {
		
	}
	obj.src = "../image/"+id+"blue.gif";
}

function changeRotateImg(num)
{
	var obj = document.getElementById("rotateImg");
	obj.src = "images/home-rotate/ImageRotate-" + num + ".jpg";
}

function findPosX(obj)
  {
    var curleft = 0;
	
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function initMenu()
{
	var aboutBtn = document.getElementById("aboutBtn");
	var aboutPosX = findPosX(aboutBtn);
	var peopleBtn = document.getElementById("peopleBtn");
	var peoplePosX = findPosX(peopleBtn);
	var ugradBtn = document.getElementById("ugradBtn");
	var ugradPosX = findPosX(ugradBtn);
	var gradBtn = document.getElementById("gradBtn");
	var gradPosX = findPosX(gradBtn);
	var researchBtn = document.getElementById("researchBtn");
	var researchPosX = findPosX(researchBtn);
	var menu = document.getElementById("topmenu");
	var menuPosX = findPosX(menu);
	var menuPosY = findPosY(menu);
	var homeBtn = document.getElementById("homeBtn");
	var homePosX = findPosX(homeBtn);
	var searchX = homePosX + 770;
	
	document.getElementById("flypch").style.left = aboutPosX.toString() + "px";
	//document.getElementById("flypch").style.top = (aboutPosY + 48).toString() + "px";
	document.getElementById("flypeople").style.left = peoplePosX.toString()  + "px";
	//document.getElementById('flypeople').style.top = (menuPosY + 48).toString() + 'px';
	document.getElementById("flyundergrad").style.left = ugradPosX.toString() + "px";
	//document.getElementById('flyundergrad').style.top = (menuPosY + 48).toString() + 'px';
	document.getElementById("flygraduate").style.left = gradPosX.toString() + "px";
	//document.getElementById('flygraduate').style.top = (menuPosY + 48).toString() + 'px';
	document.getElementById("flyresearch").style.left = researchPosX.toString() + "px";
	//document.getElementById('flyresearch').style.top = (menuPosY + 48).toString() + 'px';
	document.getElementById("hidea").style.left = (menuPosX + 15).toString() + "px";
	document.getElementById("hidea").style.top = (menuPosY + 48).toString() + "px";
	document.getElementById("hideb").style.left = (menuPosX + 115).toString() + "px";
	document.getElementById("hidec").style.left = menuPosX.toString() + "px";
	document.getElementById("hided").style.left = (menuPosX + 975).toString() + "px";

	document.getElementById("search").style.left = searchX.toString() + "px";
}

