jQuery.fn.pbtabs = function(options){
    return this.each(function(){
        var defaults = {
                content:'tabcontainer'
            },
            $tabcontainer,
            $tabs,
            $content,
            contentHeight = 0;

        options = $.extend(defaults,options);

        $tabcontainer = $(this);
        $tabs = $tabcontainer.find('a');
        $content = $tabcontainer.next('.'+options.content);
        $sections = $content.children();

        $sections.each(function(){
            var height = $(this).outerHeight();
            if(height > contentHeight){
                contentHeight = height;
            }
        });

        $sections.css('height',contentHeight+'px');

        function init(){
            var h = window.location.hash,
                l = $tabcontainer.find('a[href="'+h+'"]');

            if(h && l.length){
                changeTab(l);
            }else{
                changeTab($tabs.eq(0));
            }
        }

        function changeTab($link){
            $sections.hide();
            $tabs.removeClass('selected');
            $content.find($link.attr('href')).show();
            $link.addClass('selected');
        }

        $tabs.click(function(){
            changeTab($(this));
            return false;
        });
        
        init();
    });
};
