﻿
var sfWidths = function() {

    if(document.getElementById) {
    
        var navRoot = document.getElementById("nav");
        for(var i = 0; i < navRoot.childNodes.length; i++) {
        
            var node = navRoot.childNodes[i];
            if(node.nodeName == "LI" && node.className != "ignore") {              
            
                // determine width of parent list item
                var liWidth;
                if(BrowserDetect.browser == "Opera" && BrowserDetect.version == 5)
                    liWidth = node.style.pixelWidth;
                else
                    liWidth = node.offsetWidth;
                
                // set width of all child list item and anchor elements to that
                // of their parent list item
                var childLis = node.getElementsByTagName("LI");
                for(var j = 0; j < childLis.length; j++)
                {
                
                    childLis[j].style.width = liWidth + "px";
                    var childAs = childLis[j].getElementsByTagName("A");
                    for(var k = 0; k < childAs.length; k++) {
                        // get left & right padding of link
                        var leftPadding, rightPadding;
                        if(childAs[k].currentStyle) {
                            leftPadding = childAs[k].currentStyle.paddingLeft;
                            rightPadding = childAs[k].currentStyle.paddingRight;
                        } else {
                            leftPadding = document.defaultView.getComputedStyle(childAs[k], null).paddingLeft;
                            rightPadding = document.defaultView.getComputedStyle(childAs[k], null).paddingRight;                        
                        }
                        
                        // remove px from ends
                        leftPadding = leftPadding.replace(/px$/, "");
                        rightPadding = rightPadding.replace(/px$/, "");
                        childAs[k].style.width = (liWidth - leftPadding - rightPadding) + "px";
                    }
                }                                 
            }
        }    
    }
}

addLoadEvent(sfWidths);

if(BrowserDetect.browser == "Explorer" && BrowserDetect.version < 7)
{
    var sfHover = function() {
        var sfEls = document.getElementById("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(/ sfhover\b/, "");
            }
        }        
    }
    
    addLoadEvent(sfHover);
}