/* 
 */
(function($){
    
    $.fn.topicToggler = function(options){
        //private vars
        var widget = $(this);
        
        //set the default popup options
        var defaults = {
            topicSelector: '.topic',
            activeClass: 'active',
            toggleElement: 'a'
        };
        
        //extend options with defaults
        var options = $.extend(defaults, options);
        var elHeight = 0;
        if($('#topicsArea').size()){
            $(options.topicSelector).each(function(){
                ($(this).height() > elHeight) ? elHeight = $(this).height() : null;
            });
            $('#topicsArea').css('height', elHeight + 'px');
        }
        
        var toggles = widget.find(options.toggleElement).click(function(evt){
            evt.preventDefault();
            var clicked = $(this),
                ref = clicked.attr('href');
                el = $(ref);
            if(el.attr('id') != $(options.topicSelector + '.' + options.activeClass).attr('id')){
                var topics = $(options.topicSelector + '.active').fadeOut('fast', function(){
                    toggles.removeClass('active');
                    el.fadeIn('fast', function(){
                        topics.removeClass('active');
                        el.addClass('active');
                        clicked.addClass('active');
                    });
                });
            }
        });
        
    };
    
})(jQuery);

$().ready(function() {
    $('#topic-toggler').topicToggler();
});
