$(function() {     
    var $tooltip = $('.tooltip'),
        $box = $('.box');

    $box.delegate('[href="#open"]', 'click', function(e) {
        e.preventDefault();  
        var $this = $(this);           
        $this.toggleClass('active');
        $tooltip.toggleClass('active');
                                 
        if($tooltip.hasClass('active')) {           
            
            $(document).bind('click.closetooltip', function(e) {
                if($(e.target).parents('.box').length === 0) {
                    $this.removeClass('active');  
                    $tooltip.removeClass('active');  
                    $(document).unbind('click.closetooltip');
                }
            });  
            
        } else {
            $(document).unbind('click.closetooltip');
        }
    });
});
