/* =========================================================

switcher.js

Date: 2008-04-29
Author: Plus Three LLC (http://plusthree.com/)

An interface to innerfade.js, to allow for a series of 
images to rotate automatically, along with a control menu
and a start/stop button.

Starting after stopping or manually moving to a particular
image will resume at the next image after the one currently
selected.

// ========================================================= */

$(document).ready(function () {

	/* feature story switcher */
	
	$('#fade').innerfade({
		speed: 2000,
		timeout: 8000,
		containerheight: 340,
		tracker: 'switcher',
		trackerclass: 'selected'
	});
	
	$('#stop').click(function() {
		clearTimeout($('#fade').data('timer'));
		$('#fade').removeData('timer');
		$('#stop').hide();
		$('#start').show();
		return false;
	});
	

	$('#start').click(function() {
		$('#start').hide();
		$('#stop').show();
		$('.selector').removeClass('selected');
		$('#fade').innerfade({
			speed: 2000,
			timeout: 8000,
			containerheight: 340,
			tracker: 'switcher',
			trackerclass: 'selected'
		});
		var id = $('#fade').data('next');
		$('#' + id).addClass('selected');
		return false;
	});

	$('.selector').click(function() {
		if (this.id == 'stop' || this.id == 'start') {
			return;
		}
		
		if($('#fade').data('timer')) {
			clearTimeout($('#fade').data('timer'));
			$('#fade').removeData('timer');
			$('#stop').hide();
			$('#start').show();
		}
		
		var id = Number(this.id);
		$('.selector').removeClass('selected');
		$(this).addClass('selected');
		$('#fade li:visible').fadeOut(2000);
		$('#feature_' + id).fadeIn(2000);
		var num = $('#fade').data('num_elements');
		if (id < num) {
			$('#fade').data('next', id);
		} else {
			$('#fade').data('next', 0);
		}
		return false;
	});
});