'use strict';

// Declare app level module which depends on views, and components
angular.module('myApp', [
  'ngRoute',
  'myApp.posts',
  'myApp.users'
]).
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  $routeProvider.otherwise({redirectTo: '/posts'});
}]).
run(function($rootScope, $location) {
  $rootScope.$on( "$routeChangeStart", function(event, next, current) {
    var path = $location.$$path;
    $('nav a').each(function(){
      if (path.indexOf($(this).attr('href').replace('#', '')) != -1) {
        $(this).parent('li').addClass('active');
      } else {
        $(this).parent('li').removeClass('active');
      }
    })
  });
});
