'Render the tabs row
@param r: the S3Request'

def render(self, r):

    rheader_tabs = []
    if r.resource.get_config('dynamic_components'):
        self.dynamic_tabs(r.resource.tablename)
    tabs = tuple((t for t in self.tabs if t.active(r)))
    mtab = False
    if (r.component is None):
        for t in tabs:
            if (t.component == r.method):
                mtab = True
                break
    record_id = r.id
    if ((not record_id) and r.record):
        record_id = r.record[r.table._id]
    for (i, tab) in enumerate(tabs):
        vars_match = tab.vars_match(r)
        if vars_match:
            _vars = Storage(r.get_vars)
        else:
            _vars = Storage(tab.vars)
            if ('viewing' in r.get_vars):
                _vars.viewing = r.get_vars.viewing
        if (tab.function is None):
            if ('viewing' in _vars):
                (tablename, record_id) = _vars.viewing.split('.', 1)
                function = tablename.split('_', 1)[1]
            else:
                function = r.function
        else:
            function = tab.function
        component = tab.component
        here = False
        if ((function == r.name) or (function == r.function)):
            here = ((r.method == component) or (not mtab))
        if component:
            if (r.component and (r.component.alias == component) and vars_match):
                here = True
            elif ((not r.component) and (r.method == component)):
                here = True
            else:
                here = False
        elif (r.component or (not vars_match)):
            here = False
        if here:
            _class = 'tab_here'
        elif (i == (len(tabs) - 1)):
            _class = 'tab_last'
        else:
            _class = 'tab_other'
        if component:
            if record_id:
                args = [record_id, component]
            else:
                args = [component]
            if ('viewing' in _vars):
                del _vars['viewing']
            _href = URL(function, args=args, vars=_vars)
            _id = ('rheader_tab_%s' % component)
        else:
            args = []
            if ((function != r.name) and (not tab.native)):
                if (('viewing' not in _vars) and r.id):
                    _vars.update(viewing=('%s.%s' % (r.tablename, r.id)))
                elif ((not tab.component) and (not tab.function)):
                    if ('viewing' in _vars):
                        del _vars['viewing']
                    args = [record_id]
            elif (('viewing' not in _vars) and record_id):
                args = [record_id]
            _href = URL(function, args=args, vars=_vars)
            _id = ('rheader_tab_%s' % function)
        rheader_tabs.append(SPAN(A(tab.title, _href=_href, _id=_id), _class=_class))
    if rheader_tabs:
        rheader_tabs = DIV(rheader_tabs, _class='tabs')
    else:
        rheader_tabs = ''
    return rheader_tabs
