if (Drupal.jsEnabled) {
  $(document).ready(function(){
    hold = false;
    sheight = $("#loginarea").height();
    soffset = -1 * (sheight);
    bheight = $("#loginbtn").height();
    boffset = -1 * (bheight);
    $('#loginarea').css({top: soffset});
    //trigger the login box to pop down when user click      
    $('#loginbtn').click(
        function() {
            hold = true;
            $('#loginarea').animate({top:0}, 'slow');
            $('#loginbtn').animate({top:boffset}, 'slow');
        }
    );    
    $('#loginarea').hover(
        function() {
            //$(this).animate({top:0}, 'slow')
        },
        function() {
            if (hold != true) {
                setTimeout("$('#loginarea').animate({top:soffset}, 'normal')", 1000);
                setTimeout("$('#loginbtn').animate({top:0}, 'normal')", 1000);
            }
        }
    );
    //trigger hold when user clicks in a field
    $("#loginarea #user-login-form input").focus(function () {
        hold = true;
    });
    //remove the hold when they move out of the fields.
    $("#loginarea #user-login-form input").blur(function () {
        hold = false;
    });
    $('body').click(
        function() {
            if (hold != true) {
              hold = false;
              setTimeout("$('#loginarea').animate({top:soffset}, 'normal')", 1500);
              setTimeout("$('#loginbtn').animate({top:0}, 'normal')", 1500);
            }
        }
    );
    if ($('#loginarea #user-login-form .form-item input').hasClass("error")) {
            hold = true;
            $('#loginarea').css({top:0});
            $('#loginbtn').css({top:boffset});
    }
  });
}
