//Filename:  nav_functions.js
//Website:  Win-Win Workplace Solutions

var delayhide;
var submenu_assoc;  //Boolean to indicate whether the main menu has an associated submenu
var subMenuID;
var subMenuID2;


//Main Menu Button Controls
function menuCtrl(event,grpName,grpSub){
	submenu_assoc = grpSub; //Boolean to indicate whether there is a submenu associated with the button
	if(event == "over"){
		if(submenu_assoc == true){
			clearCloseSubmenu(grpName);  //Cancel hiding the submenu and keep About Us button on "Over" state 
			subMenuID = grpName + "_submenu";
			document.getElementById(subMenuID).style.visibility='visible';  //Show sub menu if not already visible
		}
	}else if(event == "out"){
		if(submenu_assoc == true){
			delayedCloseSubmenu(grpName); //Close Sub Menu and Return Main Button to its regular state after a delay
		}else{
			MM_nbGroup('swap_image',grpName,'');  //Return Main Button with no associated submenu to its regular state
		}
	}
}

//Submenu Button Controls
function subCtrl(event,grpName,grpName2){ 
	if(event == "over"){
		clearCloseSubmenu(grpName2);  //Cancel hiding the submenu and keep the main button in "Over" state
	}else if(event == "out"){
		delayedCloseSubmenu(grpName2);  //Close Sub Menu and Return Main Button to its regular state after a delay
	}
}

function delayedCloseSubmenu(grpName3){
	delayhide = setTimeout(function(){closeSubmenu(grpName3)},10);  	//Execute closeSubmenu after a delay
	subMenuID2 = grpName3;
}

function closeSubmenu(grpName4){
	var subMenuID3;
	subMenuID3 = grpName4 + "_submenu";
	document.getElementById(subMenuID3).style.visibility='hidden';  //Hide Subnenu
	MM_nbGroup('swap_image',grpName4,'');  //Return Main button to its regular state
}

function clearCloseSubmenu(grpName5){
	if(grpName5 == subMenuID2){  //Prevents the delayhide from being canceled when moving from a first menu group (main menu or sub menu) to another menu group
		if(window.delayhide){   
				clearTimeout(delayhide);  //Cancels the delayhide, thereby preventing the submenu from being closed (e.g keep an active submenu on the screen)
		}
	}
}

function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName, grpSub) { //Modified significantly from standard Dreamweaver function
	var i,img,nbArr,args=MM_nbGroup.arguments;
	  if (event == "swap_image") {
		document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=4) if ((img = MM_findObj(args[i])) != null) {  //increment i+ by one for each parameter added to function
			if (!img.MM_up) img.MM_up = img.src;
			img.src = ((args[i+2])? args[i+2] : img.MM_up);  //increment args[i+x] by one for each parameter added to function
			nbArr[nbArr.length] = img;
			}
	 }
}