
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     *  FUNCTION Event.observe()
     *  ====================================================================
     *  <element>, <action>, <function>
     *
     *  This function calls highlightBucket when the windows onload event happens.
     *
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
    Event.observe(window, "load",
        function() {
            highlightBucket();
        }
    );
*/

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     *  FUNCTION highlightBucket()
     *  ====================================================================
     *
     *  This function highlights the appropriate bucket if a match can be found
     *  between the URL file path and a list of file paths
     *
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

    function highlightBucket() {
    
        // doingBusiness, aboutfm, buyhome
    
        /*
        /affordableoptions - /dlink/html/LearningCenter/
        ??
        /counselormax
        /terms
        */
        var noHighlightArray = new Array(
            '/corporate/about/feedback.html',
            '/corporate/about/contactus.htm'
        );
        var doingBusinessArray = new Array(
            '/corporate/about/vendors.html',
            '/corporate/doing_business',            
            '/debt/',
            '/cgi-bin/',
            '/special/asupsiri/navigation/',
            '/dlink/html/LearningCenter/',
            '/cim/',
            '/debt/',
            '/mbs/',
            '/singlefamily/',
            '/sell/',
            '/service/',
            '/homepossible/',
            '/learn/',
            '/lpoutreach/',
            '/multifamily/',
            '/multisuite/',
			'/ontrack/',
            '/hve/',
            '/forms/',
            '/dgtq/',
            '/finance/debtsecurities/',
            '/earlyindicator/',
            '/freddienotes/',
            '/realestatepros/',
            '/slearnctr/',
            '/ts_dev/',
            '/yes/',
            '/uniform/',
            '/usbank/',
            '/wellsfargo/'
        );
        var aboutfmArray = new Array(
            '/bios/',
            '/careers/',
            '/Careers/',
            '/citizenship/',            
            '/corporate/about',
            '/corporate/citizenship',
            '/corporate/company_profile',
            '/corporate/reports/',
            '/corporate/initiatives/',
            '/corporate/whoweare/', 
            '/dlink/html/PMMS/',
            '/news/',
            '/pmms/',
            '/investors/',
            '/smm/',
            '/finance/cmhpi/',
            '/finance/smm/',
            '/initiatives/',
            '/governance/',
            '/whoweare/',
            '/speeches/',
            '/freddiemac/',
			'/freddiefacts/'
        );
        var buyhomeArray = new Array(
            '/corporate/buying_and',
            '/corporate/buyown/',
            '/avoidforeclosure/', 
            '/avoidfraud',
            '/calculadoras/',
            '/calculators/',
            '/comprecasa/',         
            '/creditsmartespanol/',
            '/hrc/'
        );
        
        var bucketId = ""; /* id name of bucket item that will be highlighted */
    
        var fileNameAndPath = location.pathname;
        var fileNameAndPathSplit = fileNameAndPath.split("/");
        var fileName = fileNameAndPathSplit[(fileNameAndPathSplit.length-1)];
        var filePath = fileNameAndPath.replace(fileName, "");
    
        /* try to match the file path with one from the list and identify its bucket */
        
        if (fileNameAndPath != '/corporate/about/fmsites.html' && fileNameAndPath != '/corporate/about/sitemap.html' && fileNameAndPath != '/corporate/about/contactus.htm'){
        
            for (var i = 0; i < noHighlightArray.length; i++)
            {
                if (fileNameAndPath.indexOf(noHighlightArray[i]) == 0){
                    bucketId = "none";
                }
            }
            if (bucketId == "") {
                for (var i = 0; i < doingBusinessArray.length; i++)
                {
                    if (fileNameAndPath.indexOf(doingBusinessArray[i]) == 0){
                        bucketId = "doingBusiness";
                    }
                }
            }
            if (bucketId == "") {
                for (var i = 0; i < aboutfmArray.length; i++)
                {
                    if (fileNameAndPath.indexOf(aboutfmArray[i]) == 0){
                        bucketId = "aboutFreddieMac";
                    }
                }   
            }
            if (bucketId == "") {
                for (var i = 0; i < buyhomeArray.length; i++)
                {
                    if (fileNameAndPath.indexOf(buyhomeArray[i]) == 0){
                        bucketId = "buyingAndOwning";
                    }
                }   
            }
        }

        /* if a bucket is identified and the bucket exists, highlight it */
        if (bucketId != "" && bucketId != "none" && document.getElementById(bucketId)){
            var ListToHighlight = document.getElementById(bucketId).firstChild;
            ListToHighlight.setAttribute("id","topnav-current");
        } 
    
    
    
    }
    //end function  



     
    function FM_HighlightBucket(bucketList, navigationType, domainName) {
        
        var bucketId = "";
        var fileNameAndPath = location.pathname;
        var fileNameAndPathSplit = fileNameAndPath.split("/");
        var fileName = fileNameAndPathSplit[(fileNameAndPathSplit.length-1)];
        var filePath = fileNameAndPath.replace(fileName, "");
        
        if (navigationType == null) {return;}
        domainName = (domainName != null) ? domainName : getdomainname(window.location.hostname);
        /* If there is only one object within the json, it's not an array. Here we make it one. */
        var bucketList = (bucketList.Site.length) ? bucketList.Site : new Array(bucketList.Site);
        
        /* go through the list of sites and try to match the domainName */
        bucketList.each(function(siteName) {
            if(siteName.name == domainName) {
                
                /* If there is only one object within the json, it's not an array. Here we make it one. */
                var siteName = (siteName.Path.length) ? siteName.Path : new Array(siteName.Path);
                siteName.each(function(urlPath) {
                    if(urlPath.name == filePath) {
                        bucketId  = urlPath.bucket;
                    }
                });
            }
        });
        
        /* if a bucket is identified, highlight it */
        if (bucketId != ""){
            var ListToHighlight = document.getElementById(bucketId).firstChild;
            ListToHighlight.setAttribute("id","topnav-current");
        } 
        
    }
    


