var newsLoader = {
				
	run: function(options) {
		var activeUrl = options.searchUrl;

		handleMoreButton();
		updateCount();
		handleForm();
		
		
		function handleMoreButton() {
			options.moreButton.click(function(e) {
				getMore(activeUrl);
				e.preventDefault();
			});
		} // end handleMoreButton()
		
		
		function handleForm() {
			if(options.searchTermInput.val()) {
				options.searchTermInput.val('');
			}
			options.searchTermInput.inlineLabel();

			options.searchForm.submit(function(e) {
				options.page = 1;
				activeUrl = options.searchUrl + "/term:" + options.searchTermInput.val();
				getMore(activeUrl, function() {
					options.clearFormLink.show();
					$('li', options.relatedList).remove();
				});
				e.preventDefault();
			});

			options.clearFormLink.click(function(e) {
				options.searchTermInput.val('').inlineLabel();

				options.page = 1;
				activeUrl = options.searchUrl;
				getMore(activeUrl, function() {
					options.clearFormLink.hide();
					$('li', options.relatedList).remove();
				});
				e.preventDefault();
			});
		} // end handleForm()
		
		
		function getMore(url, callback) {
		  options.page++;
      
			$.getJSON(url + "/limit:"+options.limit+"/page:"+options.page, function(response) {
				if($.isFunction(callback)) {
					callback();
				}
				options.totalCount = response.totalCount*1;
				options.relatedList.append(response.view);
			 	if(options.totalCount <= options.limit*options.page) {
					options.moreButton.hide();
					options.noResultsMsg.show();
				} else {
					options.moreButton.show();
					options.noResultsMsg.hide();
				}
				$('li:first', options.relatedList).addClass('first');
			});
		}; // end getMore()
		
		
		function updateCount() {
			$.getJSON(options.countUrl , function(count) {	
				options.totalCount = count * 1;
				options.relatedTab.append(' <span class="note">['+count+']</span>');
				if(options.totalCount > options.limit*options.page) {
					options.moreButton.show();
				} else {
					options.moreButton.hide();
				}
			});
		} // end updateCount()

		
	} // end run
	
}
