## Script (Python) "breadcrumbs_handler"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
from AccessControl import getSecurityManager
checkPermission = getSecurityManager().checkPermission

homedir = context.getHomeDir()

path = []
append = path.append

parent = context.aq_inner
while parent is not None:
    append(parent)
    parent = getattr(parent, 'aq_parent', None)
path = path[:-2]  # Crop of ZOPE application root and the REQUEST-container
path.reverse()

crumbs = []
dobreak = 0
for parent in path:
  crumb = {}
  if parent is context:
    try:
        view = parent.getTypeInfo().getActionById('view')
    except AttributeError:
        view = ''
    crumb['url'] = "%s/%s"%(parent.absolute_url(), view)
    crumb['style'] = 'ztmsti'              
  else:
    crumb['url'] = parent.absolute_url() + '/folder_contents' #TODO: Get this from portal_actions    
    crumb['style'] = 'ztmstiakt'
  crumb['name']= parent.title_or_id()
  if checkPermission('List folder contents', parent):
    crumbs.append(crumb)

if not homedir is None:
  crumbs.insert(0, {'url': homedir.absolute_url(), 'name': 'Min Hjemmeside', 'style':'ztmstiakt'} )

return crumbs
