function update( version ) {

	if ( typeof version == 'undefined' ) { version = ''; }
	version = version == '' ? update_version : version;

	var entries = jQuery('#entries .entry');
	var lastPostId = entries.size() ? parseInt( jQuery('#entries .entry').eq(0).attr( 'id' ).substr( 6 ), 10 ) : 0;

	if ( typeof lastPostId == 'number' && !isNaN( lastPostId ) ) {
		jQuery.get( version + 'update_' + lastPostId + '.html', function( data ) {

			if ( typeof data != 'undefined' && data != '' ) {

				data = data.replace( /class="entry"/g, 'class="entry hidden"')
				jQuery('#entries').prepend( data );

				jQuery('#entries .entry.hidden').fadeIn('slow', function() {
					jQuery(this).animate( { backgroundColor: '#ffffff' }, 2000, function() {
						jQuery(this).removeClass('hidden');
					});
				});

				move_illustrated();

				if ( jQuery('#entries .entry').size() > pagesize ) {
					while( jQuery('#entries .entry').size() > pagesize ) {
						jQuery('#entries .entry:last-child').remove();
					}
					jQuery('#previous_results').show();
				}

				jQuery('.entry .content a').each( function( e, o ) {
					o.target = '_blank';
				});

				if ( jQuery('#entries .entry').size() > 10 && !panorama_shown ) {
					showPanorama();
				}

				clearTimeout( timeoutId );
				timeoutId = setTimeout( function() { update() }, 10 );

			}

		} );
	}
	timeoutId = setTimeout( function() { update() }, 10000 );
}

function move_illustrated() {
	if ( jQuery('#top_post').length ) {
		jQuery('#entries .entry.moved').show();
		jQuery('#entries .entry.moved').removeClass('moved');
		var illustrated = jQuery('#entries .entry.illustrated').first();
		if ( illustrated ) {
			var top_post = illustrated.clone();
			top_post.attr( 'id', illustrated.attr('id') + '_moved' );
			jQuery('#top_post').html( top_post );
			illustrated.addClass('moved');
			illustrated.hide();
		} else {
			jQuery('#top_post').html('');
		}
	}
}

function movePanorama() {
	if ( jQuery('.ad_640x360').length ) {
		jQuery('.ad_640x360').prevUntil( '#entries .entry:nth-child(9)', '.entry' ).each( function( i ) {
			jQuery('.ad_640x360').after( jQuery( this ).remove() );
		});
	}
}

jQuery( document ).ready( function() {

	if ( page == 0 ) {
		setTimeout( function() { update() }, 10000 );
		move_illustrated()
	}

	jQuery('.entry .content a').each( function( e, o ) {
		o.target = '_blank';
	});

});

