$(document).ready(function() {

	activateJSON = function(which) {

		$('#json-holder-'+which).addClass('json-active');

		var $url = website_url + "admin_plugins/quotes/quote_json.asp?q_usage="+which;

		var $theHolder = $('#json-quotes-'+which);
		var $theHeight = $('#json-quotes-'+which).height();
		var $thePage = 0;
		var $theEnd;
		var $theDelay = 10000;

		$theHolder.html('<p class="json-loading">Loading quotes...</p>');

		$.getJSON($url, function(data) {

			var $theNumber = data.html.length;

			$theEnd = $theNumber - 1;
			$theHolder.height($theHeight * $theNumber);
			$theHolder.html(data.html.join(""));

			setTimeout(function(){moveTo($thePage);}, $theDelay);

		});



		function moveTo($lastPage) {
			$thePage = $lastPage + 1;

			if($thePage == $theEnd) {
				$thePage = 0;
				var $newPos = 0;
			} else {
				var $newPos = 0 - ((($thePage) * 186) + $thePage);
			}

			$($theHolder).animate({ top : $newPos }, 1000);
			setTimeout(function(){moveTo($thePage);}, $theDelay);
		};

	};


	activateJSON('client');
	activateJSON('cand');


});