I try to create function that allows have a different number of pairs "popup"/"opener-button". Every opener-button should open appropriate popup. But it doesn't work and I can't understand why. Please help me find the source of the problem and advice solutions to have result that I want see.
Problem: http://jsfiddle.net/f4kc2a84/4/
Script:
function InitPopupOpener(options) {
    if (options.opener.length == options.popup.length) {
        for (var i = 0; i < options.opener.length; i++) {
            var opener = '.' + options.opener[i];
            var popup = '.' + options.popup[i];
            console.log(opener);
            $(opener).click(function (event) {
                $(popup).toggle();
            });
            $(document).click(function (event) {
                if ($(event.target).closest(popup).length == 0 && $(event.target).attr('class') != opener.substr(1)) {
                    $(popup).hide();
                }
            });
        }
    }
}
Now it works only for second popup.
 
     
    