(function () {
  'use strict';
  
  // loading dependencies
  var Dom = require('dom');
  var Form = require('form');
  var Db = require('db');
  var Page = require('page');
  var Ui = require('ui');
  
  var GameTime = require('GameTime');
  var RoleViews = require('RoleViews');
  var VotingViews = require('VotingViews');
  var CitizenViews = require('CitizenViews');
  
  /**
   * Renders the home screen for each user
   */
  function renderHome() {
    
    // the current game time
    var time = GameTime.startingOn(Db.shared.get('time').start);
    
    /**
     * Renders information in the bar on top of the application.
     * Token from repo Happening/Betrayal
     */
    function infoItem(title, content) {
      Dom.div(function () {
        Dom.style({textAlign: 'center', Flex: true});
        Dom.div(function () {
          Dom.text(title);
          Dom.style({fontWeight: 'bold'});
        });
        content();
      });
    }
    
    // Render the page
    Dom.div(function () {
      
      // display current time
      infoItem('time', function () {
        var now = new Date();
        var dayNight = time.isDay(now)? 'Day': 'Night';
        var number = time.getNumber(now);
        Dom.text(dayNight + ' ' + number);
      });
      
      VotingViews.lynching(time);
      
      // button to go to the overview of the citizens
      Ui.bigButton(function () {
        Dom.text('List of citizens');
        Dom.on('click', function () {
          // go to citizen overview
          Page.nav(['citizens']);
        });
      });
      
      // display the role
      RoleViews.description(Db.personal.get('role'));
    });
  }
  
  /**
   * The main render method
   */
  exports.render = function () {
    
    // render a page based on the state
    if (Page.state.get(0) === 'voting') {
      // render an overview for a voting
      // TODO: hide the voting the nights for non-werewolves
      var votingId = Page.state.get(1);
      
      if (votingId) { // there is a voting id
        VotingViews.overview(votingId);
      } else {
        // otherwise just go back to the home menu
        Page.nav([]);
      }
    } else if (Page.state.get(0) === 'citizens') {
      // render citizen overview
      CitizenViews.overview();
    } else {
      // no special page: render home page
      renderHome();
    }
  };
  
  /**
   * The screen allowing for additional settings
   */
  exports.renderSettings = function () {
    Dom.div(function () {
      
      Dom.p('The following will only be applied to new games. Not the current one.');
      
      // the setting for the number of werewolves
      Dom.p('Number of werewolves in the game:');
      Form.input({
        name: 'nWerewolf',
        value: 2
      });
      
      // restart button
      Form.check({
        name: 'restart',
        text: 'Start new game!',
        sub: 'This will destroy the current game and start a new one.'
      });
    });
  };
  
}());

@@ -197,25 +197,17 @@
 ');%0A
-  %0A
   var 
-GameTime
+Obs
  = r
@@ -218,19 +218,17 @@
 re('
-GameTime');
+obs');%0A  
 %0A  v
@@ -447,107 +447,8 @@
    %0A
-    // the current game time%0A    var time = GameTime.startingOn(Db.shared.get('time').start);%0A    %0A
     
@@ -926,16 +926,189 @@
 nt time%0A
+      Obs.observe(function () %7B%0A        // get the game time from the db (using ref for the observer)%0A        var time = Db.shared.ref('time', 'gameTime').get();%0A        %0A  
       in
@@ -1140,24 +1140,26 @@
 ) %7B%0A        
+ 
+ 
 var now = ne
@@ -1164,24 +1164,26 @@
 new Date();%0A
+  
         var 
@@ -1203,21 +1203,16 @@
 me.isDay
-(now)
 ? 'Day':
@@ -1221,16 +1221,18 @@
 Night';%0A
+  
         
@@ -1253,24 +1253,18 @@
 ime.
-getN
+n
 umber
-(now)
 ;%0A
+  
     
@@ -1300,32 +1300,34 @@
  number);%0A      
+  
 %7D);%0A      %0A     
@@ -1316,25 +1316,73 @@
   %7D);%0A      
-%0A
+  %0A        // show the lynching voting section%0A  
       Voting
@@ -1409,23 +1409,27 @@
 ;%0A      
-%0A
+  %0A 
       
+ 
 // butto
@@ -1474,16 +1474,18 @@
 s%0A      
+  
 Ui.bigBu
@@ -1495,32 +1495,34 @@
 n(function () %7B%0A
+  
         Dom.text
@@ -1547,24 +1547,26 @@
 ');%0A        
+  
 Dom.on('clic
@@ -1589,24 +1589,26 @@
 %7B%0A          
+  
 // go to cit
@@ -1623,32 +1623,34 @@
 rview%0A          
+ 
+ 
 Page.nav(%5B'citiz
@@ -1657,32 +1657,34 @@
 ens'%5D);%0A        
+  
 %7D);%0A      %7D);%0A  
@@ -1669,32 +1669,34 @@
       %7D);%0A      
+ 
+ 
 %7D);%0A      %0A     
@@ -1681,33 +1681,37 @@
       %7D);%0A      
-%0A
+  %0A  
       // display
@@ -1720,16 +1720,18 @@
 he role%0A
+  
       Ro
@@ -1773,18 +1773,48 @@
 ('role')
-);
+, time);%0A      %7D);%0A      %0A      
 %0A    %7D);

Rewrite client to no longer use GameTime