// JavaScript Document
var isRotating = 0; /* Controls "button mashing" (ie. repeated clicks of the buttons). */
var isStopped = 0;
var $j = jQuery.noConflict();
var clicked = 0;
var index;

$j("document").ready(function() {
	//rotate = setInterval("rotateNext()", 6000);
	$j('#thumbs-featured span').click(function () {
		index = $j('#thumbs-featured span').index(this);
		var current_index = $j('#showcase a').index($j('.current'));
		if ( index == current_index ){
			return;
		}
		else{
			clicked = 1;
			rotateNext();
		}
	});
		
});


function rotateNext() {
	if(isRotating == 1){ return; }
	isRotating = 1;
	oCurPhoto = $j('#showcase div.current');
	oCurThumb = $j('#thumbs-featured span.current-thumb');
	if ( clicked == 0 ){
		var oNxtPhoto = oCurPhoto.next('.slide');
		if (oNxtPhoto.length == 0){
			oNxtPhoto = $j('#showcase div.slide:first');
		}
		var oNxtThumb = oCurThumb.next('span');
		if (oNxtThumb.length == 0){
			oNxtThumb = $j('#thumbs-featured span:first');
		}
	}
	else{
		var oNxtPhoto = $j('#showcase div.slide').eq(index);
		var oNxtThumb = $j('#thumbs-featured span').eq(index);
		clicked = 0;
	}
	oCurPhoto.fadeOut(800,
		function() {
			oCurPhoto.removeAttr('style');
			oCurPhoto.removeClass('current');
		});
	oCurThumb.children('img').animate({ opacity: .3},
		function() {
			oCurThumb.removeAttr('style');
			oCurThumb.removeClass('current-thumb');
		});
	oNxtPhoto.fadeIn(800,
		function() {
			oNxtPhoto.addClass('current');
		});
	oNxtThumb.children('img').animate({ opacity: 1},
		function() {
			oNxtThumb.addClass('current-thumb');
			isRotating = 0;
		});
}

