/**
 * Functionailty to control animation between markers.
 */
Synergy.MapAnimation = new function()
{
	var cycleTimeout = false;
	var cycleRunning = false;

	function runCycle()
	{
		cycleTimeout = setTimeout(function()
		{
			if( cycleRunning ) {
				Synergy.Options.map.cycle(runCycle);
			}
		}, Synergy.Options.animationDelay, runCycle);
	}

	/**
	 * Start the animation.
	 */
	this.start = function()
	{
		if( false == cycleRunning ) {
			cycleRunning = true;
			Synergy.Options.map.cycle(runCycle);
		}
	};

	/**
	 * Stop the animation.
	 */
	this.stop = function()
	{
		Synergy.Options.map.cancelActions();
		clearTimeout(cycleTimeout);
		cycleTimeout = false;
		cycleRunning = false;
	};

	/**
	 * Cancel the idle timer.
	 */
	this.cancelTimer = function()
	{
		$(document).idleTimer('destroy');
		$.data(document, 'idleTimer', '');
	};

	/**
	 * Start the idle timer.
	 */
	this.startTimer = function()
	{
		var data = $.data(document, 'idleTimer');

		if( data === undefined || data === '' ) {
			$.idleTimer(Synergy.Options.animationTimeout);

			$(document).bind("idle.idleTimer", function()
			{
				Synergy.MapAnimation.start();
			});
		}

	};

	$(document).click(this.stop);
	$(document).dblclick(this.stop);
	$(document).mousewheel(this.stop);
};
