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

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

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

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

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

$(function() {
	
	(function($){
		$.fn.shuffle = function() {
			return this.each(function() {
				var items = $(this).children();
	      		return (items.length) ? $(this).html($.shuffle(items)) : this;
			});
		}
	 
		$.shuffle = function(arr) {
			for(
	      		var j, x, i = arr.length; i;
	      		j = parseInt(Math.random() * i),
	      		x = arr[--i], arr[i] = arr[j], arr[j] = x
	    	);
	    	return arr;
		}
	})(jQuery);
	
	$('#slideshow').shuffle().children().removeClass("active").parent().find(":eq(0)").addClass("active");	
	
    setInterval( "slideSwitch()", 5000 );
    
});
