$(document).ready(function() {
    $("#nav").corner("5px"); //add rounded corners to the navigation bar

    //fix top margin issue
    $("#__EVENTTARGET").parent().hide();
    $("#__PREVIOUSPAGE").parent().hide();

    //display the login control
    $("div.login_container").show();
    //init the login dropdown list    
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
    //collapse the login dropdown list if the user clicks outside of the login control
    $(document).click(function() {
        $("ul.subnav").slideUp('fast'); //Collapse the login options
        $(this).find("li span").removeClass("subhover"); //reset the login image       
    });
    $("ul.topnav").click(function(event) { //When trigger is clicked        
        //stop the login dropdown list from collapsing when the user clicks inside the login control
        if ($("ul.subnav").css('display') == 'none') {
            $("ul.subnav").slideDown('fast'); //Drop down the login options
            event.stopPropagation(); //stop the login dropdown list from collapsing when the user clicks on he dropdown list arrow
            $(this).find("li span").addClass("subhover"); //Add "subhover" class to change the login image to unlocked with bright green arrow   
        }
    });
    $("ul.subnav").click(function(event) {
        event.stopPropagation(); //stop the login dropdown list from collapsing when the user clicks inside the login control    
    });

    $("div.search-wrapper").corner("3px");
});

//function WebForm_FireDefaultButton(event, target) {
function FireDefaultButton(event, target) {
    //event.srcElement doesn't work in FF so we check whether
    //it or event.target exists, using whichever is returned
    var element = event.target || event.srcElement;

    if (event.keyCode == 13 && !(element && element.tagName.toLowerCase() == "textarea")) {
        var defaultButton = document.getElementById(target);

        if (defaultButton && typeof defaultButton.click != "undefined") {
            event.cancel = true;
            event.returnValue = false;
            defaultButton.click();

            //prevent postback if the page is invalid
            if (typeof (Page_IsValid) != "undefined") {
                if (!Page_IsValid) {
                    return false;
                }
            }
        }
    }
}
