/* eGenix.com JavaScript */

/* --- Globals --------------- -------------------------------------- */

var EGENIX_CONTENT_OFFSET = 201;

/* --- eGenix.com Support Code -------------------------------------- */

/* eGenix.com Javascript Library 

   (c) Copyright 2006, eGenix.com Software GmbH, Langenfeld.
   
   All Rights Reserved.
   
   Permissions to use for viewing the eGenix.com web-site granted. All other uses
   require a license from eGenix.com.

   Note: Most of these utility functions work with IE6.
 
*/

/* Global flag to detect IE6 */

var IE6 = (navigator.appVersion.indexOf("MSIE 6.0") >= 0);

var egenix = {

    /* Return the inner height of the current window */

    getInnerHeight: function() {
    	return (window.innerHeight || 
		document.documentElement.clientHeight || 
		document.body.clientHeight);
    },

    /* Return the inner width of the current window */

    getInnerWidth: function() {
    	return (window.innerWidth || 
		document.documentElement.clientWidth || 
		document.body.clientWidth);
    },

    /* Open url in a fullscreen popup window with the given name */

    openFullScreenPopup: function(url, name) {
	specs = ('width=' + screen.width 
		  + ', height=' + screen.height
		  + ', top=0, left=0'
		  + 'type=fullWindow,'
		  + 'fullscreen=yes,'
		  + 'directories=no,toolbar=no,location=no,menubar=no,'
		  +             'scrollbars=no,status=no'
		  );
	window.open(url, name, specs);
	return false;
    },

    /* Check all parent nodes of node for elements with an id in the array
       ids.

    */

    hasParentWithId: function(node, ids) {
	var idsLength = ids.length;
	var currentNode = node.parentNode;
	while (currentNode) {
	    var id;
	    id = currentNode.id
	    for (var i = 0; i < idsLength; i++) {
		if (id == ids[i])
		    return true;
	    }
	    currentNode = currentNode.parentNode;
	}
	return false;
    },

    /* Search the DOM for headers matching one of the header tags given in
       acceptHeaders and return an array of nodes. 

       acceptHeaders must be a string of comma-separated header element
       names and defaults to "h1,h2,h3,h4,h5,h6".

       skipIds may be given to hide all children of certain nodes in the
       DOM.

    */

    getHeaderNodes: function(acceptHeaders, skipIds) {
	var headers = new Array();
	var allNodes = document.getElementsByTagName("*");

	/* acceptHeaders must be uppercase, since the .nodeName of DOM
	   nodes is uppercase as well. */
	if (!acceptHeaders)
	    acceptHeaders = "H1,H2,H3,H4,H5,H6";
	else
	    acceptHeaders = acceptHeaders.toUpperCase();

	for (i = 0; i < allNodes.length; i++) {
	    var node = allNodes[i];
	    var nodeName;
	    if (node.nodeType != 1) /* Element */
		continue;
	    nodeName = node.nodeName;
	    /* Note: IE6 doesn't support string indexing using str[0]. You
	       have to use str.slice(0,1) to get the same effect. */
	    if (nodeName.slice(0,1) != "H") /* nodeName is always uppercase */
		continue;
	    if (isNaN(nodeName.slice(1,2)))
		continue;
	    if (acceptHeaders.indexOf(nodeName) < 0)
		continue;
	    if (skipIds &&
		egenix.hasParentWithId(node, skipIds))
		continue;
	    headers.push(node);
	}
	return headers;
    },

    /* Strip whitespace from the left and right side of text and return
       the stripped version. */

    stripText: function(text) {
	var stripRE = /^\s*(.*)\s*$/g;
	return text.replace(stripRE, "$1");
    },

    /* Create an anchor link name from the given text */

    anchorFromText: function(text) {
	return text.replace(/[^a-zA-Z0-9]/g, "");
    },

    /* Extract plain text from the node.

       Note: text is used for recursion and should not be passed in when
       calling the function.

    */

    getNodeText: function(node, text) {
	var childNodes = node.childNodes;
	if (!text)
	    text = "";
	for (var i = 0; i < childNodes.length; i++) {
	    var childNode = childNodes[i];
	    if (childNode.nodeType == 3 &&  /* Text */
		childNode.data) {
		var nodeText = egenix.stripText(childNode.data);
		if (nodeText) {
		    if (text)
			text += " ";
		    text += nodeText;
		}
	    }
	    else if (childNode.nodeType == 1) /* Element */
		text = egenix.getNodeText(childNode, text);
	}
	return text;
    },

    /* Add an anchor element with the given name to node.

       The function returns the new element node.

       It also is careful not to add multiple anchors with the same name
       to a node, so calling it multiple times on the same node is
       allowed.

    */

    addAnchor: function(node, name) {
	var childNodes = node.childNodes;

	/* Check that we are not adding a duplicate anchor */
	for (var i = 0; i < childNodes.length; i++) {
	    var childNode = childNodes[i];
	    if (childNode.nodeType == 1 &&  /* Element */
		childNode.nodeName == "A") {
		if (childNode.name == name)
		    return childNode;
	    }
	}

	/* Add anchor element */
	if (!IE6) {
	    anchorNode = document.createElement("A");
	    anchorNode.name = name;
	    node.appendChild(anchorNode);
	}
	else {
	    /* IE6 has problems with setting the anchor .name attribute */
	    node.innerHTML += "<a name=\"" + name + "\"></a>";
	    anchorNode = node.lastChild;
	}

	return anchorNode;
    },

    /* Create a table of contents and write it to the element targetId.

       The table of contents is generated by extracting all header
       elements and their text from the document, adding anchors to all
       header elements and then creating corresponding header elements
       with a anchor link to the original headers in the elements
       targetId.

       indexHeaders may be given as comma-separated list of header element
       names to select the headers to index. Default is to index all
       header elements.

       skipIds may be given to hide all children of certain nodes in the
       DOM.

    */

    createTableOfContents: function(targetId, indexHeaders, skipIds) {
	var tocDiv = document.getElementById(targetId);
	var tocNodes;
	if (!indexHeaders)
	    indexHeaders = "h1,h2,h3,h4,h5,h6";
	tocNodes = egenix.getHeaderNodes(indexHeaders, skipIds);
	for (var i = 0; i < tocNodes.length; i++) {
	    var node = tocNodes[i];
	    var nodeText = egenix.getNodeText(node);
	    var nodeAnchor = egenix.anchorFromText(nodeText);
	    var tocHeader;
	    var tocLink;
	    var headerText;
	    var headerAnchor;

	    /* Add anchor to header node */
	    egenix.addAnchor(node, nodeAnchor);

	    /* Add header with link to element targetId */
	    tocHeader = document.createElement(node.nodeName);
	    tocLink = document.createElement("a");
	    tocLink.href = "#" + nodeAnchor;
	    headerText = document.createTextNode(egenix.getNodeText(node));
	    tocLink.appendChild(headerText);
	    tocHeader.appendChild(tocLink);
	    tocDiv.appendChild(tocHeader);
	}
	return tocDiv;
    },

    /* IE6 complains if the last entry in a dictionary has a trailing
       comma, so we leave this dummy around as last entry. */
    dummy: 0

}


/* --- Menu Code ---------------------------------------------------- */

/* eGenix CSS Menu

   Copyright Patick Griffiths & Dan Webb
   http://www.htmldog.com/articles/suckerfish/dropdowns/
   See the above reference for usage permissions.
   
   Adapted to eGenix website needs.

*/

// Patch for IE using pseudo-hover class on no a elements

sfHover = function() {
	var sfEls = document.getElementById("egenix-nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



