    def do_nearestsiblings(self, root=None):
        """ Navigate from a subpage to its nearest siblings and its parent

            gsg 2005-11-15 - This is a modification of the do_siblings function existing in 1.5beta3.
        """
        _ = self._
        # get parent page name
        parent = root or _getParent(self.pagename)
        if not parent:
            return (self.macro.formatter.sysmsg(1) +
                    self.macro.formatter.text(_('No parent page found!'))+
                    self.macro.formatter.sysmsg(0))

        try:
            depth = int(self.args[1])
        except (IndexError, TypeError, ValueError):
            depth = 0

        # iterate over children, adding links to all of them
        result = []

        # gsg 2005-11-15 - start by adding parent for link upwards
        result.append('^')
        result.append(Page(self.macro.request, parent).link_to(self.macro.request, text=parent, querystr=self.querystr))
        result.append('^&nbsp;&nbsp;&nbsp;')

        children = _getPages(self.macro.request, '^%s/' % parent)

        # gsg 2005-11-15
        # - find current page and siblings either side (if they exist)
        # childrensubset will take 1,2 or 3 siblings including current page (one or both sides may not exist)
        children.sort()
        currentdayindex = children.index(self.pagename) 
        childrensubset = []
        if currentdayindex > 0:
            childrensubset.append(children[currentdayindex-1])
        childrensubset.append(children[currentdayindex])
        if currentdayindex+1 < len(children):
            childrensubset.append(children[currentdayindex+1])
        childindex = -1

        for child in childrensubset:
            # display short page name, leaving out the parent path
            # (and make sure the name doesn't get wrapped)
            shortname = child[len(parent):]

            # possibly limit depth
            if depth and shortname.count('/') > depth:
                continue

            # gsg 2005-11-15 - now remove leading / in shortname because it doesn't look pretty
            shortname = shortname[1:]

            childindex += 1

            if child == self.pagename:
                # do not link to focus
                result.append(self.macro.formatter.text(shortname))
            else:
                # gsg 2005-11-15 - if index == 0 then this must be a left link, else must be right link
                if childindex == 0:
                    result.append('<')
                    # link to sibling / child
                    result.append(Page(self.macro.request, child).link_to(self.macro.request, text=shortname, querystr=self.querystr))
                    result.append('<&nbsp;&nbsp;&nbsp;')
                else:
                    result.append('&nbsp;&nbsp;&nbsp;>')
                    # link to sibling / child
                    result.append(Page(self.macro.request, child).link_to(self.macro.request, text=shortname, querystr=self.querystr))
                    result.append('>')

        return ''.join(result)

