function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});


            // Galleriffic
            // Initially set opacity on thumbs and add
			// additional styling for hover effect on thumbs
			var onMouseOutOpacity = 0.67;
			$('#thumbs-adv ul.thumbs li').css('opacity', onMouseOutOpacity)
				.hover(
					function () {
						$(this).not('.selected').fadeTo('slow', 1.0);
					}, 
					function () {
						$(this).not('.selected').fadeTo('slow', onMouseOutOpacity);
					}
				);

			$(document).ready(function() {
				// Initialize Advanced Galleriffic Gallery
				var galleryAdv = $('#gallery-adv').galleriffic('#thumbs-adv', {
					delay:                  3000,
					numThumbs:              12,
					preloadAhead:           10,
					enableTopPager:         true,
					enableBottomPager:      true,
					imageContainerSel:      '#slideshow-adv',
					controlsContainerSel:   '#controls-adv',
					captionContainerSel:    '#caption-adv',
					loadingContainerSel:    '#loading-adv',
					renderSSControls:       true,
					renderNavControls:      true,
					playLinkText:           'Start',
					pauseLinkText:          'Stop',
					prevLinkText:           '&lsaquo; Poprzednie',
					nextLinkText:           'Nastêpne &rsaquo;',
					nextPageLinkText:       'Nastêpna &rsaquo;',
					prevPageLinkText:       '&lsaquo; Poprzednia',
					enableHistory:          true,
					autoStart:              true,
					onChange:               function(prevIndex, nextIndex) {
						$('#thumbs-adv ul.thumbs').children()
							.eq(prevIndex).fadeTo('slow', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('slow', 1.0);
					},
					onTransitionOut:        function(callback) {
						$('#slideshow-adv, #caption-adv').fadeOut('slow', callback);
					},
					onTransitionIn:         function() {
						$('#slideshow-adv, #caption-adv').fadeIn('slow');
					},
					onPageTransitionOut:    function(callback) {
						$('#thumbs-adv ul.thumbs').fadeOut('slow', callback);
					},
					onPageTransitionIn:     function() {
						$('#thumbs-adv ul.thumbs').fadeIn('slow');
					}
				});
				
			});

