jQuery.fn.nextPage = function( settings ) {
	settings = jQuery.extend({
		speed : "normal",
		slideBy : 1
    }, settings);
    return jQuery.fn.nextPage.run ( this, settings );
};

jQuery.fn.nextPage.run = function( $this, settings ) {
	var ul = jQuery( "#counterBoardUl", $this );
	var li = jQuery( ".cbli", $this );
	
	if ( li.length > settings.slideBy ) {
		var $next = jQuery( ".next", $this );
		var $back = jQuery( ".back", $this );
		var liHeight = jQuery( li[0] ).height();
		var animating = false;

		ul.css( "height", ( li.length * liHeight ) );

		$next.click(function() {
			if ( !animating ) {
				animating = true;
				offsetTop = parseInt( ul.css( "top" ) ) - ( liHeight * settings.slideBy );
				if ( parseInt( ul.css( "top" ) ) != -960 ) {
					ul.animate({
						top: offsetTop
					}, "normal", function() {
						if( parseInt( ul.css( "top" ) ) == -960 ) {
							$next.attr( "src", "./images/counter_btn_left_off.gif" );
						}
						else
						{
							$next.attr( "src", "./images/counter_btn_left_on.gif" );
						}
						if ( parseInt( ul.css( "top" ) == 0 ) ) {
							$back.attr( "src", "./images/counter_btn_right_off.gif" );
						}
						else
						{
							$back.attr( "src", "./images/counter_btn_right_on.gif" );
						}
						
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		
		$back.click(function() {
			if ( !animating ) {
				animating = true;
				offsetTop = parseInt( ul.css( "top" ) );

				if ( offsetTop != 0 ) {
					
					//$next.css( "display", "block" );
					var check = offsetTop + liHeight;
					ul.animate({
						top: offsetTop + liHeight
					}, settings.speed, function() {
						if( parseInt( ul.css( "top" ) ) == -960 ) {
							$next.attr( "src", "./images/counter_btn_left_off.gif" );
						}
						else
						{
							$next.attr( "src", "./images/counter_btn_left_on.gif" );
						}
						if ( parseInt( ul.css( "top" ) ) == 0 ) {
							$back.attr( "src", "./images/counter_btn_right_off.gif" );
						} else {
							$back.attr( "src", "./images/counter_btn_right_on.gif" );
						}
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		
	}
};