// JavaScript Document

var stopRotate = 'no';
var flipspeed = 5;
var count = 1;

$(document).ready(function() {
	rotateImages();
	
	$('#imageChooser a').hover(function(){
		$(this).parent().addClass("hover");
	},function(){
		$(this).parent().removeClass("hover");
	});
						   
	$('#imageChooser a.itemID').click(function(){
		stopRotate = 'yes';
		$('#imageChooser li').removeClass("active");
		$(this).parent().addClass("active");
		$('#featuredImages .imageHolder').each(function() {
			if($(this).is(":visible"))
			{
				$(this).fadeOut();
			}
		});
		$('#' + $(this).parent().attr("id") + '_holder').fadeIn();
		return false;
	});
});

function viewSection(id) {
	$('#imageChooser li').removeClass("active");
	$('#featImage'+id).addClass("active");
	$('#featuredImages .imageHolder').each(function() {
		if($(this).is(":visible"))
		{
			$(this).fadeOut();
		}
	});
	$('#featImage'+id+'_holder').fadeIn();
}

function rotateImages() {
	if (stopRotate != 'yes') {
		setTimeout(function() { 
			if (count < 4) {
				count++;
			} else {
				count = 1;
			}
			if (stopRotate == 'no')
			{
				viewSection(count);
			}
			rotateImages();
		}, flipspeed*1000);
	}
}
