$(document).ready(function () {

    $('.alert').dialog({ autoOpen: false });

    hint(".hint .text");
    hint(".quant .quantity");

    jQuery.easing['BounceEaseOut'] = function (p, t, b, c, d) {
        if ((t /= d) < (1 / 2.75)) {
            return c * (7.5625 * t * t) + b;
        } else if (t < (2 / 2.75)) {
            return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
        } else if (t < (2.5 / 2.75)) {
            return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
        } else {
            return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
        }
    };

    $('.productSlider ul').jcarousel({
        animation: 500,
        scroll: 1
    });

    $('.homeLeft ul').jcarousel({
        animation: 500,
        scroll: 1
    });

    //emails login credentials to a user based on a given email address
    $('#alertforgotpassword .forgot-submit').click(function () {

        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var email = $('#forgot-email').val();
        if (reg.test(email) == true) {
            $.ajax({
                url: '/assets/handlers/forgotpassword.ashx?email=' + email,
                success: function (data) {
                    if (data == 'success') {
                        $('#forgot-message').text('Your credentials have been emailed.').css('color', 'green');
                    }
                    else {
                        $('#forgot-message').text('Please enter a valid email address.').css('color', 'red');
                    }
                }
            });
        }
        else {
            $('#forgot-message').text('Please enter a valid email address').css('color', 'red');
        }
    });

    if ($('.bil-swap a').length > 0) {
        $('.bil-swap a').click(function () {

            $('#delivery-address input', ':visible', document.body).each(function (i) {
                $(this).val($('#billing-address input').eq(i).val());
            });

        });
    }

});

$(window).load(function() {
    //make product boxes equal height
    $('#fullListing .product').equalHeight();
    $('.jcarousel-item .desc').equalHeight();
});
