﻿var options = { path: '/', expires: 10 };

$(function() {

    /* Bind search button focus/blur events */
    $(".SearchLinks input").focus(function() {
        $(this).css("background", "#fff url(/SCF/Images/searchArrowOver.gif) no-repeat 159px 2px");
        if ($(this).val() == "Search") {
            $(this).val("");
        }
    })
        .blur(function() {
            $(this).css("background", "#c05806 url(/SCF/Images/searchArrow.gif) no-repeat 159px 2px");
            if ($(this).val() == "") {
                $(this).val("Search");
            }
        });

    /* Get menu visibility cookie
    var isMenuExpanded = $.cookie("MenuExpanded");


    // if menu was expanded before, expand now and bind click events
    // otherwise, just bind click events
    if (isMenuExpanded == null || isMenuExpanded == "false") {
        bindMenuNotExpanded();
    } else {
        expandMenuImmediate();
        bindMenuExpanded();
    } */
    bindMenuNotExpanded();

});

//Menu is in the shrunk state, bind so that first click expands menu
function bindMenuNotExpanded() {
    /* Menu drop-down arrow click */
    $("#MenuDropDown").toggle(
        function() { expandMenuAnimateBind(); },
        function() { shrinkMenuAnimateBind(); }
    );
}

//Menu is in the expanded state, bind so that first click shrinks menu
function bindMenuExpanded() {
    /* Menu drop-down arrow click */
    $("#MenuDropDown").toggle(
        function() { shrinkMenuAnimateBind(); },
        function() { expandMenuAnimateBind(); }
    );
}

//Expand menu without animations
function expandMenuImmediate() {

    var menuHeight = $("#MainMenu").outerHeight() + 20; //add 20px for height of bottom menu bar
    $("#MenuDropDown").hide(); //$(this)
    $(".Header, .HeaderWrapper").css({ height: menuHeight + "px" });
    $("#MenuBottom").show(0);
    $("#MenuDropDown").css({
        "background-image": "url(/SCF/Images/menuTextWhite.gif)",
        "top": menuHeight - 19 + "px"
    }).show();
    $("#MainMenu").show(0,
        function() {
            $("ul.SecondLevelMenu").css({
                "height": $("ul#MainMenu").height(),
                "overflow": "hidden"
            });
        }
    );
}

//Bind mouse click so that when "Menu" is clicked,
//the menu will expand with animations
function expandMenuAnimateBind() {

    var menuHeight = $("#MainMenu").outerHeight() + 20; //add 20px for height of bottom menu bar
    $("#MenuDropDown").hide();//$(this)
    $(".Header, .HeaderWrapper").animate(
        { height: menuHeight + "px" },
        1000,
        function() {
            $("#MenuBottom").show(0);
            $("#MenuDropDown").css({
                "background-image": "url(/SCF/Images/menuTextWhite.gif)",
                "top": menuHeight - 19 + "px"
            }).show(0);
            $("#MainMenu").show("normal",
                function() {
                    $("ul.SecondLevelMenu").css({
                        "height": $("ul#MainMenu").height(),
                        "overflow": "hidden"
                    });
                }
            );

        } // /func - animate callback
    ); // animate
    //$.cookie("MenuExpanded", "true", options);
}

//Bind mouse click so that when "Menu" is clicked,
//the menu will shrink with animations
function shrinkMenuAnimateBind() {
    //shrink menu

    $("#MainMenu").hide(0);
    $("#MenuDropDown").hide(0);//$(this)
    $("#MenuBottom").hide(0);
    $(".Header, .HeaderWrapper").animate(
        { height: "30px" },
        1000,
        function() {
            $("#MenuDropDown").css({
                "background-image": "url(/SCF/Images/menuText.gif)",
                "top": "0px"
            }).show(0);
        } // /func - animate callback
    ); // /animate
        //$.cookie("MenuExpanded", "false", options);
}
