var highlightMenu = true;
var textResizing = true;
var expandingMenu = false;

$(document).ready(function() {
    // <li> Hover for IE6 and below
    if ($.browser.msie && $.browser.version < "7") {
        $("#nav li").hover(function() {
            $(this).addClass("hover");
        }, function() {
            $(this).removeClass("hover");
        });
    }

    $("#nav a").each(function() {
        // Add active class to current page link in the menu
        if (highlightMenu) {
            if (location.href.toLowerCase().indexOf($(this).attr('href').toLowerCase()) != -1) {
                $(this).parent().siblings().removeClass('active');
                $(this).parent().addClass("active");
            }
        }

        // Expand lists when the user tabs through menu items
        $(this).focus(function() {
            $(this).parents('li').addClass('hover');
        });
        // Collapse lists again when the link loses focus
        $(this).blur(function() {
            $(this).parents('#nav li').removeClass('hover');
        });
    });

    // Text resizing
    if (textResizing) {
        var bodyTextSize = readCookie('textSize');
        if (bodyTextSize != null) {
            $('html').css({ 'font-size': bodyTextSize + "px" });
            // Cufon.refresh();
        }

        $('a#smallText').click(function(e) {
            e.preventDefault();
            var bodyTextSize = parseInt($('html').css('font-size'));
            //alert(bodyTextSize);
            if (bodyTextSize > 8) {
                bodyTextSize -= 2;
                $('html').css({ 'font-size': bodyTextSize + "px" });
            }
            createCookie('textSize', bodyTextSize);
            // Cufon.refresh();
        });

        $('a#largeText').click(function(e) {
            e.preventDefault();
            var bodyTextSize = parseInt($('html').css('font-size'));
            //alert(bodyTextSize);
            if (bodyTextSize < 38) {
                bodyTextSize += 2;
                $('html').css({ 'font-size': bodyTextSize + "px" });
            }
            createCookie('textSize', bodyTextSize);
            // Cufon.refresh();
        });

    }

    if (expandingMenu) {
        var navid = "" + $.query.get('n');
        $("#vNav ul.subnav").hide();

        if (navid != "") {
            $("#vNav li#" + navid).parents("ul.subnav").show();
            $("#vNav li#" + navid).children("ul.subnav").show();
        }

        $("#vNav li.navdrop > a").next("ul.subnav").children("li").children("a").each(function() {
            $(this).attr("href", $(this).attr("href") + "?n=" + $(this).parent("li").parent("ul").parent("li").attr("id"));
        });

        $("#vNav li.navdrop > a").click(function() {
            $(this).next("ul.subnav").slideToggle();
            return false;
        });
    }
});
