/*  home.js  v4  R7.9 (positioned flyouts) jrg/kkh  2007-06-15  */

var userAgent = navigator.userAgent.toLowerCase();

/* hide from old browsers that do not support getElementByID */
if (document.getElementById) {
    init = function() {
        /* fixHeights on home page colored blocks */
        fixHeights = function() {
            var maxHeight = 0;
            var tmpHeight,i;
            for(i=0; i < arguments.length; i++) {
                tmpHeight = document.getElementById(arguments[i]).offsetHeight;
                if (maxHeight < tmpHeight) maxHeight = tmpHeight;
            }
            for(i=0; i < arguments.length; i++) {
                document.getElementById(arguments[i]).style.height = maxHeight + "px";
            }
        }
        fixHeights("ts");
 
        var navs = new Array("navts");
        if(userAgent.indexOf("msie") > -1 && userAgent.indexOf("opera") == -1) {
            for(var j=0; j<navs.length;j++) {
                var sfEls = document.getElementById(navs[j]).getElementsByTagName("LI");
                for (var i=0; i<sfEls.length; i++) {
                    sfEls[i].onmouseover=function() {
                        this.className+=" sfhover";
                        positionFlyoutTop(this);
                    }
                    sfEls[i].onmouseout=function() {
                        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                    }
                }
            }
        } else {
            for(var j=0; j<navs.length;j++) {
                var sfEls = document.getElementById(navs[j]).getElementsByTagName("LI");
                for (var i=0; i<sfEls.length; i++) {
                    sfEls[i].onmouseover=function() {
                        positionFlyoutTop(this);
                    }
                }
            }
        }
    }
};

function positionFlyoutTop(node) {
    var flyout = node.getElementsByTagName("UL")[0];
    if(flyout) {
        flyout.style.top = "auto";
        
        var viewportHeight = document.documentElement.clientHeight;
        
        /* Opera/Konqueror treat clientHeight as page height. */
        if(viewportHeight == document.body.scrollHeight) {
            viewportHeight = window.innerHeight;
            /* Account for horizontal scrollbar in Opera. */
            if(document.body.scrollWidth > window.innerWidth && userAgent.indexOf("opera") > -1)
                viewportHeight -= 16; 
        }

        var scrollTop = document.documentElement.scrollTop;
        
        /* Konqueror's document.documentElement.scrollTop is always 0 */
        if(scrollTop == 0) {
            scrollTop = document.body.scrollTop;
        }
        
        /* When flyout is cutoff at the bottom of the viewport, align with bottom of viewport */
        if((flyout.offsetTop + flyout.offsetHeight) > (viewportHeight + scrollTop))
            flyout.style.top = (flyout.offsetTop - (flyout.offsetTop + flyout.offsetHeight - viewportHeight - scrollTop)) + "px";
        
        /* For flyout is taller than viewport/cutoff at the top, align with top of viewport */
        if(flyout.offsetTop < scrollTop)
            flyout.style.top = scrollTop + "px";
    }
}
/* load init for browsers that support attachEvent, including IE and Opera */
if (window.attachEvent) { 
    window.attachEvent("onload", init); 
} 
/* otherwise, load only for known browsers that need the fixes */
else if (userAgent.indexOf("firefox/1.5" > -1) ) {
    window.onload=init;
};

