$(document).ready(function()
{
	var ravingFans = $('#ravingfans');

	if(ravingFans != null)
	{
		slideShow(ravingFans, 5000);
	}

	var testimonials = $('#testimonials');

	if(testimonials != null)
	{
		slideShow(testimonials, 7500);
	}

	// clear the email box on focus
	$('#txtNewsletter').focus(function() { 
		if($('#txtNewsletter').val() == 'email@domain.com')
		{
			$('#txtNewsletter').val(''); 
			$('#txtNewsletter').removeClass('dimmed');
		}
	} );

	$('#txtNewsletter').blur(function() {
		if($('#txtNewsletter').val() == '')
		{
			$('#txtNewsletter').val('email@domain.com');
			$('#txtNewsletter').addClass('dimmed');
		}
	} );
});

function slideShow(context, speed)
{
	$('ul.slideshow li', context).css({opacity:0.0});
	$('ul.slideshow li:first', context).css({opacity:1.0});

	// remove the hidden class
	$('ul.slideshow li', context).removeClass('hidden');

	// start the show
	var timer = setInterval(function(){gallery(context);}, speed);

	$('ul.slideshow').hover(
		function()
		{
			clearInterval(timer);
		},
		function()
		{
			timer = setInterval(function(){gallery(context);}, speed);
		}
	);
}

function gallery(context)
{
	var current = ($('ul.slideshow li.show', context) ? $('ul.slideshow li.show', context) : $('ul.slideshow li:first', context));
	var next = ((current.next().length) ? current.next() : $('ul.slideshow li:first', context));
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000).removeClass('show');
}

