function slideSwitch() {

	// grab the current slide
	var $active = $('#slideShow DIV.active');
	
	if( $active.length == 0 ) $active = $('#slideShow .panel:last');
	
	// grab the next slide
	var $next = $active.next().length ? $active.next() : $('#slideShow .panel:first');
	


	$active.addClass('last-active');
	
	// animate fade out for current slide
	$active.css({opacity: 1.0})
			.animate( {opacity: 0.0}, 1500);
	
	// animate fad in for next slide
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1500, function() {
			$active.removeClass('active last-active');
			});
			
	// change and clean up classes
	$currentLink = $('#galleryNav A.activeLink');
	$nextLink = $currentLink.next().length ? $currentLink.next() : $('#galleryNav .galleryLink:first');
	
	$currentLink.removeClass('activeLink');
	$nextLink.addClass('activeLink');
			
}


function setSlide( newSlideId, slide )
{
	stopAnimation();
	
	// get the current link and remove active
	$currentLink = $('#galleryNav A.activeLink');
	$currentLink.removeClass('activeLink');
	
	// make the clicked link active
	$newLink = $('#'+newSlideId);
	$newLink.addClass('activeLink');
	
	
	// animate only if new slide is different from current
	var oldSlideId = $currentLink.attr("id");
	
	if( oldSlideId != newSlideId )
	{
		//hide the current slide
		var $active = $('#slideShow DIV.active');
		
		$active.addClass('last-active');
		
		$active.css({opacity: 1.0})
				.animate( {opacity: 0.0}, 500);
		
		
		//show the new slide
		var $newSlide = $('#'+slide);
		
		
		$newSlide.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 500, function() {
				$active.removeClass('active last-active');
				});
	}		
	
}


function stopAnimation()
{
	if ($intervalId != 0)
	{
		clearInterval( $intervalId );
		$intervalId = 0;
	}
}
