'use strict';

(function () {
	var RouteCtrl = function($scope, $routeParams, $q, $log, $templateCache, GlobalService) {
		//lazy load needed sources (js/css/i18n) by URL
		//TODO preload HTML too
		var nav = $routeParams.nav;
		window.REQUIRE.load("../i18n/app_" + GlobalService.getConfig('language') + ".json", null, function (response) {
			GlobalService.setI18N('app', response);
		});
		window.REQUIRE.load("../i18n/" + nav + "_" + GlobalService.getConfig('language') + ".json", null, function (response) {
			GlobalService.setI18N(nav, response);
		});
		window.REQUIRE.load('ctrls/' + nav + "-ctrl.js");
		window.REQUIRE.load('../tpl/' + nav + '.html', ['ctrls/' + nav + "-ctrl.js"], function (template) {
				$templateCache.put('tpl/' + nav + '.html', template);
				$scope.templateUrl = 'tpl/' + nav + '.html';
				if( ! $scope.$$phase) {
					setTimeout(function () {$scope.$apply();}, 0);
				}
			}
		);
	};
	window.APP = angular.module("Web", window.SETTINGS.ngModules)
		.config(function($routeProvider) {
			$routeProvider.when('/:nav?/:view?/:id?', {
				templateUrl: "url-router.html",
				controller: RouteCtrl,
				reloadOnSearch: false
			});
		}).config(function ($controllerProvider) {
			APP.controller = $controllerProvider.register;
		}).config(function ($compileProvider) {
			APP.directive = $compileProvider.directive;
		}).config(function ($locationProvider) {
			$locationProvider.html5Mode(true);
		}).config(function($resourceProvider) {
			$resourceProvider.defaults.stripTrailingSlashes = false;
		}).config(function ($httpProvider) {
			$httpProvider.interceptors.push(function($q, $injector, $rootScope, $timeout) {
				return {
			    	'request': function(config) {
						if ($rootScope.httpRequestTimeout) {
							config.timeout = $rootScope.httpRequestTimeout.promise;
						}
					    $rootScope.$broadcast('xhrLoading', 1);
						return config;
					}, 'response': function(response) {
						$rootScope.$broadcast('xhrLoading', -1);
						return response;
					},'responseError': function(rejection) {
						$rootScope.$broadcast('xhrLoading', -1);
						if (rejection.status >= 500 || rejection.status === 404) {
							$rootScope.$broadcast('responseError', rejection);
						} else if (rejection.status <= 403 && rejection.status >= 401) {
							$rootScope.$broadcast('authError', rejection);
						} else if (rejection.status !== 0) {
							// when is not one of [unexpected,not found,unauthorized,canceled,aborted] then propagate rejection
							return $q.reject(rejection);
						}
					}
				};
			});
		}).value('$anchorScroll', angular.noop);

	// preload first controller - performance improvement
	var hashParsed = location.hash.split("/");
	if (hashParsed && hashParsed[1]) {
		window.REQUIRE.load('ctrls/' + hashParsed[1].split("?")[0] + "-ctrl.js");
	}
} ());
@@ -2591,16 +2591,197 @@
 noop);%0A%0A
+%09// performance directive%0A%09window.APP.directive(%22miloDisableAnimations%22, function ($animate) %7B%0A%09%09return function (scope, element) %7B%0A%09%09%09$animate.enabled(false, element);%0A%09%09%7D;%0A%09%7D);%0A%0A%0A
 %09// prel

add performance directive - milo disable animations