/**
 * @author Lupatus (michal.kluszewski@firma.o2.pl)
 * @package kumple.pl
 * @subpackage js-script
 * @copyright o2.pl 2005-2007
 *
 * $Revision: 243 $
 * $LastChangedDate: 2007-06-27 20:24:04 +0200 (Wed, 27 Jun 2007) $
 */


var o2_BlogViewer = Class.create( );

o2_BlogViewer.prototype = {
	
	pos : 0,
	
	width : -1,
	
	max : 0,
	
	min : 0,
	
	box_width : 420,
	
	jump : 70,
	
	initialize : function( ) {
		
	},
	
	exec : function( action , params ) {
		
		if( this.width == -1 && action.match( /^(new|old)er\-date$/ ) ) {
			this.width = params.width;
			this.pos   = params.pos;
			this.min   = this.box_width - this.width;
			if( this.min >= 0 ) {
				this.max = this.min;
			}
		}
		
		switch( action ) {
			case 'newer-date':
				if( this.pos > this.min ) {
					var np = this.pos - this.jump;
					if( np <= this.min ) {
						np = this.min;
						$( 'blog-btn-newer-on' ).hide( );
						$( 'blog-btn-newer-off' ).show( );
					}
					if( this.pos == this.max && np < this.max ) {
						$( 'blog-btn-older-on' ).show( );
						$( 'blog-btn-older-off' ).hide( );
					}
					this.pos = np;
					new Effect.Move( 'blog-dates' , { x: this.pos , y: 0 , mode: 'absolute' } );
				}
			break;
			
			case 'older-date':
				if( this.pos < this.max ) {
					var np = this.pos + this.jump;
					if( np >= this.max ) {
						np = this.max;
						$( 'blog-btn-older-on' ).hide( );
						$( 'blog-btn-older-off' ).show( );
					}
					if( this.pos == this.min && np > this.min ) {
						$( 'blog-btn-newer-on' ).show( );
						$( 'blog-btn-newer-off' ).hide( );
					}
					this.pos = np;
					new Effect.Move( 'blog-dates' , { x: this.pos , y: 0 , mode: 'absolute' } );
				}
			break;
			
			default:
				Warning( 'BlogViewer unknown action: ' + action );
				Info( params );
			break;
		}
		
		return false;
	}
	
}

var BV = new o2_BlogViewer( );


