Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 518)
+++ documentViewer.py	(revision 525)
@@ -113,14 +113,26 @@
     metadataService = None
     """MetaDataFolder instance"""
-
+    
+
+    #
     # templates and forms
+    #
+    # viewMode templates
     viewer_text = PageTemplateFile('zpt/viewer_text', globals())
     viewer_xml = PageTemplateFile('zpt/viewer_xml', globals())
     viewer_images = PageTemplateFile('zpt/viewer_images', globals())
     viewer_index = PageTemplateFile('zpt/viewer_index', globals())
+    # available layer types
+    availableLayers = {'text': ['dict','search','gis','annotator'],
+                       'xml': None, 'images': None, 'index': None}
+    # layer templates
+    layer_text_annotator = PageTemplateFile('zpt/layer_text_annotator', globals())
+    layer_text_gis = PageTemplateFile('zpt/layer_text_gis', globals())
+    # toc templates
     toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals())
     toc_text = PageTemplateFile('zpt/toc_text', globals())
     toc_figures = PageTemplateFile('zpt/toc_figures', globals())
     toc_none = PageTemplateFile('zpt/toc_none', globals())
+    # other templates
     common_template = PageTemplateFile('zpt/common_template', globals())
     search_template = PageTemplateFile('zpt/search_template', globals())
@@ -296,4 +308,8 @@
         return ret
     
+    
+    def getAvailableLayers(self):
+        """returns dict with list of available layers per viewMode"""
+        return self.availableLayers
     
     def getBrowser(self):
Index: zpt/layer_text_annotator.zpt
===================================================================
--- zpt/layer_text_annotator.zpt	(revision 525)
+++ zpt/layer_text_annotator.zpt	(revision 525)
@@ -0,0 +1,101 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<metal:block metal:define-macro="html_head">
+  <!--  annotator -->
+  <link rel="stylesheet" type="text/css"
+    tal:attributes="href string:$rootUrl/template/annotator_files/css/annotator.css" />
+
+  <script
+    tal:attributes="src string:$rootUrl/template/annotator_files/lib/vendor/json2.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/extensions.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/console.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/class.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/range.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/annotator.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/widget.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/editor.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/viewer.js"></script>
+  <script
+    tal:attributes="src string:$rootUrl/template/annotator_files/lib/notification.js"></script>
+  <script
+    tal:attributes="src string:$rootUrl/template/annotator_files/lib/plugin/store.js"></script>
+  <script
+    tal:attributes="src string:$rootUrl/template/annotator_files/lib/plugin/permissions.js"></script>
+  <script
+    tal:attributes="src string:$rootUrl/template/annotator_files/lib/plugin/annotateitpermissions.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/plugin/auth.js"></script>
+  <script tal:attributes="src string:$rootUrl/template/annotator_files/lib/plugin/tags.js"></script>
+  <script
+    tal:attributes="src string:$rootUrl/template/annotator_files/lib/plugin/unsupported.js"></script>
+  <script
+    tal:attributes="src string:$rootUrl/template/annotator_files/lib/plugin/filter.js"></script>
+
+  <script type="text/javascript">
+            // <!--
+            $(document).ready(function() {
+                // annotator
+                var elem = $('div.pageContent').get(0);
+                var uri = window.location.href.split(/#|\?/).shift();
+                var devAnnotator = new Annotator(elem).addPlugin('Auth', {
+                    //tokenUrl: 'http://annotateit.org/api/token'
+                    tokenUrl : 'http://localhost:8080/test/annotator/token?user=casties'
+                //autoFetch: false
+                }).addPlugin('Permissions', {
+                    user : 'casties',
+                    userString : function(user) {
+                        if (user && user.name) {
+                            return user.name;
+                        }
+                        return user;
+                    },
+                    userId : function(user) {
+                        if (user && user.id) {
+                            return user.id;
+                        }
+                        return user;
+                    }
+                }).addPlugin('Store', {
+                    prefix : 'http://localhost:18080/AnnotationManager/annotator',
+                    //prefix: 'http://virtuoso.mpiwg-berlin.mpg.de:8080/AnnotationManager/annotator',
+                    //prefix: 'http://annotateit.org/api',
+                    annotationData : {
+                        'uri' : uri
+                    },
+                    loadFromSearch : {
+                        'limit' : 20,
+                        'uri' : uri
+                    //'uri': 'http://127.0.0.1:18080/ECHOdocuViewfullTest?pn=21&url=/mpiwg/online/permanent/library/163127KK'
+                    }
+                });
+            });
+        // -->
+        </script>
+
+</metal:block>
+</head>
+<body>
+  <!-- right-side options -->
+  <div class="col buttons">
+    <!-- LAYER DISPLAY OPTION  -->
+    <ul>
+      <li metal:define-macro="layer_select_li">
+        <input type="checkbox" class="autosubmit" name="viewLayer" value="annotator"
+          tal:attributes="checked python:'annotator' in viewLayers" /> Annotations
+      </li>
+    </ul>
+  </div>
+
+  <metal:block metal:define-macro="options_box">
+    <!-- BEGIN ANNOTATIONS -->
+    <div class="options">
+      <h4>Annotations</h4>
+      <div>nothing to be seen here...</div>
+    </div>
+    <!-- END ANNOTATIONS -->
+  </metal:block>
+
+</body>
+
+</html>
Index: zpt/layer_text_gis.zpt
===================================================================
--- zpt/layer_text_gis.zpt	(revision 525)
+++ zpt/layer_text_gis.zpt	(revision 525)
@@ -0,0 +1,52 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<!-- not used here
+<metal:block metal:define-macro="html_head">
+</metal:block>
+-->
+</head>
+<body>
+  <!-- right-side options -->
+  <div class="col buttons">
+    <!-- LAYER DISPLAY OPTION  -->
+    <ul>
+      <metal:block metal:define-macro="layer_select_li">
+        <li tal:condition="python:docinfo.get('numPlaces',0)">
+          <input type="checkbox" class="autosubmit" name="viewLayer" value="gis"
+            tal:attributes="checked python:'gis' in viewLayers" /> Places<br />
+        </li>
+      </metal:block>
+    </ul>
+  </div>
+
+  <metal:block metal:define-macro="options_box">
+    <!--"BEGIN PLACES"-->
+    <div class="options" tal:condition="python:'gis' in viewLayers">
+      <tal:block
+        tal:define="
+            name docinfo/documentName;
+            places python:here.getPlacesOnPage(docinfo=docinfo, pn=pn);
+            pidlist python:','.join([p['id'] for p in places]);">
+        <h4>Places</h4>
+        <ul>
+          <li>
+            <a
+              tal:attributes="href python:'http://mappit.mpiwg-berlin.mpg.de/db/RESTdb/db/mpdl/%s?id=%s&format=gis'%(name,pidlist)"
+              target="_blank">on this page</a>
+          </li>
+          <li>
+            <a
+              tal:attributes="href python:'http://mappit.mpiwg-berlin.mpg.de/db/RESTdb/db/mpdl/%s?format=gis'%(name)"
+              target="_blank">in whole document</a>
+          </li>
+        </ul>
+      </tal:block>
+    </div>
+    <!--"END PLACES"-->
+  </metal:block>
+
+</body>
+
+</html>
Index: zpt/viewer_text.zpt
===================================================================
--- zpt/viewer_text.zpt	(revision 514)
+++ zpt/viewer_text.zpt	(revision 525)
@@ -4,24 +4,32 @@
   tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode;
               tocMode pageinfo/tocMode; viewLayer pageinfo/viewLayer; viewLayers pageinfo/viewLayers;
+              availableLayers python:here.getAvailableLayers().get('text', None);
               viewerUrl docinfo/viewerUrl;
               rootUrl here/getDocumentViewerURL;
               numPages docinfo/numPages | nothing;">
 <head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-  <title
-    tal:content="python:docinfo.get('creator',' ') + ' - ' + docinfo.get('title',' ')" />
-  <link rel="stylesheet" href="template/docuviewer_css" type="text/css" />
-  <script type="text/javascript" tal:attributes="src string:$rootUrl/template/jquery_js"></script>
-  <script type="text/javascript">
-            // <!--
-            $(document).ready(function() {
-                // autosubmit forms
-                $('form.autosubmit').find('.autosubmit').change(function() {
-                    this.form.submit();
-                });
-                $('form.autosubmit input[type="submit"]').hide();
-            });
-        // -->
-        </script>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title tal:content="python:docinfo.get('creator',' ') + ' - ' + docinfo.get('title',' ')" />
+<link rel="stylesheet" href="template/docuviewer_css" type="text/css" />
+<script type="text/javascript" tal:attributes="src string:$rootUrl/template/jquery_js"></script>
+<script type="text/javascript">
+    // <!--
+    $(document).ready(function() {
+        // autosubmit forms
+        $('form.autosubmit').find('.autosubmit').change(function() {
+            this.form.submit();
+        });
+        $('form.autosubmit input[type="submit"]').hide();
+    });
+// -->
+</script>
+<!--  layer headers -->
+<tal:block tal:repeat="layer viewLayers">
+  <tal:block tal:define="mpath string:here/template/layer_text_${layer}/macros/html_head"
+    tal:condition="python:exists(mpath)">
+    <metal:block metal:use-macro="python:path(mpath)" />
+  </tal:block>
+</tal:block>
+
 </head>
 <body tal:condition="numPages">
@@ -68,5 +76,5 @@
         <div class="options">
           <h4>Search results</h4>
-          <div metal:use-macro="here/template/search_template/macros/results_div"/>
+          <div metal:use-macro="here/template/search_template/macros/results_div" />
         </div>
       </div>
@@ -87,4 +95,5 @@
                   tal:attributes="checked python:viewMode=='text'" /> Text
                 <ul>
+                  <!-- text layers -->
                   <li>
                     <input type="checkbox" class="autosubmit" name="viewLayer"
@@ -95,10 +104,15 @@
                     <input type="checkbox" class="autosubmit" name="viewLayer"
                       value="search"
-                      tal:attributes="checked python:'search' in viewLayers" /> Search hits
+                      tal:attributes="checked python:'search' in viewLayers" /> Search
+                    hits
                   </li>
-                  <li tal:condition="python:docinfo.get('numPlaces',0)">
-                    <input type="checkbox" class="autosubmit" name="viewLayer" value="gis"
-                      tal:attributes="checked python:'gis' in viewLayers" /> Places<br />
-                  </li>
+                  <!-- auto-layer select buttons -->
+                  <tal:block tal:repeat="layer availableLayers">
+                    <tal:block
+                      tal:define="mpath string:here/template/layer_text_${layer}/macros/layer_select_li"
+                      tal:condition="python:exists(mpath)">
+                      <li metal:use-macro="python:path(mpath)" />
+                    </tal:block>
+                  </tal:block>
                 </ul>
               </li>
@@ -123,28 +137,30 @@
             <!-- make sure we have one viewLayer=search -->
             <tal:block tal:repeat="vl viewLayers">
-                <input type="hidden" name="viewLayer" tal:attributes="value vl" tal:condition="python:vl != 'search'"/>
+              <input type="hidden" name="viewLayer" tal:attributes="value vl"
+                tal:condition="python:vl != 'search'" />
             </tal:block>
-            <input type="hidden" name="viewLayer" value="search"/>
+            <input type="hidden" name="viewLayer" value="search" />
             <!-- query text -->
-            <input type="text" name="query" tal:attributes="value query"/>
-            <input type="submit" value="Search"/>
-            <a tal:attributes="href python:here.getLink('query',None)">Clear</a>
-            <ul>
-                <li>
-                  <input type="radio" name="queryType" value="fulltext" 
-                    tal:attributes="checked python:queryType=='fulltext'"/> Exact
-                </li>
-                <li>
-                  <input type="radio" name="queryType" value="fulltextMorph" 
-                    tal:attributes="checked python:queryType=='fulltextMorph'"/> All forms
-                </li>
-                <li>
-                  <input type="radio" name="queryType" value="ftIndex" 
-                    tal:attributes="checked python:queryType=='ftIndex'"/> Fulltext index
-                </li>
-                <li>
-                  <input type="radio" name="queryType" value="ftIndexMorph" 
-                    tal:attributes="checked python:queryType=='ftIndexMorph'"/> Morphological index
-                </li>
+            <input type="text" name="query" tal:attributes="value query" /> <input
+              type="submit" value="Search" /> <a
+              tal:attributes="href python:here.getLink('query',None)">Clear</a>
+            <ul>
+              <li>
+                <input type="radio" name="queryType" value="fulltext"
+                  tal:attributes="checked python:queryType=='fulltext'" /> Exact
+              </li>
+              <li>
+                <input type="radio" name="queryType" value="fulltextMorph"
+                  tal:attributes="checked python:queryType=='fulltextMorph'" /> All forms
+              </li>
+              <li>
+                <input type="radio" name="queryType" value="ftIndex"
+                  tal:attributes="checked python:queryType=='ftIndex'" /> Fulltext index
+              </li>
+              <li>
+                <input type="radio" name="queryType" value="ftIndexMorph"
+                  tal:attributes="checked python:queryType=='ftIndexMorph'" />
+                Morphological index
+              </li>
             </ul>
           </form>
@@ -214,25 +230,12 @@
         <!--"END TEXT NORMALIZATION"-->
 
-        <!--"BEGIN PLACES"-->
-        <div class="options" tal:condition="python:'gis' in viewLayers">
-          <tal:block tal:define="
-            name docinfo/documentName;
-            places python:here.getPlacesOnPage(docinfo=docinfo, pn=pn);
-            pidlist python:','.join([p['id'] for p in places]);">
-            <h4>Places</h4>
-            <ul>
-            <li><a
-              tal:attributes="href python:'http://mappit.mpiwg-berlin.mpg.de/db/RESTdb/db/mpdl/%s?id=%s&format=gis'%(name,pidlist)"
-              target="_blank">on this page</a>
-            </li>
-            <li>
-              <a
-              tal:attributes="href python:'http://mappit.mpiwg-berlin.mpg.de/db/RESTdb/db/mpdl/%s?format=gis'%(name)"
-              target="_blank">in whole document</a>
-            </li>
-            </ul>
+        <!--  auto-layer option boxes -->
+        <tal:block tal:repeat="layer viewLayers">
+          <tal:block
+            tal:define="mpath string:here/template/layer_text_${layer}/macros/options_box"
+            tal:condition="python:exists(mpath)">
+            <metal:block metal:use-macro="python:path(mpath)" />
           </tal:block>
-        </div>
-        <!--"END PLACES"-->
+        </tal:block>
       </div>
       <!-- /col-right -->
