$( document ).ready( function() {

	// external links w/tracking
	$( '#main a[rel="external"]' ).attr( 'title', 'Visit website (Opens in a new window)' ).click( function() {
		return ! window.open( '/?out=' + this.href );
	});

	// external/dev links w/o tracking
	$( '#footer a[rel="external"], #main a[rel="new"]' ).click( function() {
		return ! window.open( this.href );
	});

	// paginate content
	var use_next_title = false;
	var use_next_numbers = false;
	var max_height = 0;
	$( '#paginate' ).children( 'div:not(:first)' ).hide();
	$( '#paginate div.element' ).css({ position: 'absolute', top: 0, left: 0 }).each( function( i ) {
		if( $( this ).height() > max_height ) {
			max_height = $( this ).height();
		}
		var n = ( i + 1 );
		var p = ( i - 1 );
		if( use_next_numbers && n > 1 ) {
			$( 'h1', this ).prepend( n + '. ' );
		}
		n = ( n == $( '#paginate div.element' ).size() ? 0 : n );
		$( this ).append( '<p class="next' + ( ! use_next_title ? ' lw' : '' ) + '" title="Click to find out..." style="position: absolute; bottom: -23px;">' + ( use_next_title ? '<span><strong>Next</strong>: ' + $( '#paginate div:eq(' + n + ') h1' ).text() + ' &#8250;</span>' : 'What&#8217;s Next?' ) + '</p>' ).find( 'p.next' ).click( function() {
			$( '#paginate' ).children( 'div:eq(' + i + ')' ).fadeOut( 'fast' );
			$( '#paginate' ).children( 'div:eq(' + n + ')' ).fadeIn( 'slow' );
		});
		if( p >= 0 ) {
			$( this ).append( '<p class="prev" title="Back to previous page" style="position: absolute; bottom: -20px; right: 10px; color: #666; font-size: .9em; cursor: pointer;">Back</p>' ).find( 'p.prev' ).click( function() {
				$( '#paginate' ).children( 'div:eq(' + i + ')' ).fadeOut( 'fast' );
				$( '#paginate' ).children( 'div:eq(' + p + ')' ).fadeIn( 'slow' );
			});
		}
	});
	$( '#paginate div.element' ).css( 'height', ( max_height + 23 ) + 'px' );
	$( '#paginate div.element:last p.next' ).html( 'Back to Start' );

});