var Carusel = new Class({
				INTERVAL_TIME: 3000,
				POSITION_X_BALANCE: 8,
				FADE_ANIMATION: true,
				
				elements: {},
				images: [],
				interator: 0,
				timer: null,
				fx: null,
				
				initialize: function(){
					this.elements = {
						mainImage: $('o_main_img_box').getElement('img'),
						miniatureBorder: $('miniature_border'),
						miniature: $('miniature')
					};

					var minaitureMargin = this.elements.miniature.getElement('img').getStyle('margin-right').toInt()
					var miniatureWidth = this.elements.miniature.getElement('img').getStyle('width').toInt();
					var borderWidth = this.elements.miniatureBorder.getStyle('border-top-width').toInt();
					
					this.setImages();
					this.fx = new Fx.Tween( this.elements.miniatureBorder, {link: 'chain'} );
				},
				
				setImages: function(){
					this.elements.miniature.getElements('img').each(function( elem, index ){
						elem.addEvent( 'click', this.clickEvent.bind(this) );
						elem.addEvent( 'mouseover', function(){ return false; } );
						this.images.push( elem ); 
						
						if( 0 != index && this.FADE_ANIMATION ){
							elem.fade( 0.6 );
						}
					}.bind(this));;
				},
				
				start: function(){
					this.timer = setInterval(  this.execiute.bind( this ), this.INTERVAL_TIME );
				},
				
				execiute: function(){
					this.images[ this.interator ]
					this.interator = ( this.interator >= (this.images.length - 1) ) ? 0 : this.interator + 1;
					this.animate();
				},
				
				animate: function(){
					var actualImage = this.images[ this.interator ];
					var prevImage = ( this.interator != 0 ) ? this.images[ this.interator - 1 ] : this.images.getLast();
					
					this.images.each( function( item ){
						item.removeClass( 'selected' );
						if( this.FADE_ANIMATION ){
							item.fade( 0.6 );
						}
					}, this);
					actualImage.addClass( 'selected' );
					if( this.FADE_ANIMATION ){
						actualImage.fade( 1 );
					}
					
					var newLeft = actualImage.offsetLeft;
					var newTop = actualImage.offsetTop;
					
					if( prevImage.offsetTop == newTop ){
						this.fx.start( 'top', newTop );
						this.fx.start( 'left', newLeft + this.POSITION_X_BALANCE );
						this.fx.start( 'left', newLeft - this.POSITION_X_BALANCE );
						this.fx.start( 'left', newLeft );
					}
					else{
						this.fx.start( 'left', newLeft );
						this.fx.start( 'top', newTop + this.POSITION_X_BALANCE );
						this.fx.start( 'top', newTop - this.POSITION_X_BALANCE );
						this.fx.start( 'top', newTop );
					}
					
					var bigImgSrc = actualImage.get('alt').split('|');
				
					this.elements.mainImage.set( 'src', bigImgSrc[0] );
					this.elements.mainImage.getParent().set( 'href', bigImgSrc[1] );
				},
				
				clickEvent: function( e ){
					// bloced automat
					clearInterval( this.timer );
					this.fx.cancel();
					
					this.interator = this.images.indexOf( e.target );
					this.animate();
					this.start();
					
					return false;
				}
			});
