/* library.js */

var idNavigation = 'topnav';

navHover = function()
{
  var oNav = document.getElementById(idNavigation);
  if(oNav)
  {
    var navEls = oNav.getElementsByTagName('LI');
    for(var i = 0; i < navEls.length; i++)
    {
      navEls[i].onmouseover = function()
      {
        this.className += ' hover';
      }
      navEls[i].onmouseout = function()
      {
        this.className = this.className.replace(new RegExp(' hover\\b'), '');
      }
    }
  }
}

navAccessible = function()
{
  var oNav = document.getElementById(idNavigation);
  if(oNav)
  {
  	var navEls = oNav.getElementsByTagName('A');
  	for (var i = 0; i < navEls.length; i++)
    {
  		navEls[i].onfocus = function()
      {
  			this.className += (this.className.length > 0? ' ' : '') + 'focus'; //a:focus
  			this.parentNode.className += (this.parentNode.className.length > 0 ? ' ': '') + 'hover'; //li < a:focus
  			if(this.parentNode.parentNode.parentNode.nodeName == 'LI')
        {
  				this.parentNode.parentNode.parentNode.className += (this.parentNode.parentNode.parentNode.className.length > 0? ' ': '') + 'hover'; //li < ul < li < a:focus
  				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == 'LI')
  					this.parentNode.parentNode.parentNode.parentNode.parentNode.className += (this.parentNode.parentNode.parentNode.parentNode.parentNode.className.length > 0? ' ': '') + 'hover'; //li < ul < li < ul < li < a:focus
  			}
  		}
  		navEls[i].onblur = function()
      {
  			this.className = this.className.replace(new RegExp('( ?|^)focus\\b'), '');
  			this.parentNode.className = this.parentNode.className.replace(new RegExp('( ?|^)hover\\b'), '');
  			if(this.parentNode.parentNode.parentNode.nodeName == 'LI')
        {
  				this.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.className.replace(new RegExp('( ?|^)hover\\b'), '');
  				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == 'LI')
  					this.parentNode.parentNode.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp('( ?|^)hover\\b'), '');
  			}
  		}
//alert(navEls[i].onfocus + '\n\n' + navEls[i].onblur);
    }
	}
}

// only ie needs the navHover script. all need the accessibility script...
if(window.addEventListener)
  window.addEventListener('load', navAccessible, false); // gecko, safari, konqueror and standard
else if(document.addEventListener)
  document.addEventListener('load', navAccessible, false); // opera 7
else if(window.attachEvent)
{ // win/ie
	window.attachEvent('onload', navHover);
	window.attachEvent('onload', navAccessible);
}
else
{ // mac/ie5
	if(typeof window.onload == 'function')
  {
		var existing = onload;
		window.onload = function()
    {
			existing();
			navHover();
			navAccessible();
		}
	}
  else
  {
		window.onload = function()
    {
			navHover();
			navAccessible();
		}
	}
}

var enableBlockerMessage = true;
var stringBlockerMessage = 'You appear to be using pop-up blocking software.\n\nYou are trying to use a feature of this site that uses a pop-up window.\n\nPlease disable your pop-up blocker or enable pop-ups for this site.';

function newWindow(href, target, width, height)
{
  var returnValue = false;
  var features = (width != null && height != null) ? ((arguments.length == 4) ? 'scrollbars,status,width=' + width + ',height=' + height : ((arguments[4]) ? arguments[4] + ',width=' + width + ',height=' + height : 'width=' + width + ',height=' + height)) : ((arguments.length > 4) ? arguments[4] : null);
  if(width != null && height != null && window.screen)
  {
    var pxLeft = ((screen.availWidth - width - 10) * .5);
    var pxTop = ((screen.availHeight - height - 30) * .5);
    features += ',left=' + pxLeft + ',top=' + pxTop + ',x=' + pxLeft + ',y=' + pxTop;
  }
  if(!window.open)
    returnValue = true;
  else
  {
    if(features != null)
      self[target + 'Win'] = window.open(href, target, features);
    else
      self[target + 'Win'] = window.open(href, target);
    if(!self[target + 'Win'])
    {
      if(enableBlockerMessage) 
        alert(stringBlockerMessage);
      else
        returnValue = true;
    }
    else if(self[target + 'Win'].focus)
      self[target + 'Win'].focus();
  }
  return returnValue;
}

