$(document).ready(function(){
	
	var contentItems = $(".home_showcase ul > .slideItem");
	
	
	/* Animate creates a smoother transition, but IE doesn't support opactiy correctly, rendering this implementation useless.*/
	
	contentItems.each( function(){
		
		$(this).css('opacity', 0);
		$(this).css({opacity: 0,'-ms-filter':"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)",'filter': 'alpha(opacity=0)'});
	}); //rrrrgh IE
	contentItems.hide();
	rotateContent(contentItems,0);
	
	//Testimonials Rotation
	var testimonialItems = $("#testimonial_rotator > div");
	if(testimonialItems.length > 1)
	{
		rotateTestimonialContent(testimonialItems,0); //kick off the recursion.
	}
	
	
	//ShowCase Support
	/*
	$("div[data-showcase-id]").each(function(){
		$(this).simpleSlideshow({showcaseID: $(this).data("showcase-id"), showCaptions: true});
	});
	*/
});

function rotateContent(items, idx)
{
	var iterator = idx;
	var prevIdx = iterator - 1;
	
	if( prevIdx < 0)
	{
		prevIdx = (items.size() -1);
	}
	//$(items[prevIdx]).fadeOut(700);//fadeOut(200);
	$(items[prevIdx]).animate({opacity: 0}, 1000);
	$(items[iterator]).show();
	$(items[iterator]).animate({opacity: 1.0}, 1000);
	$(items[prevIdx]).hide();
	//$(items[iterator]).fadeIn(1000);

	
	if( (iterator + 1) >= (items.size()) )
	{
		iterator = 0;
	}
	else
	{
		iterator++;
	}
	setTimeout( function ()
	{
			rotateContent(items,iterator)
	}, 8000);
}

function rotateTestimonialContent(items, idx)
{
	items.hide();												//hide all the children of the supplied div tag
	$(items[idx]).fadeIn(2500);									//fade in the child at specified index.
				
	var newIdx = 0;
	
	((items.size() - 1) == idx) ? (newIdx = 0) : (newIdx = idx + 1);		//increase the index unless at the last child
				
	setTimeout( function ()
	{
		rotateContent(items,newIdx)
	}, 12000);
	
}
