<!-- $Id: templm/timeline1.txt 2015/12/15 22:50:46 $ -->
%(
   timeline contains:
   self events 
   + birth of children
   + marriage of parents, children
   + death of parents, spouses, children
   Known bug: unable to have a %foreach; inside a sorted_list.
              So, unable to get the witnesses of an event.
%)

%let;l_mi;%if;(has_parents)%mother.index;%end;%in;

%define;add(z1,z2,z3)
  %foreach;z1.event;
    %if;("z1" = "self"
         or event.name = [death]
         or (event.name = [birth] and "z1" = "child" )
         or (event.name = [marriage event] 
             and ("z1" = "child" 
                  or ("z1" = "father" 
                      and event.spouse.index = l_mi))))
      %apply;add_in_sorted_list%with;
        %if;(event.has_date)%event.date.year;%else;9999%end;
      %and;
        <tr>
          <td valign="top" style="white-space: nowrap;" width="1">
            <span class="edate">
              %if;event.has_date;%event.date;
              %else;---
              %end;
            </span>
          </td>
          <td valign="top" style="white-space: nowrap;" width="1">
          %if;(event.has_place) %event.place;%end;
          </td>
          <td valign="top">
            <span>
              %if;("z1" = "self")
                %apply;capitalize(event.name)%sp;
              %else;
                %apply;a_of_b%with;
                  %apply;capitalize(event.name)
                %and;
                  <span title="%if;(z3 = 0)[z2]0%elseif;(z3 = 1)[z2]1%else;[z2]2%end;">%self;</span> %if;event.has_spouse; [with] %event.spouse;%end; 
                %end;
              %end;
            </span>
            %if;("z1" = "self")
              %if;event.has_witnesses;
                <p style="margin:0;">
                  %foreach;event_witness;
                    <span>%apply;capitalize(event_witness_kind) :</span>
                    %apply;short_display_person("event_witness")<br>
                  %end;
                </p>
              %end;
            %end;
          </td>
        </tr>
      %end;
    %end;
  %end;
%end;

%if;(has_event or has_families or has_parents)

  %empty_sorted_list;
  
  %if;(has_event)
    %apply;add("self","","")
  %end;

  %if;(has_families)
    %foreach;family;
      %apply;add("spouse","the spouse",spouse.sex)
      %if;(has_children)
        %foreach;child;
          %apply;add("child","a son/a daughter/a child",child.sex)
        %end;
      %end;
    %end;
  %end;
  %if;(has_parents)
    %apply;add("father","the father/the mother/a parent",0)
    %apply;add("mother","the father/the mother/a parent",1)
  %end;

  <br><h3 class="highlight">[*time line]</h3>
  <table>
    %foreach;sorted_list_item;
      %item.2;
    %end;
  </table>
%end;
