var mvlRouter = new Router({
  '/login': {on: getC},
  '/student': {      
      '/dashboard': {on: getC,
          '/settings':{on: getC}},
      '/childfeedback': {on: getC},
      '/yourfeedback': {on: getC},
      '/assignments': {on: getC}
  },
  '/educator': {
      '/dashboard': {on: getC,
          '/settings':{on: getC}},
      '/schedule': {
          '/(\\d+)': {
              '/(\\d+)': {on: getC}
          }
       },
      '/questionbank': {
          '/(\\d+)': {
              '/(\\d+)': {
                  '/(\\d+)': {on: getC}
              }
          }
       }
  },
  '/logout': {
      on: function(){
          var auth = new SSO();
          auth.logOut();
      }
  },

  '/create': {                    
      '/entity': {
          '/(\\d+)': {
               '/tos': {on: getC},
               '/register': {on: getC},
               '/appearance' : {on: getC},
               '/skin' : {on: getC},
               '/eyes' : {on: getC},
               '/hair' : {on: getC},
               '/ptype': {on: getC},
               '/pquiz': {'/(\\d+)': {on: getC}},        
               '/cquiz': {'/(\\d+)': {on: getC}},
               '/name': {on: getC}
          }
      }              
  },                      
  '/raise': {
      '/mychild': {on: getC,               
          '/(\\d+)': {on: getC,
              '/(\\d+)': {on: getC},
              '/videos': {on: getC}
          }              
      }
  },    
  '/live': {          
      '/life': {on: getC,               
          '/(\\d+)': {on: getC,
              '/(\\d+)': {on: getC},
              '/videos': {on: getC}
          }              
      }
  }  

});

var page_obj = new Page({
    'login': {
        on: function()
        {
          /* 
           * If you are coming back to the Login page and there is no login box:
           * logout and load the page again. That fixes the use of the browser
           * back button after login.
           */
          if ($('#login-box').length == 0) {
              var auth = new SSO();
              auth.logOut();
              window.location = '#/login';
          }
            
        }
      
    },
    'student-dashboard': {
        on: function() {            
            var sDash = new sDashboard();                                                                
            sDash.show();
        },
        'settings': {
            on: function() {
                var sDash = new sDashboard();
                sDash.settings();
            },
            level: 3
        }        
    },
    'create-entity': {
        on: function(){
            var childWizard = new createEntity();    
            childWizard.show();
        }
    },
    'raise-mychild': {
            'videos': {
              on: function() {
                  var raiseChild = new raiseEntity(child);
                  raiseChild.showVideos();
              },
              level: 4              
            },
            on: function() {
                var raiseChild = new raiseEntity(child);                
                raiseChild.showQuestions();
                return false;
            }
    },
    'live-life': {
            on: function() {                
                var raiseAdult = new raiseEntity(adult);    
                raiseAdult.showQuestions();
            }
    },
    'student-childfeedback': {
        on: function() {
            child_feedback_obj.show();
        }
    },
    'student-yourfeedback': {
        on: function() {
            adult_feedback_obj.show();
        }
    },
    'student-assignments': {
        on: function() {            
            var assignments_obj = new Assignments();
            assignments_obj.show();
        }
    },    
    'educator-dashboard': {
        on: function() {            
            var eDash = new eDashboard();
            eDash.show();
        }
    },
    'educator-schedule': {
        on: function(){
            var schedule = new eSchedule();
            schedule.show();
        }    
    },
    'educator-questionbank': {
        on: function(){            
            var questionBank = new QuestionBank();
            questionBank.show();
        }    
    }    
}, {
    educator: [
              ]
});

mvlRouter.init('/login');


if ( $('#login').length > 0 ) {
   setLoginActions();                   
}

function getC()
{                    
    if (auth_obj.isLoggedIn() == false) {
        return false;
    }
    
    if (child == false || adult == false) {
        var product_obj = new Product();                
        product_obj.setSimulationIds({
            child: 'MVL Raise Child',        
            adult: 'MVL Adult Simulation',
            active: 'MVL Raise Child'
        });
    }

    $('body').hide();
    page_obj.show();
    $('body').show();
    ieFix();
  }
