// JavaScript Document
var subIn = '';
var inItem = '';
var oldSubIn = '';
var oldInItem = '';
var menuTimeout = 0;
var animateTimer = 0;	
var inIframe = 0;
var inIframeSub = 0;

function getRefToDiv(divID) {
    if( document.layers ) { //Netscape layers
        return document.layers[divID]; }
    if( document.getElementById ) { //DOM; IE5, NS6, Mozilla, Opera
        return document.getElementById(divID); }
    if( document.all ) { //Proprietary DOM; IE4
        return document.all[divID]; }
    if( document[divID] ) { //Netscape alternative
        return document[divID]; }
    return false;
}


function startAnimation(thisFunction, divID, upLevelMenu){
 
  // start the correct animation
   switch(thisFunction){
    case "In": 
		
		if(divID == 'registrationMenu' || divID == 'libraryMenu' || divID == 'libraryHoursSubMenu' || divID == 'libraryResourcesSubMenu' || divID == 'courseSubMenu')
		{
			document.getElementById('stateSelectBox').style.display = 'none';	
		}
	  	if(menuTimeout && (divID == inItem || divID == subIn)){ 
		    clearTimeout(menuTimeout);
		}
	   
		
		// initialize global iframe variables
		var frameToIn = 'iFrameBlock';
		var shadowIn = 'menuShadow';
		inIframe = 1;
		
		if(divID != upLevelMenu){
			inIframeSub = 1;
			frameToIn = 'iFrameSub';
			shadowIn = 'subMenuShadow';
		}
		 
			 
	// do a quick removal of the old menu if its still up
	  	if( oldInItem != '' && oldInItem != upLevelMenu){
			inIframe = 0;
			inIframeSub = 0;
			hideMenus();
	  		destroyMenu(oldInItem);
	  	}
		
	  // set the new global variables
	  oldInItem = inItem;
	  oldSubIn = subIn;
	  	inItem = upLevelMenu;
		inIframe = 1;
	    if( upLevelMenu != divID){
	  		subIn = divID;
			inIframeSub = 1;
		}
	
	//  replaced with below so that it delays the in function long enough to be sure
	// the user meant to open the menu
	// inMenu(divID, .25, 5, upLevelMenu, frameToIn, shadowIn);
	  
	 var newFunction =  "inMenu('" + divID + "',.25,5,'" +upLevelMenu + "','" + frameToIn + "','" + shadowIn +"')";
	     animateTimer = setTimeout(newFunction,400);
	
	break;
	
	case "Out":
		oldInItem = inItem;
		oldSubIn = subIn;
		inItem = '';
		subIn = '';
		inIframe = 0;
		inIframeSub = 0;
		document.getElementById('stateSelectBox').style.display = 'inline';
		menuTimeout = setTimeout('hideMenus();',400);
	
	break;
	   
	default: 
		alert('"' + thisFunction + '" is not a valid menu function');
	break;
	}
	
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function inMenu(myelement, increment, transition, upLevelMenu, iframe, inShadow)
{


// set our menu to a variable 
var s = getRefToDiv(myelement);		
var i = getRefToDiv(iframe);
var shadow = getRefToDiv(inShadow);

		
// transition in everything 
if (s.style.display != 'inline' && (myelement == inItem || myelement == subIn)){
	i.style.display = 'none';
	i.style.height="1px";
	i.style.width="1px";
	i.style.filter = "";
	/*
	shadow.style.display = 'none';
	shadow.style.height="1px";
	shadow.style.width="1px";
	shadow.style.filter = "";
	*/
		
		//set the transition
	
	// the fade filter
	/*
	shadow.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=" + increment + ",slideStyle=push,bands=0)";
	*/
	s.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=" + increment + ",slideStyle=push,bands=0)";
	i.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=" + increment + ",slideStyle=push,bands=0)";
	
	// the reveal trans filter set in menucontent
	//s.style.filter = "revealTrans(duration=" + increment + ",transition=" + transition + ")";
	//i.style.filter = "revealTrans(duration=" + increment + ",transition=" + transition + ")";
	
	// run the transition
	
	if (document.all && s.filters){
	//s.filters[0].apply();
	//shadow.filters[0].apply();
	i.filters[0].apply();
	}
	s.style.display = "inline"; 
	
	// move the shadow into place
	/*
	shadow.style.height = parseInt(s.style.height)  + 'px';
	shadow.style.width = parseInt(s.style.width) + 'px';
	shadow.style.left = findPosX(s)+5;
	shadow.style.top = findPosY(s)+5;
	shadow.style.display = "inline"; 
	*/
	// move the blank iframe into its place
	i.style.height = parseInt(s.style.height) + 'px';
	i.style.width = parseInt(s.style.width) + 'px';
	i.style.left = findPosX(s);
	i.style.top = findPosY(s);
	//i.style.display = "inline"; 
	
	if (document.all && s.filters){
	//s.filters[0].play();
	//shadow.filters[0].play();
	i.filters[0].play();
	
	}
}
		
}

function hideMenus(){
	
	if( inIframe == 0){
		getRefToDiv('iFrameBlock').style.height = '0px';
		getRefToDiv('iFrameBlock').style.display = 'None';
		getRefToDiv('menuShadow').style.height = '0px';
		getRefToDiv('menuShadow').style.display = 'None';
	
		
	}
	if( inIframeSub == 0){
		getRefToDiv('iFrameSub').style.height = '0px';
		getRefToDiv('iFrameSub').style.display = 'None';
		getRefToDiv('subMenuShadow').style.height = '0px';
		getRefToDiv('subMenuShadow').style.display = 'None';
		
	}
	if( inItem != 'donateMenu'){
		destroyMenu('donateMenu');
	}
	if( inItem != 'internationalProgramsMenu'){
		destroyMenu('internationalProgramsMenu');
	}
	if( inItem != 'researchMenu'){
		destroyMenu('researchMenu');
	}
	if( inItem != 'registrationMenu'){
		destroyMenu('registrationMenu');
	}
	if( inItem != 'outreachMenu'){
		destroyMenu('outreachMenu');
	}
	if( inItem != 'vcMenu'){
		destroyMenu('vcMenu');
	}
	if( inItem != 'infoMenu'){
		destroyMenu('infoMenu');
	}
	if( inItem != 'libraryMenu'){
		destroyMenu('libraryMenu');
	}
	if( inItem != 'homelandSecurityMenu'){
		destroyMenu('homelandSecurityMenu');
	}
	if( inItem != 'corporateRelationsMenu'){
		destroyMenu('corporateRelationsMenu');
	}
	if( subIn != 'courseSubMenu'){
		destroyMenu('courseSubMenu');
	}
	if( subIn != 'libraryHoursSubMenu'){
		destroyMenu('libraryHoursSubMenu');
	}
	if( subIn != 'libraryResourcesSubMenu'){
		destroyMenu('libraryResourcesSubMenu');
	}
	if( subIn != 'IndustrialForumSubMenu'){
		destroyMenu('IndustrialForumSubMenu')	
	}

}
function hideAllMenus(){
	
 subIn = '';
 inItem = '';
 oldSubIn = '';
 oldInItem = '';
 menuTimeout = 0;
 animateTimer = 0;
 inIframe = 0;
 inIframeSub = 0;

		destroyBackground();
	
		destroyMenu('courseSubMenu');
		destroyMenu('donateMenu');
		destroyMenu('internationalProgramsMenu');
		destroyMenu('registrationMenu');
		destroyMenu('outreachMenu');
		destroyMenu('vcMenu');
		destroyMenu('infoMenu');
		destroyMenu('corporateRelationsMenu');
		destroyMenu('homelandSecurityMenu');
		destroyMenu('libraryHoursSubMenu');
		destroyMenu('libraryResourcesSubMenu');
		destroyMenu('libraryMenu');
		destroyMenu('researchMenu');

}

function destroyBackground(){
		getRefToDiv('iFrameBlock').style.height = '0px';
		getRefToDiv('iFrameBlock').style.display = 'None';
		getRefToDiv('menuShadow').style.height = '0px';
		getRefToDiv('menuShadow').style.display = 'None';
		getRefToDiv('subMenuShadow').style.height = '0px';
		getRefToDiv('subMenuShadow').style.display = 'None';
		getRefToDiv('iFrameSub').style.height = '0px';
		getRefToDiv('iFrameSub').style.display = 'None';	
}

function destroyMenu(menu){
		
		var s = getRefToDiv(menu);
		s.style.display = 'None';
}

function highlight(divID, changeColor){
	var s = getRefToDiv(divID);
	s.style.backgroundColor =  'ABBCA9';
	s.style.borderColor = '002A00';
	
	if( -1 != navigator.userAgent.
      indexOf ("MSIE") )
  {
    // IE Size
    s.style.height = '25px';
  }
  else
  {
    // Mozilla Size, stupid hacks
    s.style.height = '20px';
  }
	s.style.color = '000000';

	s.style.borderWidth = '1px';
	s.style.paddingTop = '3px';
	s.style.marginLeft = '0px';
}
function unHighlight(divID, changeColor){
	var s = getRefToDiv(divID);
	s.style.backgroundColor =  '';
	s.style.borderColor = '';
	s.style.borderWidth = '0px';
	s.style.color = '000000';
	s.style.height = '25px';
	s.style.marginTop = '0px';
	s.style.paddingTop = '4px';
	s.style.marginLeft = '1px';
}
