angular.module("vsuhanov.Config", [])
	.provider("Config", function () {

							var config = {};

							var optionHandlers = {};

							/**
							 *
							 * @param option
							 * @param handler
							 */
							this.registerOptionHandler = function (option, handler) {
								optionHandlers[option] = optionHandlers[option] || [];
								optionHandlers[option].push(handler);
							};

							/**
							 *
							 * @param _config
							 */
							this.configure = function (_config) {
								angular.extend(config, _config);
							};

							/**
							 *
							 * @param _config
							 */
							this.defaults = function (_config) {
								angular.extend(_config, config);
								config = _config;
							};

							this.$get = [function () {
								return {
									getConfig : function () {
										return config;
									}
								}
							}];
						}).run(function (Config) {
										 var config = Config.getConfig();
										 var iterator = function (config, currentKey, callback) {

											 angular.forEach(config, function (value, key) {
												 var fullKey = (currentKey && currentKey + ".") + key;
												 if (config.hasOwnProperty(fullKey)) {
													 return callback(fullKey, config[fullKey]);
												 }
												 if (angular.isObject(value)) {
													 iterator(value, fullKey, callback);
												 }
											 })
										 }
									 });