﻿/* LAYOUT.JS */
// configuration variables
    var txt_search = 'Search';
    // value for whether to show the widget toolbar
    // default is NOT to show. can be modified on a page-by-page basis.
    // (see HTML templates for examples)
    var bool_showtools = false;
    // an array of social bookmarking sites
    var arr_socialbookmarks = new Array();
        arr_socialbookmarks.push(
            '<a href="email-a-friend.html?fromHREF=' + escape(document.location) + '&title=' + escape(document.title) + '" onClick="javascript:newWindow(this.href,\'SendEmail\',600,800);return false;">'+
            '<img src="/NRC/StructuralImages/social-email.gif" alt="" />'+
            'Email a Friend'+
            '<\/a>'
        );
        arr_socialbookmarks.push(
            '<a href="javascript:;" onclick="dcsMultiTrack(\'DCS.dcssip\',\'www.twitthis.com\',\'DCS.dcsuri\',\'/twit\',\'DCS.dcsqry\',\'?url=\' + escape(location.href),\'WT.ti\',escape(\'Twitter: \' + document.title)); TwitThis.pop();">'+
            '<img src="/NRC/StructuralImages/social-twitthis.gif" alt="" />'+
            'TwitThis'+
            '<\/a>'
        );
        arr_socialbookmarks.push(
            '<a class="newwin" onclick="dcsMultiTrack(\'DCS.dcssip\',\'www.mixx.com\',\'DCS.dcsuri\',\'/submit\',\'DCS.dcsqry\',\'?page_url=\' + escape(location.href),\'WT.ti\',escape(\'Mixx: \' + document.title));" href="http://www.mixx.com/submit?page_url='+document.location+'">'+
            '<img src="/NRC/StructuralImages/social-mixx.gif" alt="" />'+
            'Mixx This'+
            '<\/a>'
        );
        arr_socialbookmarks.push(
            '<a class="newwin" onclick="dcsMultiTrack(\'DCS.dcssip\',\'www.delicious.com\',\'DCS.dcsuri\',\'/post\',\'DCS.dcsqry\',\'?url=\' + escape(location.href),\'WT.ti\',escape(\'Delicious: \' + document.title));" href="http://delicious.com/post?url='+document.location+'">'+
            '<img src="/NRC/StructuralImages/social-delicious.gif" alt="" />'+
            'Add to Delicious'+
            '<\/a>'
        );
        arr_socialbookmarks.push(
            '<a class="newwin" onclick="dcsMultiTrack(\'DCS.dcssip\',\'www.facebook.com\',\'DCS.dcsuri\',\'/share.php\',\'DCS.dcsqry\',\'?u=\' + escape(location.href),\'WT.ti\',escape(\'Facebook: \' + document.title));" href="http://www.facebook.com/share.php?u='+document.location+'">'+
            '<img src="/NRC/StructuralImages/social-facebook.gif" alt="" />'+
            'Add to Facebook'+
            '<\/a>'
        );
    // HTML for the generated toolbar (share/text size)
    var html_toolbar = '<div id="toolbar">';
        html_toolbar+= '<div id="tool-share"><a id="ctrl" href="#">SHARE<\/a>';
        html_toolbar+= '<div id="share-opts"><ul>';
        for(var i=0;i<arr_socialbookmarks.length;i++){
            html_toolbar+='<li '+((i==0) ? 'class="first"' : '')+'>'+arr_socialbookmarks[i]+'<\/li>';
        }
        html_toolbar+= '<\/ul><\/div>';
        html_toolbar+= '<\/div>';
        html_toolbar+= '<div id="tool-text"><a href="#" id="txt-small"><img src="/NRC/StructuralImages/toolbar-txt-small.gif" alt="reduce font size" /><\/a><a href="#" id="txt-large"><img src="/NRC/StructuralImages/toolbar-txt-large.gif" alt="increase font size" /><\/a>TEXT SIZE<\/div>';
        html_toolbar+= '<\/div>';
    // text size control widget
    var int_txtsize = 10; // font size default is based on 10px;
    var int_txt_min = 9; // anything below 9 pixels introduces rendering errors when not anti-aliased
    var int_txt_max = 18; // set maximum size for type
// reuseable functions
    // used for showing and hiding of additional indicies in the fund detail pages.
    function toggle_index(theIndex){
        // show/hide table rows
        if($('input#'+theIndex+':checked').val()=='show'){
            $('tr.'+theIndex).show();
        }else{
            $('tr.'+theIndex).hide();
        }
        // control graph display
        $('p.index').hide();
        if($('#toggle-indecies input[id$="-index"]:checked').length === 2){
            $('p.all-index').show();
        }else if($('#toggle-indecies input[id$="-index"]:checked').length > 0){
            $('p.'+$('#toggle-indecies input[id$="-index"]:checked').attr('id')).show();
        }else{
            $('p.default-graph').show();
        }
    }
// application of page code
    $(document).ready(function(){
        $('body').addClass('with-js');
        // add .last to the last LI in any UL or OL
        // add .first to the first LI in any UL or OL
        $('ul,ol').each(function(){
            $('li:last',this).addClass('last');
            $('li:first',this).addClass('first');
        });
        // decorate HRs
        $('hr').wrap('<div class="hr"><\/div>');
        // add shadows on .table2
        $('table.table2:not(.noshade)').wrap('<div class="shaded"></div>');
        /* tools widget bar */
        if(bool_showtools){
            $('div#doc').append(html_toolbar); // add bar to page
            $('body').addClass('with-toolbar');
            $('#toolbar a').focus(function(){
                this.blur();
            });
            $('#toolbar #ctrl').click(function(e){
                if($(this).attr('class')=='open'){ // if open, then close
                    $(this).removeClass('open');
                    $('#share-opts').hide();
                }else{ // if not open, open
                    $(this).addClass('open');
                    $('#share-opts').show();
                }
                e.stopPropagation();
                return false;
            });
            $('#toolbar a.newwin').click(function(){
                window.open($(this).attr('href'));
                this.blur();
                return false;
            });
            $('#toolbar a#txt-small').click(function(){
                if(int_txtsize > int_txt_min){
                    int_txtsize--;
                    $('#content').css('font-size',int_txtsize+'px');
                }
                this.blur();
                return false;
            });
            $('#toolbar a#txt-large').click(function(){
                if(int_txtsize < int_txt_max){
                    int_txtsize++;
                    $('#content').css('font-size',int_txtsize+'px');
                }
                this.blur();
                return false;
            });
        }
        /* left nav: highlight parent item of active page */
        $('#left-rail .left-nav a.active').parents('li').parents('li').find('a:first').addClass('active-sub');
        /* search form */
        $('input#q').val(txt_search);
        $('#q').focus(function(){
            if($(this).val()==txt_search){
                $(this).val('');
            }
        });
        $('#q').blur(function(){
            if($(this).val()==''){
                $(this).val(txt_search);
            }
        });
        $('#search-form').submit(function(){
            if($('#q').val()==txt_search){
                return false;
            }
        });
        /* top navigation */
        $('#nav-bar li[id^="nav"]').hover( // only apply behavior to LIs with an ID beginning with "nav" inside #nav-bar
            function(){
                $('a:first',this).addClass('open')
                $('ul:first',this).show();
            },
            function(){
                $('a:first',this).removeClass('open');
                $('ul:first',this).hide();
            }
        );
        if($.browser.msie && ($.browser.version < 7)){ // hide SELECT elements in IE6 where they conflict with dropdown nav
            $('#nav-bar,span.infobox').hover(
                function(){
                    $('select').css('visibility','hidden');
                },
                function(){
                    $('select').css('visibility','visible');
                }
            );
        }
        /* your account */
        $('#your-account').click(function(e){ e.stopPropagation(); });
        $('#your-account div.top a').click(function(){
            if($(this).attr('class')=='open'){ // if open, then close
                $(this).removeClass('open');
                $(this).parents('#your-account').find('div.dropdown').hide();
                this.blur();
                return false;
            }else{ // if not open, then open
                $(this).addClass('open');
                $(this).parents('#your-account').find('div.dropdown').show();
                this.blur();
                return false;
            }
        });
        $('div.stack input.txt').each(function(){
            if($(this).val()!=''){
                $(this).parents('div.stack').find('label').hide();
            }
        });
        $('div.stack input.txt').focus(function(){
            if($(this).val()==''){
                $(this).parents('div.stack').find('label').hide();
            }
        });
        $('div.stack input.txt').blur(function(){
            if($(this).val()==''){
                $(this).parents('div.stack').find('label').show();
            }
        });
        /* self-submitting pulldown fields */
        $('select.self-submit').change(function(){
            $(this).parents('form')[0].submit();
        });
        /* tabbed content */
        $('div.tabbed > ul.tabs').tabs();
        $('div.tabbed ul.tabs a').focus(function(){
            this.blur();
        });
        $('div.tabbed').each(function(){
            $(this).prev('h2').addClass('plain');
        });
        /* split columns immediately following static tabs */
        $('div.tabs').next('div.columns').css('padding-top','0');
        /* 2-column lists */
        $('ul.list-2col').each(function(){
            $('li:nth-child(odd)',this).addClass('odd');
            $('li:nth-child(even)',this).addClass('even');
        });
        /* Learn More */
        $("div.learn-more h6").click(function(){
            $(this).parent().find("h6.on").removeClass("on");
            $(this).parent().find("div:visible").hide();
            $(this).addClass("on").next().show();
        });
        $("div.learn-more h6.on").click();
        /* Zebra Stripes */
        $("table:not(.nozebra)").each(function() {
            $("tbody tr:odd", this).addClass("zebra");
        });
        /* Search Results nav */
        $("div.column3 h3").click(function() {
            if($(this).attr("class") == "closed") {
                $(this).removeClass("closed");
                $(this).next().show();
            }
            else {
                $(this).addClass("closed");
                $(this).next().hide();
            }
        });
        /* popup information boxes */
        $('span.infobox').hover(
            function(){
                $(this).addClass('infobox-open');
            },
            function(){
                $(this).removeClass('infobox-open');
            }
        );
        $('div.quicklinks').hover(
            function(){
                $('div.ql-dropdown',this).show()
            },
            function(){
                $('div.ql-dropdown',this).hide();
            }
        );
        /* toggle index rows in tables */
        $('#toggle-indecies input[id$="-index"]').each(function(i){
            $(this).change(function(){
                toggle_index($(this).attr('id'));
            });
        });
        /* hide login and share dropdowns when clicking outside them on the page */
        $('body').click(function(){
            // login dropdown
            $('div#your-account div.dropdown:visible').hide();
            $('div#your-account a.open').removeClass('open');
            // share dropdown
            $('#share-opts:visible').hide();
            $('#toolbar #ctrl').removeClass('open');
        });
        /* daily fund performance widget */
        // add last to ULs in flyout
        $('div#fund-performance div.content div.col').each(function(){
            $('ul:last', this).addClass('last');
        });
        $('div#fund-performance-btn a').click(function(){
            if($('div#fund-performance').attr('class')=='open'){ // if open, then close
                $('div#fund-performance').removeClass('open').addClass('closed');
                $('div#fund-performance .content').hide();
                //ie 6
                if($.browser.msie && ($.browser.version < 7)){
                    $('div#fund-performance').css('left', '723px');
                    $('div#fund-performance').css('width', '262px');
                }
                this.blur();
                return false;
            }else{ // if not open, then open
                $('div#fund-performance').removeClass('closed').addClass('open');
                $('div#fund-performance .content').show();
                //ie 6
                if($.browser.msie && ($.browser.version < 7)){
                    $('div#fund-performance').css('left', '0');
                    $('div#fund-performance').css('width', '985px');
                }
                this.blur();
                return false;
            }
        });
        /* hide daily fund performance content when clicking outside them on the page */
        $('body').click(function(){
            $('div#fund-performance .content').hide();
            $('div#fund-performance').removeClass('open').addClass('closed');
            //ie 6
            if($.browser.msie && ($.browser.version < 7)){
                $('div#fund-performance').css('left', '723px');
                $('div#fund-performance').css('width', '262px');
            }
        });
    });