/******************************************************************************
 * Name:		menu_lib.js
 * Version:		1.0.2
 * Author:		Hayes Consulting
 * Created:		14-Jan-2005
 * ---------------------------------------------------------------------------
 *
 * Purpose: 
 *   Resource library for navigation menu bar and pop-menu functionality
 *
 * Usage:
 *   N/A
 *
 *
 * Change Record:
 * ---------------------------------------------------------------------------
 * <Who>		        <When>			    <What>
 * ---------------------------------------------------------------------------
 *
 *****************************************************************************/


/**************************************************************
 * Name:        P7_autoLayers() 
 * Author:      www.projectseven.com
 * Purpose:     Sets visibility of DHTML layers
 * Accepts:     See P7 documentation
 * Returns:     Nothing
 **************************************************************/
function P7_autoLayers() { //v1.2 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;
 var a = parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc) {p7c=new Array();document.p7setc=true;
  for (var u=0;u<10;u++) {p7c[u] = new Array();}}
 for(k=0; k<p7c[a].length; k++) {
  if((g=MM_findObj(p7c[a][k]))!=null) {
   b=(document.layers)?g:g.style;b.visibility="hidden";}}
 for(k=1; k<args.length; k++) {
  if((g=MM_findObj(args[k])) != null) {
   b=(document.layers)?g:g.style;b.visibility="visible";f=false;
   for(j=0;j<p7c[a].length;j++) {
    if(args[k]==p7c[a][j]) {f=true;}}
  if(!f) {p7c[a][p7c[a].length++]=args[k];}}}
} //end ()

/**************************************************************
 * Name:      P7_ReDoIt()
 * Author:    www.projectseven.com
 * Purpose:   Sets reload preference
 * Accepts:   Nothing
 * Returns:   Nothing
 **************************************************************/
function P7_ReDoIt() { //v1.21 by PVII
 if(document.layers) {MM_reloadPage(false);}
} //end ()

/**************************************************************
 * Name:      P7_Snap()
 * Author:    www.projectseven.com
 * Purpose:   "Snaps" one or more layers into a specified 
 *            position on the page
 * Accepts:   See P7 documentation
 * Returns:   Nothing
 **************************************************************/
function P7_Snap() { //v2.62 by PVII
  var x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,args=P7_Snap.arguments;a=parseInt(a);
  for (k=0; k<(args.length-3); k+=4)
   if ((g=MM_findObj(args[k]))!=null) {
    el=eval(MM_findObj(args[k+1]));
    a=parseInt(args[k+2]);b=parseInt(args[k+3]);
    x=0;y=0;ox=0;oy=0;p="";tx=1;da="document.all['"+args[k]+"']";
    if(document.getElementById) {
     d="document.getElementsByName('"+args[k]+"')[0]";
     if(!eval(d)) {d="document.getElementById('"+args[k]+"')";if(!eval(d)) {d=da;}}
    }else if(document.all) {d=da;} 
    if (document.all || document.getElementById) {
     while (tx==1) {p+=".offsetParent";
      if(eval(d+p)) {x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
      }else{tx=0;}}
     ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);var tw=x+ox+y+oy;
     if(tw==0 || (navigator.appVersion.indexOf("MSIE 4")>-1 && navigator.appVersion.indexOf("Mac")>-1)) {
      ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);
      }else{var w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;
      a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
      x=document.body.scrollLeft + event.clientX + bx;
      y=document.body.scrollTop + event.clientY;}}
   }else if (document.layers) {x=g.x;y=g.y;var q0=document.layers,dd="";
    for(var s=0;s<q0.length;s++) {dd='document.'+q0[s].name;
     if(eval(dd+'.document.'+args[k])) {x+=eval(dd+'.left');y+=eval(dd+'.top');break;}}}
   if(el) {e=(document.layers)?el:el.style;
   var xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
   if(navigator.appName=="Netscape" && parseInt(navigator.appVersion)>4){xx+="px";yy+="px";}
   if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
    xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);
    xx+="px";yy+="px";}e.left=xx;e.top=yy;}}
} //end ()

/**************************************************************
 * Name:      doMenu()
 * Author:    Hayes Consulting
 * Purpose:   Sets up top menu bar image elements and the menu
 *            (layer) itself, according to current menu target
 *            and the current site sub-section    
 *              1) Set image for right neighbor  
 *              2) Set image for active menu/section button
 *              3) Set shadow image, connecting to sub-menu
 *              4) Place and make visible the menu layers
 *
 * Accepts:   String - menu item (eg, 'company' or 'news')
 *                     This is the current menu item that is
 *                     or would be clicked.
 * Returns:   Nothing
 **************************************************************/
function doMenu(menuItem) {
    var ssStr;
    menuItem = menuItem.toLowerCase();

    //first reset all menu items
    resetNavMenu();

    //check for sub-section global variable
    if(document.subSection == null || 
       document.subSection == "") {
      alert("ERROR - Variable \'subSection\' not set for current page");
      return;
    } else {
        ssStr = document.subSection.toLowerCase();
    }

    if(menuItem == ssStr) {
        // menu item is current sub-section,
        // don't pop the menu up, etc.
        doSubSection('on');
    } else {
        //set image source for all relevant items
        setNavButNeighbor(menuItem,'on');
        setSubSectNavBut(menuItem,'on');
        setSubSectShadow(menuItem,'off');

        //position menu layers
        if(menuItem == 'company') {
            P7_Snap('menu_company'
                   ,'closer_company',-20,20
                   ,'menu_company'
                   ,'drop_company',-22,20);            
        } else {
            P7_Snap('menu_'  +menuItem
                   ,'closer_' +menuItem,-10,20
                   ,'menu_'  +menuItem
                   ,'drop_'   +menuItem,0,20);
        }

        //set layer visibility
        P7_autoLayers(0,'drop_' +menuItem,'closer_' +menuItem);
    }
} //end ()


/**************************************************************
 * Name:      doSubSection()
 * Author:    Hayes Consulting
 * Purpose:   Sets up top nav bar image elements according to 
 *            current site sub-section    
 *              1) Set image for right neighbor  
 *              2) Set image for active menu/section button
 *              3) Set shadow image, connecting to sub-menu
 *
 * Accepts:   String - state to set. Range is: ('on'|'off')
 * Returns:   nothing
 **************************************************************/
function doSubSection(s) {
    //get current sub-section numeric value
    //var ss = mapSS();
    var state = s.toLowerCase();
    var ssStr = 'home';
    if(document.subSection != null && document.subSection != "") {
      ssStr = document.subSection.toLowerCase();
    }

    setNavButNeighbor(ssStr,state);
    setSubSectNavBut(ssStr,state);
    setSubSectShadow(ssStr,state);
} //end ()

/**************************************************************
 * Name:      setSubSectNavBut() 
 * Author:    Hayes Consulting
 * Purpose:   Sets the image source for the navigation button
 *            image corresponding with the sub-section name
 *            that is passed-in.
 *            
 * Accepts:   String -- Name of site sub-section
 *            String -- Sub-section menu state ('on'|'off')
 * Returns:   Nothing
 **************************************************************/
function setSubSectNavBut(ss,state) {
    if(ss == 'home') {return;}
    if(state == 'on') {
        MM_swapImage('menu_' + ss,'','hnav_images/menu_' + ss +'_h.gif',1);
    } else {
        MM_swapImage('menu_' + ss,'','hnav_images/menu_' + ss +'.gif',1);
    }
} //end ()

/**************************************************************
 * Name:      setNavButNeighbor() 
 * Author:    Hayes Consulting
 * Purpose:   Sets the image source for the image immediately
 *            to the right of the sub-section image corresponding
 *            to the sub-section name passed in.
 *            
 * Accepts:   String -- Name of site sub-section
 *            String -- Sub-section menu state ('on'|'off')
 * Returns:   Nothing
 **************************************************************/
function setNavButNeighbor(ss,state) {
    if(ss == 'home') {return;}
    var target = getNeighbor(ss);
    if(state == 'on') {
        MM_swapImage('menu_' + target,'','hnav_images/menu_' + target +'_l.gif',1);
    } else {
        MM_swapImage('menu_' + target,'','hnav_images/menu_' + target +'.gif',1);
    }
} //end ()

/**************************************************************
 * Name:      setSubSectShadow() 
 * Author:    Hayes Consulting
 * Purpose:   Sets the image source for the shadow image 
 *            running underneath the top navigation bar
 *            
 * Accepts:   String -- Name of site sub-section
 *            String -- Sub-section menu state ('on'|'off')
 * Returns:   Nothing
 **************************************************************/
function setSubSectShadow(ss,state) {
    if(ss == 'home') {return;}
    if(state == 'on') {
        MM_swapImage('shadow','','hnav_images/sectionShadow_' + ss +'.gif',1);
    } else {
        MM_swapImage('shadow','','hnav_images/shadow_clear.gif',1);
    }
} //end ()

/**************************************************************
 * Name:      getNeighbor() 
 * Author:    Hayes Consulting
 * Purpose:   Returns name of section (navigation button)
 *            righthand "neighbor" button in the top navigation
 *            bar
 *            
 * Accepts:   String -- Name of a site sub-section
 * Returns:   String -- Name of righthand neighbor
 **************************************************************/
function getNeighbor(section) {
    switch (section) {
    case 'products' :
        return 'solutions';
    case 'solutions' :
        return 'services';
    case 'services' :
        return 'sales';
	case 'sales' :
        return 'partners';
    case 'partners' :
       return 'news';
    case 'news' :
	    return 'company';
    case 'company' :
		return 'none';
    default :
        return null;
    }
} //end ()

/**************************************************************
 * Name:      resetNavMenu() 
 * Author:    Hayes Consulting
 * Purpose:   Hides all menu layers and resets all navigation 
 *            buttons to their "up" or "off" state
 *            
 * Accepts:   Nothing
 * Returns:   Nothing
 **************************************************************/
function resetNavMenu() {
    //retract all layers
    P7_autoLayers(0);
    //reset all buttons to up state
    MM_swapImage('menu_products','','hnav_images/menu_products.gif',
                 'menu_solutions','','hnav_images/menu_solutions.gif',
                 'menu_services','','hnav_images/menu_services.gif',
				 'menu_sales','','hnav_images/menu_sales.gif',
				 'menu_partners','','hnav_images/menu_partners.gif',
                 'menu_news','','hnav_images/menu_news.gif',
                 'menu_company','','hnav_images/menu_company.gif',1);
} //end ()

//end of file
