var intSlides;
var $active = $('#slideshow div:last');

function slideSwitch() {

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

    $active.animate({opacity: 0.0}, 1000, function() {
        $active.css({'z-index':1, 'opacity': 1 });
   		$next.css({'z-index':intSlides});
   		( $next.next().length ? $next.next() : $('#slideshow div:first') ).css({'z-index':2});
    });

}

$(function() {

	//sort the slides into appropriate order
	arrSlides = $('#slideshow > div');
	intSlides = arrSlides.length;

	for ( i=0; i<intSlides; i++ ) {
		$( arrSlides[i] ).css({ 'z-index': intSlides-i });
	}

	setInterval( 'slideSwitch();', 5000 );

});