
	jQuery.fn.startRotation = function(settings) {

		settings = jQuery.extend({
			timeout: 4000
			}, settings)

		var stopRotation = false;
		var currententry = 0;
		var name = $(this).attr("id");
		var entries = $("." + name + "entry");

		function rotate() {
			currententry ++;
			if (currententry >= entries.length) {
				currententry = 0;
			}
			showEntry(currententry);
			continueRotation(settings.timeout);
		}

		function showEntry() {
				callAjaxRequest('/specials/rotation/rotate.do', true, function(xml) {
					var resultDiv = document.getElementById("rotation");
					resultDiv.innerHTML = xml.responseText;
				})
		}

		function continueRotation(timeout) {
			setTimeout(function() {
				if (stopRotation) {
					continueRotation(1000);
				}
				else {
					rotate();
				}
			},
			timeout);
		}

		function initializeHoverRotation() {
			var links = $("." + name + "link");
			for (var i=0; i < entries.length; i++) {
				var page = $("#" + name + "page_" + i);
				page.attr({
					name: i,
					href: $(links[i]).attr("href")});
				$("#" + name + "page_" + i).bind("mouseenter",
					function() {
						currententry = $(this).attr("name");
						showEntry();
					}
				);
			}
		}

		$("#rotation").hover(
			function() {
				stopRotation = true;
			},
			function() {
				stopRotation = false;
			}
		);

		initializeHoverRotation();
		continueRotation(settings.timeout);
	};

	$().ready(function() {
		$("#rotation").startRotation(4000);
	});
