var who = null;
sfHover = function()
{
  // skip ie7
  /*if (typeof document.body.style.maxHeight != "undefined")
  {
    return;
  }*/

  var sfEls = document.getElementById('main_menu_top').getElementsByTagName('LI');
  for (var i=0; i<sfEls.length; i++) {
    if (sfEls[i].className != '' && !sfEls[i].className.match("level2"))
    {
      sfEls[i].test = true;
      sfEls[i].timer = null;
      var reg = new RegExp('function.+\n\{\n(.+)\n\}');
      sfEls[i].oldOnmouseover = '';
      sfEls[i].oldOnmouseout = '';
      sfEls[i].unSfHover = function()
      {
        this.test = true;
        this.className = this.className.replace(new RegExp(' sfhover\\b'), '');

        elts = this.getElementsByTagName('a');

        for (z = 0;z < elts.length; z++)
        {
          elt = elts[z];
          if ('level1 sfhover' == elt.className)
          {
            elt.className = elt.className.replace(new RegExp(' sfhover\\b'), '');
          }
        }
        //eval(this.oldOnmouseout);
        clearTimeout(this.timer);
      }

      sfEls[i].onmouseover = function() {
        if (this.test) {
          if (who) who.unSfHover();
          this.className += ' sfhover';

          elts = this.getElementsByTagName('a');

          for (z = 0;z < elts.length; z++)
          {
            elt = elts[z];
            if ('level1' == elt.className)
            {
              elt.className += ' sfhover';
            }
          }
          this.test = false;
          who = this;
        }
        if (this.timer) { clearTimeout(this.timer);}
      }
      sfEls[i].onmouseout = function() {
        eval(this.obj+'=this');
        this.timer = setTimeout(this.obj + '.unSfHover()', 500);
      }
    }
  }

  // hack ie 6 : an iframe is added to pass over the select element
  sfEls = document.getElementById('main_menu_top').getElementsByTagName('UL');
  s = {
		top     : 'auto', // auto == .currentStyle.borderTopWidth
		left    : 'auto', // auto == .currentStyle.borderLeftWidth
		width   : 'auto', // auto == offsetWidth
		height  : 'auto', // auto == offsetHeight
		opacity : true,
		src     : 'javascript:false;'
	};

  for (i = 0; i < sfEls.length;i++)
  {
    if(sfEls[i].className != '' && sfEls[i].className.match("menu_level_2"))
    {
       html = '<iframe class="bgiframe" frameborder="0" tabindex="-1" src="'+s.src+'"'+
        'style="display:block;position:absolute;z-index:-1;'+
        (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
        'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
        'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
        'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
        'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
      '"/>';

      sfEls[i].insertBefore(document.createElement(html), sfEls[i].firstChild);
    }
  }
}

sfHover2 = function()
{
  // skip ie7
  if (typeof document.body.style.maxHeight != "undefined")
  {
    return;
  }

  var sfEls = document.getElementById("main_menu_top").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
	  if (sfEls[i].className != '' && sfEls[i].className.match("level2"))
    {
		  sfEls[i].onmouseover=function() {
  			this.className+=" sfhover2";
  		}
  		sfEls[i].onmouseout=function() {
  			this.className=this.className.replace(new RegExp(" sfhover2\\b"), "");
  			//document.getElementById("searchClass").style.visibility= 'hidden';
  		}
  	}
	}
}

if (window.attachEvent) window.attachEvent('onload', sfHover);
if (window.attachEvent) window.attachEvent('onload', sfHover2);
