/*
Author: Michiel van der Blonk
Date: Jun 15, 2005
Description: Navigation helper for IE 5.5+
	1.On mouseover, add hover class to all LI tags in the menu
	2.On onmouseout, remove hover class
	In effect you can then use a style sheet to define unhovered
	list items to be hidden.
	A special case is taken in consideration for SELECT tags.
	These are always on top of any element in IE, and can only
	be hidden by superimposing an IFRAME tag.
Caveats: The UL element has to be the menu. Do not use a containing DIV,
or change the code in that case.
Copyright: This script is a modified version from a script by Tanny O'Hally
Based on HTML for Suckerfish dropdowns
*/

var hideSelectTags = false;

/**
* @Date: Jun 15, 2005
* @Description: on load of window, this function adds hover capability for LI tags in IE
**/
startList = function(){
	// check current environment
    isIE = navigator.userAgent.toLowerCase().match(/msie 5.5/i);
    isIE = isIE || navigator.userAgent.toLowerCase().match(/msie 6/i);
	var supportsID = (document.getElementById)?true:false;
	var menuName = "navlist";
	var iframeCode = '<iframe id="menushim" src="about:blank" scrolling="no" frameborder="0" style="position:absolute;display:none;margin:0;padding:0;border:none"></iframe>';

	// document.all checks for IE. Al other browsers are OK
	if (isIE && supportsID)
	{
		// Add a shim to hide select items for drop down menus.
		window.navlist.innerHTML=(iframeCode + window.navlist.innerHTML);
		var sfEls = document.getElementById(menuName).getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++)
		{
			sfEls[i].onmouseover=function()
			{
					this.className+=" over";
					if (hideSelectTags)
						hideDropdowns(this.getElementsByTagName("ul")[0],true);
			}
			sfEls[i].onmouseout=function()
			{
					this.className=this.className.replace(" over","");
					if (hideSelectTags)
						hideDropdowns(this.getElementsByTagName("ul")[0],false);
			}
		}
	}
}

/**
* @Date: Jun 15, 2005
* @Description: checks if an element is contained in a parent. 
	This is necessary to decide if a SELECT tag needs to be hidden
**/
function isInParent(el, parent){
	if (el == null)
		return true;
	var aEls=parent.getElementsByTagName(el.tagName);
	if(aEls && aEls.length==0)
		return false;
	for(var i=0;i<aEls.length;i++){
		if(el==aEls[i])
			return true;
	}
	return false;
}

/**
* @Date: Jun 15, 2005
* @Description: hide dropdowns that are on top of the currently displayed menu item
**/
function hideDropdowns(obj, bool){
	// IE 5 can only show/hide all SELECT tags
	if (navigator.appVersion.substr(22,3)=="5.0"){
		if(bool)
			hideSelects();
		else
			showSelects();
		return;
	}
	// IE 5.5+ can find the tags and hide them specifically
	// using a superimposed IFRAME
	var mnuShim=document.getElementById("menushim");
	if (mnuShim && obj && bool)
	{
			mnuShim.style.left		= findPosX(obj)+"px";
			mnuShim.style.top		= findPosY(obj)+"px";
			mnuShim.style.width		= obj.offsetWidth+"px";
			mnuShim.style.height	= obj.offsetHeight+"px";
			obj.style.zIndex		= "101";
			mnuShim.style.zIndex	= "1";
			mnuShim.style.display	= "block";
	} else
			mnuShim.style.display	= "none";
}

/**
* @Date: Jun 15, 2005
* @Description: find horizontal position relative to page
**/
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

/**
* @Date: Jun 15, 2005
* @Description: find vertical position relative to page
**/
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		// continue as long as you haven't reached either BODY or the menu tag itself
		while (obj.tagName != "BODY" && obj.offsetParent)
		{
			if (!(obj.id=="topnav"))
				curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/**
* @Date: Jun 15, 2005
* @Description: hide a specific SELECT tag
**/
function hideSelect(id){
	var el=document.getElementById(id);
	if (el!=null)
		el.className+=" hide";
}

/**
* @Date: Jun 15, 2005
* @Description: hide all SELECT tags on the page
**/
function hideSelects(){
	var oSelects=document.getElementsByTagName("select");
	for(var i=0;i<oSelects.length;i++)
		oSelects[i].className+=" hide";
}

/**
* @Date: Jun 15, 2005
* @Description: show all SELECT tags on the page
**/
function showSelects(){
	var oSelects=document.getElementsByTagName("select");
	for(var i=0;i<oSelects.length;i++)
		oSelects[i].className=oSelects[i].className.replace(" hide","");
}

/**
* @Date: Jun 15, 2005
* @Description: DOM compatible code for adding an event
	to already existing comments
**/
function addEvent(obj, evType, fn) {
	// adds an eventListener for browsers which support it
	// Written by Scott Andrew: nice one, Scott
	if (obj.addEventListener){
		obj.addEventListener(evType,fn,true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType,fn);
		return r;
	} else {
		return false;
	}
}

addEvent(window,"load", startList);
