function setup() {
    $('#interactiveBox').load('/lifestages/homepageInitial.html #initialContainer', function () {setDropdown();});
    setFilterDropdown();

    if ($.browser.msie) {
        $('.navDrop').wrap('<div class="rounded_border"></div>');
        $('.navDrop').css('display', 'block');
        $('#navArticles').parent().css('margin-left', '-260px');
        $('.navDrop').corner("round 3px").parent().css('padding', '3px').corner("round 6px");
    }

    if (navigator.appVersion.indexOf("Mac")!=-1) { 
        $('#navRAQ').css('padding-left', 14); 
        $('#navRAQselected').css('padding-left', 14); 
        $('#navRAQselected').css('width', 138); 
    }
    
    if ($.browser.mozilla) {
        if (navigator.appVersion.indexOf("Mac")!=-1) { 
            $('#searchInput').css('height', 14); 
            $('#navRAQselected').css('width', 144); 
        }
        
        if ($(window).width() > 960) {
            $('html').css('overflow-x', 'hidden');
            $('body').css('overflow-x', 'hidden');
        } else {
            $('html').css('overflow-x', 'visible');
            $('body').css('overflow-x', 'visible');
        }
    }

    $('ul#top li').hoverIntent(
      function () {
        if ($.browser.msie) {
            $(this).children('.rounded_border').fadeIn(100);
        } else {
            $(this).children('.navDrop').fadeIn(100);
        }
      },
      function () {
        if ($.browser.msie) {
            $(this).children('.rounded_border').fadeOut(100);
        } else {
            $(this).children('.navDrop').fadeOut(100);
        }
      }
    )
    
    $('.jqmWindow').jqm({
        toTop: true,
        modal: true,
        onShow: function(h) {
            h.w.fadeIn('slow');
        },
        onHide: function(h) {
            h.o.remove();
            h.w.fadeOut('slow');
        } 
    });
}

function inputFocus() {
    $('#searchInput').val('');
}

function inputBlur() {
    if ($('#searchInput').val()=='') {
        $('#searchInput').val('Search');
    }
}

function submitQuery() {
    window.location = '/search/default.aspx?q='
    + encodeURIComponent($('#searchInput').val());
    return false;
}

function setDropdown() {
    if ($.browser.msie) {
        $('#dropdown').wrap('<div id=\'dropdownwrapper\' style=\'display:none;z-index:51;\' />');
        $('#dropdown').css('display', 'block');
    }
    
    $('#dropper').click(function () {
        if ($.browser.msie) {
            $('#dropdownwrapper').toggle();
        } else {
            $('#dropdown').toggle();
        }
        return false;
    });
    
    $('#dropdown li a').click(function () {
        var section = $(this).attr('id');
        swapSection(section);
        return false;
    });
}

function swapSection(section) {
    if ($.browser.msie) {
        $('#initialContainer').load('/lifestages/'+section+'.html #initialContainer', function () {
            setDropdown();
        });
    } else {
        $('#initialContainer').fadeTo('fast', 0, function() {
            $('#initialContainer').load('/lifestages/'+section+'.html #initialContainer', function () {
                $('#initialContainer').fadeTo('fast', 1, function() {setDropdown();});
            });
        });
    }
}

function setFilterDropdown() {
    $('#dropperFilter').click(function () {
        $('#dropdownFilter').toggle();
        return false;
    });
    
    $('#dropdownFilter li a').click(function () {
        var section = $(this).attr('id');
        var copy = $(this).text();

        if (copy=='View all articles' && $(this).parent().parent().parent().parent().attr('id')=='viewArticles') {     
            $('#dropperFilter').html('Choose a life stage that applies to you');
        } else {
            $('#dropperFilter').html(copy);
        }
        $('#dropdownFilter').hide();
        $('#dropdownFilter li a').removeClass('selected');
        $(this).addClass('selected');
        
        if (section!='viewAll') {
            $('.options:not(.'+section+')').hide();
            $('.newsletter:not(.'+section+')').hide();
            $('.'+section).show();
        } else {
            $('.options').show();
            $('.newsletter').show();
        }
        return false;
    });
}

$(window).resize(function() {
    if ($.browser.mozilla) {
        if ($(window).width() > 960) {
            $('html').css('overflow-x', 'hidden');
            $('body').css('overflow-x', 'hidden');
        } else {
            $('html').css('overflow-x', 'visible');
            $('body').css('overflow-x', 'visible');
        }
    }
});

