jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
    return -c * ((t = t / d - 1) * t * t * t - 1) + b;
};

jQuery.extend(jQuery.expr[':'], {
    focus: function (element) {
        return element == document.activeElement;
    }
});

$(function () {
    $('.lastitemize').each(function () {
        $('> :last', this).addClass('lastItem');
    });

    // popin
    $('.popinClose').click(function () {
        $('.popinEnable, #popinOverlay div').fadeOut('slow');
        $('.popinEnable').removeClass('popinEnable');
    });

    // Store locator
    //activé uniquement lorsqu'on n'est PAS en mode édition dans le BO Sitefinity
    if ($('meta[name="Generator"]', 'head').size() > 0) {
        if ($('.mapInfos').length != 0) {
            $('.mapInfos input').focus(function () {
                if ($(this).val() == $(this).attr('title')) {
                    $(this).val('');
                    $(this).css('color', '#535353');
                }
            });
            $('.mapInfos input').blur(function () {
                if ($(this).val() == '') {
                    $(this).val($(this).attr('title'));
                    $(this).css('color', '#CACACA');
                }
            });
            $('.mapInfos input').css('color', '#CACACA');
            if ($('.mapResults').length = !0) {
                $('.mapResults').jScrollPane({
                    dragMinHeight: 18,
                    dragMaxHeight: 18,
                    scrollbarWidth: 18
                });
            }
        }
    }

    // clear input on focus
    $('.accountArea input').focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            $(this).val('');
            $(this).css('color', '#808080');
        }
    });
    $('.accountArea input').blur(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
            $(this).css('color', '#CACACA');
        }
    });
    $('.accountAreaLogin input').focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            $(this).val('');
            $(this).css('color', '#808080');
        }
    });
    $('.accountAreaLogin input').blur(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
            $(this).css('color', '#CACACA');
        }
    });


    // show/hide subnavigation
    $('.clubMenu > a, .cardMenu > a').hover(function () {
        $(this).parent().find('.subNav').show();
    });
    $('.clubMenu, .cardMenu').mouseleave(function () {
        $('.subNav', this).hide();
    });

    // forms validation
    //activé uniquement lorsqu'on n'est PAS en mode édition dans le BO Sitefinity
    if ($('meta[name="Generator"]', 'head').size() > 0) {
        if ($('.newsletterContent').length != 0 || $('.accountManageContent').length != 0 || $('.contactContent').length != 0 || $('.wizardContent').length != 0 || $('.accountContent').length != 0 || $('.resetPasswordContent').length != 0 || $('.accountArea').length != 0 || $('.accountAreaLogin').length != 0) {
            $('.newsletterContent, .accountManageContent, .contactContent, .wizardContent, .accountContent, .resetPasswordContent, .accountArea, .accountAreaLogin').validationEngine({
                validationEventTriggers: "blur",  //will validate on keyup and blur  
                success: false,
                failure: false
            })
        }
    }
});


function openModale(modaleId) {
    $('.popin').css('visibility', 'hidden');
    $('.popin').show();

    $('#' + modaleId + ' + div#popinOverlay > div').css({ 'opacity': '0.6' });
    $('#' + modaleId + ' + div#popinOverlay > div').fadeIn('slow');

    $('#' + modaleId).css('visibility', 'visible');
    $('#' + modaleId).fadeIn('slow').addClass('popinEnable');
    var winH = $(window).height();
    var winW = $(window).width();
    var modWidth = $('.popinContent').width();
    if (winH < $('.popinContent').height() + 40) {
        //$('.popinEnable').css('overflow-y', 'scroll');
        //$('.popinEnable').css('overflow-x', 'hidden');
        $('.popinEnable').css('top', 20);
        $('.popinEnable').css('height', winH);
        modWidth = modWidth + 15; // space needed for scrollbar
    } else {
        $('.popinEnable').css('top', winH / 2 - $('.popinEnable').height() / 2);
    }
    $('.popinEnable').css('width', modWidth);
    $('.popinEnable').css('left', winW / 2 - $('.popinEnable').width() / 2);
    return false;
}
function closeModale(modaleId) {
    $('.popinEnable, #' + modaleId + ' + div#popinOverlay > div').fadeOut('slow');
    $('.popinEnable').css('visibility', 'hidden');
    $('.popinEnable').show();
    $('.popinEnable').removeClass('popinEnable');
}
