
function btnOn() 
  {
    var srcString = this.src
    srcString = srcString.replace(/.gif/,'_over.gif')
    this.src = srcString
  }
function btnOff() 
  {
    var srcString = this.src
    srcString = srcString.replace(/_over.gif/,'.gif')
    this.src = srcString
  }  

var theme_aqch1 = new Object()

theme_aqch1.navCells = document.getElementById('mainnav').getElementsByTagName('TD');

/* This main nav is a little more complicated than normal since we're adding event handlers to the 
   TDs surrounding the links (in order to be able to vertically center the links) */


theme_aqch1.navOn = function ()
  {
    theme_aqch1.hideMenus(); 
    clearTimeout(theme_aqch1.menutimer); //prevents menu from disappearing once we move onto it
    if(this.hasSubMenu)
      {      
        
        this.position = getObjPosition(this)
        if(this.offsetWidth) {this.submenu.style.width = this.offsetWidth + 'px'} //make menu same width as highlighted area
        
        if(this.offsetHeight) {this.submenu.style.top = (this.offsetHeight + this.position.y) + 'px'}
        else {this.submenu.style.top = '186px';} //two different paths to hopefully the same value
        this.submenu.style.left = this.position.x + 'px';         
        this.submenu.style.zIndex = 200;
        this.submenu.style.display = 'block';         
      }
    addClass(this,"navOn")
  }
  
//since we're using the TD as the link, we need to make it behave like a the link within.  
theme_aqch1.followLink = function ()
  {
    window.location = this.firstChild.href;
  }
  
  
theme_aqch1.hideMenus = function()
  {   
     for (lk = 0 ;lk < theme_aqch1.navCells.length; lk++)
      {
         theme_aqch1.navCells[lk].className = theme_aqch1.navCells[lk].className.replace(/ ?navOn/, "");
         if (theme_aqch1.navCells[lk].hasSubMenu) {theme_aqch1.navCells[lk].submenu.style.display = 'none' }
      }     
  }

//Hide the menu -- after a delay.      
theme_aqch1.setHideMenus = function()
{
 theme_aqch1.menutimer = setTimeout(theme_aqch1.hideMenus,theme_aqch1.menuDelay)
}
  
  
theme_aqch1.initNav = function()
  {
    var thisCell
    
    this.secondarynav = document.getElementById("menus");
    if (this.secondarynav != null) {this.submenus = this.secondarynav.getElementsByTagName('DIV')}
    this.menuDelay = 500; //ms
    this.menutimer;       
      
    for (var i = 0, navlen = theme_aqch1.navCells.length;  i < navlen; i++)
      {
        thisCell = this.navCells[i]
        thisCell.submenu = document.getElementById(thisCell.id.replace(/mn/,'sn'))
        thisCell.hasSubMenu = thisCell.submenu != null
        if(thisCell.hasSubMenu)
          {
            thisCell.submenu.onmouseover = function(){clearTimeout(theme_aqch1.menutimer)} ;  
            thisCell.submenu.onmouseout = theme_aqch1.setHideMenus ; 
          }
        
        thisCell.onmouseover = this.navOn;
        thisCell.firstChild.onmouseover = function(){clearTimeout(theme_aqch1.menutimer)} ; //mousing over the actual link (the TD's firstChild) can be seen as the same as mousing out of the surrounding TD, so we need to stop the menu from going away. 
        thisCell.onmouseout = this.setHideMenus;
        thisCell.onclick = this.followLink;        
      }
  }
  
theme_aqch1.initFormFields = function()
  {

    var formfields = [ {fm:document.searchform, fld:'search_string',ds:'Search Site'}]    
    var selectedForm,formfield;
    
    for (var bt = 0; bt < formfields.length; bt++)
      {
        selectedForm = formfields[bt].fm;
        if (selectedForm)
          {
            formfield = selectedForm.elements[formfields[bt].fld]
            if (formfield)
              {
                formfield.label = document.getElementById('lbl_' + formfield.id)
                if(formfield.label)
                  {
                    formfield.defaultString = formfield.label.firstChild.nodeValue;
                    formfield.label.style.display = 'none'
                  }
                else {formfield.defaultString = formfields[bt].ds;}
                
                formfield.onfocus = function(){if(this.value == this.defaultString) {this.value = '' }}
                formfield.onblur = function(){if(this.value == '') {this.value = this.defaultString }};
                formfield.onblur()  
              } //end, formfield exists
          } //end, if selected form
      } //end, for
  
  
  }//end, initFormFields
  
  
//shop by form event handlers
theme_aqch1.handleShopBy = function()
  {
    var targetOption = this.options[this.selectedIndex]
    var targetId = targetOption.value
    var rw = this.form.rw.value == 'true'
    var targetText = encodeURIComponent(targetOption.text.replace(/-/g,'')) + '/';
    if(targetId == '') return false
   
    if(rw)
      {
        if(this.id == 'shopbygroup') {var destination = '/category/' + targetText + targetId}
        else {var destination = '/manufacturer/' + targetText + targetId}
      }
    else
      {
        if(this.id == 'shopbygroup') {var destination = '/group.cfm?gid=' + targetId}
       else {var destination = '/manufacturer.cfm?mfid=' + targetId}
      }
    
    window.location = destination;
  }
 
//Not currently needed by this theme, but leaving in place, just in case.  
theme_aqch1.initShopBy = function()
  {
    if(document.getElementById('shopbygroup')){document.getElementById('shopbygroup').onchange = this.handleShopBy}
    if(document.getElementById('shopbybrand')){document.getElementById('shopbybrand').onchange = this.handleShopBy}
  } 
  
theme_aqch1.initialize = function()
  {
    if (!(document.getElementById && document.getElementsByTagName && document.createElement)) {return false}
    
    this.initNav();
    this.initFormFields()
    this.initShopBy()
  }

window.postAJAXfn = function() {theme_aqch1.initialize()};
theme_aqch1.initialize()

