﻿$(function(){
	$( '.section' ).each( function(){
		$( 'ul:last-child', this ).addClass( 'last-child' )
		$( this ).prepend( '<div class="bottom"></div>' );
	});
	$( 'dl dd ol li:last-child').addClass( 'last-child' );
	$( 'div#bn-list.section div:last-child').addClass( 'last-child' );
	$( 'div#bn-list.section ul:odd' ).addClass( 'odd' );

	var count = $( '.list ul' ).size();
//	console.log(count);
	var no = 0;
	var unit =20;
	var noMax = Math.ceil( count / unit );
	$( '.ins-navi' ).html( '<div><ul class="step line"><\/ul><ul class="hit line"><\/ul></div>' );
	for ( var i = 1; i <= noMax; i++ ) {
		$( '.hit' ).append( '<li><a href="#">' + i + '<\/a><\/li>' );
	}
	$( '.step' ).append( '<li><a href="#" class="step-prev">前のページ<\/a><\/li>' );
	$( '.step' ).append( '<li><a href="#" class="step-next">次のページ<\/a><\/li>' );
	showHit( $( '.list'), no, noMax, unit );

	$( '.hit li a' ).click( function() {
		no = Number( $( this ).html() );
		no--;
	showHit( $( '.list'), no, noMax, unit );
		return false;
	});

	$( '.step li a' ).click( function() {
		if ( $( this ).attr( 'class' ) == 'step-prev' ) {
			no--;
		} else {
			no++;
		}
	showHit( $( '.list'), no, noMax, unit );
		return false;
	});

});

function showHit( obj, no, noMax, unit ) {
	$( '.step-prev' ).show();
	$( '.step-next' ).show();
	if ( no == 0 ) {
		$( '.step-prev' ).hide();
	}
	if ( no == ( noMax  - 1 ) ) {
		$( '.step-next' ).hide();
	}
	$( '.hit li a' ).removeClass( 'active' );
	$( '.hit' ).each( function() {
		$( 'li:nth(' + no + ') a', this ).addClass( 'active' );
	});
	$( 'ul', obj ).hide();
	for( var i = 0; i < unit; i++ ) {
		$( 'ul:nth(' + ( unit * no + i ) + ')', obj ).show();
	}
}

