var hmenuShow = false;					// variable that tracks if a rollover menu on the home page is showing
var overHMenu = false;					// variable that tracks if the mouse is over a rollover menu on the home page
var popMenus = 18;
var o = false;

/** General Functions for the Search Unit and Hide/Show a layer **************************/

function preLoadMenuImgs() {
	menu_img_names = new Array('hnav_books', 'hnav_office', 'hnav_cds', 'hnav_clothing', 'hnav_art', 'hnav_computers',
   							'hnav_dvd', 'hnav_flowers', 'hnav_food', 'hnav_free', 'hnav_health', 'hnav_home', 'hnav_babies',
   							'hnav_pets', 'hnav_sports', 'hnav_superstores', 'hnav_toys', 'hnav_travel');
	menu_images_on = new Array();
	menu_images_off = new Array();
	for (var i = 1; i <= 18; i++) {
		menu_images_on[i] = new Image();
		menu_images_on[i].src = 'images/' + menu_img_names[i-1] + '_on.gif';
		menu_images_off[i] = new Image();
		menu_images_off[i].src = 'images/' + menu_img_names[i-1] + '.gif';
	}
	var hMenus = true;
	initRelLayers();
}

function hMenuImgOn(index) {
	if ( loaded && rollovers) document.images[index].src = 'images/hnav_'+index+'_on.gif';
}

function hMenuImgOff(index) {
	if ( loaded && rollovers) document.images[index].src = 'images/hnav_'+index+'.gif'	;
}

function overChecker(index) { // this function sets the menuOff function only if the mouse  is considered by browers as a mouseout event) 
   //alert (" overChecker index is " + 'menu'+index);
   o = false;
   menuString = "menuOff('" + index + "')" ;
   //alert ("menu string " + menuString);
	setTimeout(menuString, 500);		
}

function menuOff(index) {						// this function handles the mouseout event from the menu
   
   //alert (" menuOn index is " + 'menu'+index);
   if (!index) return;

	if (o == true) return;
   popLayer('menu'+index,'off');
	hMenuImgOff(index);    // hMenus only use this function
}

function menuOn(index) { 				// this function sets a flag to track if the mouse is over the menu 
   //alert (" menuOn index is " + 'menu'+index);
   o = true;
	turnEmOff(index);
	popLayer('menu'+index, 'on');
	hMenuImgOn(index);	
}


function catMenuOn(index) { 				// this function sets a flag to track if the mouse is over the menu 
   //alert (" catmenuOn index is " + 'menu'+index);
   if( !ns4)
      {
      o = true;
	   
	   popLayer('menu'+index, 'on');
	   	
   } 
   turnEmOff(index);
   hMenuImgOn(index);
}

function turnEmOff(index) {

   for (var i = 0; i < category_names.length; i++) {
   	if (category_names[i] != index) {
         
			popLayer('menu'+category_names[i],'off');
   		hMenuImgOff(category_names[i]);
   	}
   }
}

function initRelLayers() {

    //kr added as per #6 from ht
	for( var x = 0; x < category_names.length; x++ ) 
   {
      //menuOff(category_names[x]);
      turnEmOff(category_names[x]);
   }

	//below the positioning of the rollover are being calculated.	
	for (i = 0; i < category_names.length; i++) 
       { 
		placeRelLayer('hnav1','menu'+category_names[i],70,(i*10)-260);
	   }		
}

function placeRelLayer(relDivId, absDivId, x, y) {
	if (ns4) {
		document.layers[absDivId].left = document.layers[relDivId].pageX + x;
		document.layers[absDivId].top = document.layers[relDivId].pageY + y;
	}
	else if (ie){
		if (mac && !macIE5) {						// Deal with IE 4.x Macs relative layer position.
			shadow = relDivId + "IEMac";			// Since IE4.x doesn't record the offset of a relative layer
			var parent = document.all[shadow];		// create an id for the wrapping element (<td> etc.), take the shadow
			var positionX = 0;						// from that element.  The element must be named 'shadowname'IEMac
			var positionY = 0;
			while (parent != document.body) { 
				positionX += parent.offsetLeft;
				positionY += parent.offsetTop;
				parent = parent.parentElement;				
			}
			document.all[absDivId].style.posLeft = positionX + x;
			document.all[absDivId].style.posTop = positionY + y;
		}
		else {
         //alert(" absDivId " + relDivId);
			document.all[absDivId].style.posLeft = document.all[relDivId].offsetLeft + x;
			document.all[absDivId].style.posTop = document.all[relDivId].offsetTop + y;
		}
	}
	else if (DOM) {
		document.getElementById(absDivId).style.left = document.getElementById(relDivId).offsetLeft + x;
		document.getElementById(absDivId).style.top = document.getElementById(relDivId).offsetTop + y;
		popLayer(absDivId,'on');
		popLayer(absDivId,'off');
	}	

}





function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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.0
  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 && document.getElementById) 
     x=document.getElementById(n); 
  
  return x;
}

// args
//    1.  image name
//    2.  ?
//    3.  swap image name
//    4.  number?
//
//  offset of arg array is 0

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 

  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
      {
      document.MM_sr[j++]=x; 

      if(!x.oSrc) 
         x.oSrc=x.src; 

      x.src=a[i+2];
      }
}


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);



