$( document ).ready(function () {
	
	var blocks = $('#content-home-right #content_buy_ticket .block');
	var block_scrollTop = false;
	var block_scrollTop_step = $(blocks).innerHeight();
	var block_scrollTop_cur_step = 0;
	var block_scrollTop_max_step = $(blocks).length;
	var container_h = $('#content_buy_ticket').height();
	var steps_visible = Math.ceil( container_h / block_scrollTop_step );
	
	$('#content-home-right #content_buy_ticket').animate({scrollTop: 0}, 1);
	
	$('#content-home-right .gotoUp').click(function(){
		var link = $(this);
		var block = $('#content_buy_ticket', $(link).parent() );

		if( block_scrollTop == false ){
			block_scrollTop = intval($(block).css('scrollTop'));
		}

		block_scrollTop_cur_step = block_scrollTop_cur_step - 1;
		if( block_scrollTop_cur_step < 0 ){
			block_scrollTop_cur_step = 0;
		}

		block_scrollTop = block_scrollTop_step * block_scrollTop_cur_step;
		
		if( block_scrollTop <= 0 ){
			block_scrollTop = 0;
		}
		
		$(block).stop().animate({
			scrollTop: block_scrollTop
		}, 500, function(){
			
			$(link).removeClass('gotoOff');
			if( block_scrollTop <= 0 ){
				$(link).addClass('gotoOff');
			}else{
				if( block_scrollTop_max_step > steps_visible  ){
					$('#content-home-right .gotoDown').removeClass('gotoOff');
				}
				
			}
			
		});

		$(link).trigger('blur');
		return false;
	});

	$('#content-home-right .gotoDown').click(function(){
		var link = $(this);
		var block = $('#content_buy_ticket', $(link).parent() );
		
		if( block_scrollTop == false ){
			block_scrollTop = intval($(block).css('scrollTop'));
		}
		
		if( blocks.length <= steps_visible ){
			block_scrollTop = 0;
		}else{
			
			block_scrollTop_cur_step = block_scrollTop_cur_step + 1;
			
			if( block_scrollTop_cur_step > (blocks.length - steps_visible )  ){
				block_scrollTop_cur_step = block_scrollTop_cur_step - 1;
			}
			
			block_scrollTop = block_scrollTop_step * block_scrollTop_cur_step;
			
		}

		$(block).stop().animate({
			scrollTop: block_scrollTop
		}, 500, function(){
			
			$(link).removeClass('gotoOff');
			if( blocks.length <= steps_visible ){
				$(link).addClass('gotoOff');
			}else{
				$('#content-home-right .gotoUp').removeClass('gotoOff');
			}
			
			if( (block_scrollTop_cur_step + steps_visible ) == block_scrollTop_max_step ){
				$(link).addClass('gotoOff');
			}
			
		});

		$(link).trigger('blur');
		return false;
	});

	if( block_scrollTop_max_step <= steps_visible  ){
		$('#content-home-right .gotoDown').addClass('gotoOff');
	}
	
	$('#content-home-right #content_buy_ticket #content_buy_ticket_inner').bind('mousewheel', function(event, delta) {
		if(delta > 0){
			$('#content-home-right .gotoUp').trigger('click');
		}else{
			$('#content-home-right .gotoDown').trigger('click');
		}
		return false;
    });

		
});