function slideSwitch() {
	var $active = $('#slideshow IMG.active');	// variable 'active' holds all elements that are 'slideshow IMG.active'
	var $activeTab = $('#insurance-menu li.active');
	var $next =  $active.next().length ? $active.next() // assign 'next' to the next picture
		: $('#slideshow IMG:first');					// or if it's the last image then assign to the first
	var $nextTab = $activeTab.next().length ? $activeTab.next()
		: $('#insurance-menu li:first');

	$nextTab.addClass('active');
	$activeTab.removeClass('active');
				
	$active.addClass('last-active');	// adds a last-active css class to the active element so that we can make sure it is directly behind the "next" image while it fades in
	$next.css({opacity: 0.0})	// set the 'next' element's opacity to 0
		.addClass('active')		// set the 'next' element to the 'active' element
	$active.removeClass('active');
	$next.animate({opacity: 1.0}, 1000, function() {	// change the opacity of next to 1.0 over a period of 1 sec
		$active.removeClass('last-active');
	});	
}
$(function() {
	var playSlideshow = setInterval( "slideSwitch()", 4500 );	// call slideSwitch every 4.5 seconds
	var $tabs = $('#insurance-menu li');
	var $images = $('#slideshow IMG');
	$tabs.mouseover(function() {
		clearInterval(playSlideshow);
		$tabs.removeClass('active');
		$images.removeClass('active last-active');
		$(this).addClass('active');
		var index = $tabs.index(this);
		$images.eq(index).addClass('active');
	});
	$tabs.mouseout(function() {
		playSlideshow = setInterval( "slideSwitch()", 4500 );
	});
});

