angular.module('umbraco.services')
	.factory('helpService', function ($http, $q, umbRequestHelper) {
		var helpTopics = {};

		var defaultUrl = "http://our.umbraco.org/rss/help";
		var tvUrl = "http://umbraco.tv/feeds/help";

		function getCachedHelp(url){
			if(helpTopics[url]){
				return helpTopics[cacheKey];
			}else{
				return null;
			}
		}

		function setCachedHelp(url, data){
			helpTopics[url] = data;
		}

		function fetchUrl(url){
			var deferred = $q.defer();
			var found = getCachedHelp(url);

			if(found){
				deferred.resolve(found);
			}else{

				var proxyUrl = "dashboard/feedproxy.aspx?url=" + url; 
				$http.get(proxyUrl).then(function(data){
					var feed = $(data.data);
					var topics = [];

					$('item', feed).each(function (i, item) {
						var topic = {};
						topic.thumbnail = $(item).find('thumbnail').attr('url');
						topic.title = $("title", item).text();
						topic.link = $("guid", item).text();
						topic.description = $("description", item).text();
						topics.push(topic);
					});

					setCachedHelp(topics);
					deferred.resolve(topics);
				});
			}

			return deferred.promise;
		}

		var service = {
			findHelp: function (args) {
				var url = service.getUrl(defaultUrl, args);
				return fetchUrl(url);
			},

			findVideos: function (args) {
				var url = service.getUrl(tvUrl, args);
				return fetchUrl(url);
			},

			findLessons: function (path, baseurl) {

			    //build request values with optional params
			    var qs = "?path=" + path;
                if (baseurl){
			        qs += "&baseurl=" + encodeURIComponent(baseurl);
			    }
			    
                var url = umbRequestHelper.getApiUrl(
                        "helpApiBaseUrl",
                        "GetLessons" + qs);
                
			    return  umbRequestHelper.resourcePromise(
                        $http.get(url), "Failed to get lessons content");
			},

			getLessonSteps: function (path, baseurl) {

			    var qs = "?path=" + path;
			    if (baseurl) {
			        qs += "&baseurl=" + encodeURIComponent(baseurl);
			    }

			    var url = umbRequestHelper.getApiUrl(
                        "helpApiBaseUrl",
                        "GetLessonSteps" + qs);
    
			    return umbRequestHelper.resourcePromise(
                        $http.get(url), "Failed to get lessons content");
			},

			getContextHelpForPage: function (section, tree, baseurl) {

			    var qs = "?section=" + section + "&tree=" + tree;

			    if (tree) {
			        qs += "&tree=" + tree;
			    }

			    if (baseurl) {
			        qs += "&baseurl=" + encodeURIComponent(baseurl);
			    }

			    var url = umbRequestHelper.getApiUrl(
                        "helpApiBaseUrl",
                        "GetContextHelpForPage" + qs);

			    return umbRequestHelper.resourcePromise(
                        $http.get(url), "Failed to get lessons content");
			},

			getUrl: function(url, args){
				return url + "?" + $.param(args);
			}
		};

		return service;

	});
@@ -1378,971 +1378,8 @@
 %7D,%0A%0A
-%09%09%09findLessons: function (path, baseurl) %7B%0A%0A%09%09%09    //build request values with optional params%0A%09%09%09    var qs = %22?path=%22 + path;%0A                if (baseurl)%7B%0A%09%09%09        qs += %22&baseurl=%22 + encodeURIComponent(baseurl);%0A%09%09%09    %7D%0A%09%09%09    %0A                var url = umbRequestHelper.getApiUrl(%0A                        %22helpApiBaseUrl%22,%0A                        %22GetLessons%22 + qs);%0A                %0A%09%09%09    return  umbRequestHelper.resourcePromise(%0A                        $http.get(url), %22Failed to get lessons content%22);%0A%09%09%09%7D,%0A%0A%09%09%09getLessonSteps: function (path, baseurl) %7B%0A%0A%09%09%09    var qs = %22?path=%22 + path;%0A%09%09%09    if (baseurl) %7B%0A%09%09%09        qs += %22&baseurl=%22 + encodeURIComponent(baseurl);%0A%09%09%09    %7D%0A%0A%09%09%09    var url = umbRequestHelper.getApiUrl(%0A                        %22helpApiBaseUrl%22,%0A                        %22GetLessonSteps%22 + qs);%0A    %0A%09%09%09    return umbRequestHelper.resourcePromise(%0A                        $http.get(url), %22Failed to get lessons content%22);%0A%09%09%09%7D,%0A%0A
 %09%09%09g

remove client side lesson functions from core - these will be moved to the starter-kit