﻿$(document).ready(function () {
    
    $('#homeRegButton').hover(function () { $(this).attr('src', 'images/registerButton_hover.png') }, function () { $(this).attr('src', 'images/registerButton.png') });
    // Added rollover for new sign up button on webinars.  09/01/2010.  BD.
    $('#homeSignupButton').hover(function () { $(this).attr('src', 'images/signup_hover.png') }, function () { $(this).attr('src', 'images/signup.png') });

    // We may now have multiple events that can be registered on the Events page so need multiple versions of the button for rolling over.  09/28/2010.  BD.
    $('#homeSignupButton0').hover(function () { $(this).attr('src', 'images/signup_hover.png') }, function () { $(this).attr('src', 'images/signup.png') });
    $('#homeSignupButton1').hover(function () { $(this).attr('src', 'images/signup_hover.png') }, function () { $(this).attr('src', 'images/signup.png') });
    $('#homeSignupButton2').hover(function () { $(this).attr('src', 'images/signup_hover.png') }, function () { $(this).attr('src', 'images/signup.png') });
    $('#homeSignupButton3').hover(function () { $(this).attr('src', 'images/signup_hover.png') }, function () { $(this).attr('src', 'images/signup.png') });
    $('#homeSignupButton4').hover(function () { $(this).attr('src', 'images/signup_hover.png') }, function () { $(this).attr('src', 'images/signup.png') });

    $('#loginButton').hover(function () { $(this).attr('src', 'images/loginButton_hover.jpg') }, function () { $(this).attr('src', 'images/loginButton.jpg') })

    $('#loginButton').click(function () { loginUser($('#un').val(), $('#pw').val()) });

    $('.littleLogin').click(function () {
        positionLoginBubble();
        $('#loginBubble').fadeIn(200);
        $('#littleUn').focus();
    })

    function positionLoginBubble() {
        lb = $('#loginBubble');
        lb.css('left', 706+(($(window).width()-936)/2));
    }

    $(window).resize(function () {
        positionLoginBubble();
    });

    $('#littleLoginHot').click(closeLoginBubble);

    $('.loginBubbleInputs').keydown(function (e) {
        if (e.keyCode == 27) // [ESC] was pressed - cancel and close
        {
            closeLoginBubble();
        }
        if (e.keyCode == 13) // [enter] was pressed - submit the user
        {
            loginUser($('#littleUn').val(), $('#littlePw').val());
            return false; // prevents the page from reloading
        }
    });

    $('.homeLoginInputs').keydown(function (e) {
        if (e.keyCode == 27) // [ESC] was pressed - cancel and close
        {
            closeLoginBubble();
        }
        if (e.keyCode == 13) // [enter] was pressed - submit the user
        {
            loginUser($('#un').val(), $('#pw').val());
            return false;
        }
    });

    function closeLoginBubble() {
        $('#loginBubble').fadeOut(200);
    }

    $('#littleLoginButton').hover(function () { $(this).attr('src', 'images/littleLoginButton_hover.png') }, function () { $(this).attr('src', 'images/littleLoginButton.png') })

    $('#littleLoginButton').click(function () { loginUser($('#littleUn').val(), $('#littlePw').val()) });

    function loginUser(un, pw) {
        $('input').blur();
        $('input').attr("disabled", true);
        $('#loginBubbleError').html('<img src="images/loginAni.gif" />');
        $.ajax({
            type: 'GET',
            url: 'authCheck.aspx',
            data: 'email=' + un + '&password=' + pw + '&cookieCheck=' + $('#cookieCheck:checked').val() + '&ref=' + $('#SignIn').attr('ref'),
            success: function (msg) {
                if (msg == "False") {
                    $('#loginBubbleError').text('Email and/or password not found');
                    $('#signInError').text('Email and/or password not found');
                    $('input').removeAttr('disabled');
                }
                else {
                    window.location = msg;
                }
            }
        });

    }

});
