angular.module('api.firebase')

	.provider('firebaseSvc', function () {

		var _firebaseUrl = '';
		this.setFirebase = function (name) {
			_firebaseUrl = 'https://' + name.toLowerCase() + '.firebaseio.com/';
		};

		this.$get = [
			'$firebase',
			'$timeout',
			function firebaseSvc($firebase, $timeout) {
				var connTimeout;
				function startTimer() {
					connTimeout = $timeout(function () {
						Firebase.goOffline();
					}, 20000);
				}
				startTimer();

				this.getRef = function (path) {
					var _ref = new Firebase(_firebaseUrl + path);
					return _ref;
				};

				this.getSvc = function (path) {
					// Reduce number of connections to Firebase
					$timeout.cancel(connTimeout);
					Firebase.goOnline();
					startTimer();
					return $firebase(this.getRef(path));
				};
				return this;
			}
		];
	});