jQuery( function( $ ) {

	var fat = 1440; // 1.44s fade animation time

	do_setup( $( '#features' ), 'feature', 6000 ); // 6s interval between transitions

	function do_setup( o, children, interval ) {

		o.children( '.rig_widget_slide' ).each( function () {

			if ( $( this ).height() > 221 )
				$( this ).css( 'top', '-' + ( Math.floor( $( this ).height() / 2 ) - 110 ) + 'px' );

		} );

		$( '#' + children + '-1' ).addClass( 'current prev' ).fadeIn( fat );

		o.data( 'count', o.children( '.rig_widget_slide' ).length ).
			data( 'current', 1 ).
			data( 'interval', setInterval( function () { do_animation( o, children ) }, interval ) );

	}

	function do_animation( o, children ) {

		var $prev = $( '#' + children + '-' + o.data( 'current' ) );

		if ( o.data( 'current' ) == o.data( 'count' ) )
			o.data( 'current', 1 );
		else
			o.data( 'current', o.data( 'current' ) + 1 );

		$( '#' + children + '-' + o.data( 'current' ) ).hide( 1, function () {

			$prev.removeClass( 'current' );

			$( '#' + children + '-' + o.data( 'current' ) ).addClass( 'current prev' ).
				fadeIn( fat, function () { $prev.removeClass( 'prev' ) } );

		} );

	}

} )