/*
	Modified by Andrew Clarke <andrew@clarke.ca>:
		- 2002-08-20
		- 2002-08-23
		- 2002-09-04
		- 2002-09-09 - comment out eval (pref+"Layer3"+suff+".visibility='hidden'"); to keep the spalsh icon visible until you go to another top menu item.  Otherwise it can disappear when you go lower in the existing menu which isn't what we want to happen.
		- 2002-10-28
		- 2002-11-01
*/

var opened=new Array();
var maxlevels=6;
var pref,suff,ie=0;
if (document.all) { pref=""; suff=".style"; ie=1;}
if (document.layers) { pref="document.layers['"; suff="']";}
var ltimer=0;
var lholder=0;
var layer3loaded=0;
var closed=0;

// expander (mid,level,expandaction,hassubmenu,event)
// mid          - MenuID of expanding item (e.g. 'd10', 'd14')
// level        - 1,2,3 - tiers
// expandaction - 1-expand/0-close
// hassubmenu   - 1-has/0-no
// logo         - for 1st level only
// event  - event object from browser

function findObj(n, d) {
  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=findObj(n,d.layers[i].document); return x;
}

/**************/
/* expander() */
/**************/
function expander (mid,level,expandaction,hassubmenu,logo,SplashSubMenuX,SplashSubMenuY,event)
{
	// alert("mid,level,expandaction,hassubmenu,logo,SplashSubMenuX,SplashSubMenuY,event: " + mid + ", " + level + ", " + expandaction + ", " + hassubmenu + ", " + logo + ", " + SplashSubMenuX + ", " + SplashSubMenuY + ", " + event); // debugging
  closed=0;
  if (ltimer) {window.clearTimeout (ltimer); ltimer=0; }
  if (!lholder) {lholder=findObj ("logoholder");}

  // Close all opened layers before
	if (mid > 0) layer1Text.style.visibility="hidden";

  for (i=level;i<maxlevels;i++) {
  	if (opened[i]) {
			eval (pref+"d"+opened[i]+suff+".visibility='hidden'");

			if (ie) {
				eval ("document.id"+opened[i]+".src='/pic/sp.gif'");
			} else {
				x = findObj ("id"+opened[i]);
				if (x) {x.src='/pic/sp.gif';}
			}

			// Comment out the following line because it's hiding the little splash graphic when you click on a submenu.  We want the graphic to stay visible until you go to another top menu item.
			// eval (pref+"Layer3"+suff+".visibility='hidden'");
			opened[i]=0;
    }
  }

  // If menu item contain submenu then make that visible
  if ((hassubmenu) && (expandaction)) {
		eval (pref+"d"+mid+suff+".visibility='visible'");

		if (ie) {
			eval ("document.id"+mid+".src='/pic/_arrow.gif'");
		} else {
			x=findObj ("id"+mid); if (x) {x.src='/pic/_arrow.gif';
		}
	}

	opened[level]=mid;
}

  // For category menu we need to show logo
  if (level==1)
    {
/*    if (!expandaction) {lholder.src='/pic/sp.gif'; }*/
    if ((expandaction) && (logo != '')) {
      eval (pref+"Layer3"+suff+".visibility='hidden'");

      if (SplashSubMenuX==0) {
        if (ie) {
        	ypos=eval ("document.id"+mid+".offsetParent.offsetTop+document.id"+mid+".offsetTop");
        }  else {
        	ypos=event.pageY-20;
        }

        xpos=150+((ypos-220)*(ypos-220))/400;
      } else {
				xpos=SplashSubMenuX; ypos=SplashSubMenuY;
			}

      eval (pref+"Layer3"+suff+".top="+ypos);
      eval (pref+"Layer3"+suff+".left="+xpos);

      if (hassubmenu) {
        eval (pref+"d"+mid+suff+".top="+ (ypos));
        eval (pref+"d"+mid+suff+".left="+(xpos+50));
      }

      lholder.src=logo; // to display the logo
      // alert("logo: " + logo); // debugging
      }
    }
  if (level>1)
    {
    if (hassubmenu)
      {
      if (SplashSubMenuX==0)
        {
        if (ie)
          {ypos=eval ("document.id"+mid+".offsetParent.offsetTop+document.id"+mid+".offsetTop");}
         else {ypos=event.pageY-20; }
        xpos=50+level*125+((ypos-220)*(ypos-220))/480;
    } else {
			xpos=SplashSubMenuX; ypos=SplashSubMenuY;
		}
      eval (pref+"d"+mid+suff+".top="+ (ypos));
      eval (pref+"d"+mid+suff+".left="+(xpos));
	  }
	}
} // end function expander

function none() {}

function hold ()
{
	// alert('hold');
	if (ltimer) {window.clearTimeout (ltimer); ltimer=0;}
	// layer1Text.style.visibility="visible";
}

function closemenu()
{
	if (!closed) {
		// alert('calling expander from closemenu');
		expander (0,1,0,0,'',0,0,0);
		closed=1;
  }
}

function leave()
{
	if (ltimer) {window.clearTimeout (ltimer); }
	ltimer=window.setTimeout ("closemenu()",1000);
}

function logoloaded()
{
	if (!layer3loaded) {if (findObj("Layer3")) {layer3loaded=1;}}

  if (layer3loaded) {
		// alert (lholder.src+' loaded!');
		eval (pref+"Layer3"+suff+".visibility='visible';");
	}
}