$(document).ready(function() {
    $('#tooltip').mouseover(function(e) {
        $('#remember_tooltip').css({
            top: (e.pageY + 5) + 'px',
            left: (e.pageX + 5) + 'px'
        }).show();

    }).mouseout(function() {
        $('#remember_tooltip').hide();
    });

    $('.forgot_password').click(function() {
        resetError();

        $('#forgot_password').modal({
            overlayId: 'overlay',
            escClose: true,
            overlayClose: true,
            position: new Array('13%', '')
        });

        $('#forgot_password_form').submit(function() {
            resetError();

            username = $('#forgot_username').val();

            if (username.replace(/ /g, '').length == 0) {
                showForgotError('Please enter your username or email');

                return false;
            }

            $.post($(this).attr('action'), {
                forgot_button: 'true',
                username: username
            },
            function(data) {
                if (data.error) {
                    showForgotError(data.error);
                }

                if (data.success) {
                    showForgotError(data.success, true);

                    $('#forgot_username').val('');

                    $('.nvm').text('WOO! Password\'s reset! LETS LOGIN!');
                }
            },
            'json');
        });
    });
});


function resetError() {
    error = $('#forgot_error');

    error.addClass('hidden');
}

function showForgotError(text, success) {
	showGlobalError(text, success, "#forgot_error");
}
