/* ================================================================ 
This copyright notice must be kept untouched in the stylesheet at 
all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/menu/pro_drop_1.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */
function isIE_mdd(ver)
{
  var res = false;
  if( Prototype.Browser.IE )
  {
    if( /MSIE (\d+\.\d+);/.test(navigator.userAgent) )  //test for MSIE x.x;
    { 
      var nav_ver=new Number(RegExp.$1) // capture x.x portion and store as a number
      var ver_sup = Math.floor(parseFloat(nav_ver))+1;
      if( typeof(ver) == 'undefined' ) res = true;
      else if( ver >= nav_ver && ver < ver_sup ) res = true;
    }
  }
  return res;
}
function detectDoctype(){
  var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
  var res=false;
 /*********************************************
    Just check for internet explorer.
  **********************************************/
  if(typeof document.namespaces != "undefined")
    res=document.all[0].nodeType==8 ? re.test(document.all[0].nodeValue) : false;
  else
    res=document.doctype != null ? re.test(document.doctype.publicId) : false;
  if(res){
    res=new Object();
    res['xhtml']=RegExp.$1;
    res['version']=RegExp.$2;
    res['importance']=RegExp.$3;
    return res;
  }else{
    return null;
  }
}
/*
var myversionInfo=detectDoctype();
if(myversionInfo != null){
    alert(myversionInfo.xhtml);
    alert(myversionInfo.version);
    alert(myversionInfo.importance);
}
else{
    alert("There is no DOCTYPE in the code!");
}
*/
if(typeof Prototype=='undefined')
{
  var scripts = document.getElementsByTagName("script");
  for(var i = 0 ; i < scripts.length ; i++ )
  {
    var s = scripts[i];
    if(s.src && s.src.match(/stuHover\.js(\?.*)?$/))
    {
      var path = s.src.replace(/stuHover\.js(\?.*)?$/,'');
      var include = '../../scriptaculous-js/lib/prototype';
      document.write('<script type="text/javascript" src="'+path+include+'.js'+'"><\/script>');
      break;
    }
  }
}

detectBorder = function()
{
  var sub = $(this).next('ul');
  if( typeof(sub) != 'undefined' && !sub.hasClassName('sub') )
  {
    sub.setStyle({'left': '200px'})
    var left = Number(sub.getStyle('left').replace(new RegExp("px\\b"), ""));
    var width = 200 + (2*3); //sub.getWidth();
    var wBody = $$('body').first().getWidth();
    var offsetLeft = sub.cumulativeOffset().left;
    var diff = wBody - (offsetLeft + width);
    if( diff < 0 ) sub.setStyle({'left': (left-(2*(width-3)))+'px'})
  }
}
menuHoriz = function(idMenuDropDown) {
  var el,w=5;
  $$("#"+idMenuDropDown+" li.top").each(function(el)
  {
    w+= $(el).getWidth();
  });
  if(el=$(idMenuDropDown))el.setStyle({width:w+'px'});
  /*
  $$("#"+idMenuDropDown+" li a").each(function(el)
	{
    var sub = $(el).next('ul');
	  if( (typeof(sub) != 'undefined') && !sub.hasClassName('sub'))
    {
      Event.observe( el, "mouseover", detectBorder, true ) ;
	  }
	});
	/**/
} 

stuHover = function() {
  if( typeof(Prototype) != 'undefined' && (isIE_mdd(6) || !detectDoctype() ) )
  {
  	$$("ul.menuDropDown li").each(function(el)
  	{
  		el.onmouseover = function() {
        $(this).addClassName('iehover');
      	$(this).getElementsBySelector('a').each(function(el) {
          el.onmouseover = function () { $(this).addClassName($(this).hasClassName('fly')?'fly_iehover':'iehover'); }
        });
  		}
  		el.onmouseout = function() {
  			$(this).removeClassName('iehover');
      	$(this).getElementsBySelector('a').each(function(el) {
          el.onmouseout = function () {$(this).removeClassName($(this).hasClassName('fly')?'fly_iehover':'iehover'); }
        });
  		}
    });
  }
}

loadMenuDropDown = function()
{
  stuHover();
  menuHoriz('menuNav');
  //menuHoriz('menuNavIntranet');
}

if (window.attachEvent) {
  window.attachEvent("onload", loadMenuDropDown);
}
else Event.observe( window, "load", loadMenuDropDown, true ) ;
