(function() {

	'use strict';

	function countryService($http) {

		var self = this;

		self.extractFromPlace = function(country, next) {

			if(country) {

				var arr = country.split(',');

				if(arr.length == 2) {

					$http.get('countries.json')
						.success(function(countries) {

							var countryCode = _.findWhere(countries, {name:arr[1].trim()});

							return next(null, countryCode['alpha-2'].toLowerCase());

						});
					
				}

			}

			return next(null, 'afg');
		}

	}

	angular.module('temblorpe')
		.service('Country', countryService);

})();