/* This is the therapists widget. You can pass in options 
 * to override the default values. Attach to the widget dom element.
 * @param (optional):
 * requires: jQuery, jquery.modal.js
 */
(function($){ 

    $.fn.therapists = function(options){
        //private vars
        var widget = $(this),
            bios = [],
            current = 0;
        
        //set the default popup options
        var defaults = {
            continuous: true
        };
        
        //extend options with defaults
        var options = $.extend(defaults, options);
        
        widget.find('button').each(function(i){
            var pCont = $(this).siblings('.bio');
            bios.push(pCont);
            $(this).click(function(){
                current = i;
                $().modal({popContent: pCont});
                $('.pop-container .next').click(function(){
                    var html = null;
                    if(current == bios.length - 1){
                        current = 0;
                        html = bios[0];
                    }else{
                        current++;
                        html = bios[current];
                    }
                    $().modalChange({popHtml: html});
                });
                
                $('.pop-container .prev').click(function(){
                    var html = null;
                    if(current == 0){
                        current = bios.length - 1;
                        html = bios[current];
                    }else{
                        current--;
                        html = bios[current];
                    }
                    $().modalChange({popHtml: html});
                });
            });
        });
        
    };
    
})(jQuery);

$().ready(function() {
    $('.therapists ul').therapists();
});
