var slide_position = 0;
var count;
var vCarousel;
var dir = +1;
var timer;
var step = 1;
var mouse_over = false;

document.observe('dom:loaded',function()
{
	var arrow_top = $('right_arrow_top');
	var arrow_bottom = $('right_arrow_bottom');
	count = $('right_products').select('li').length;
//	var products = $('right_products');

	//chvilku poeká na naetení obrázku
	setTimeout(function() {
		vCarousel = new UI.Carousel("right_bottom", { direction: "vertical", scrollInc: 1 } );
		timer = new PeriodicalExecuter(__move,4);
	}, 1000);

	arrow_top.observe('mouseenter',function(ev)
	{
		mouse_over = true;
		timer.stop();
		dir = +step;
		timer = new PeriodicalExecuter(__move,0.3);
	});
	arrow_top.observe('mouseleave',function(ev)
	{
		mouse_over = false;
		timer.stop();
	});
	arrow_bottom.observe('mouseover',function(ev)
	{
		mouse_over = true;
		timer.stop();
		dir = -step;
		timer = new PeriodicalExecuter(__move,0.3);
	});
	arrow_bottom.observe('mouseleave',function(ev)
	{
		mouse_over = false;
		timer.stop();
	});
	/*
	products.observe('mouseenter',function(ev)
	{
		timer.stop();
	});
	products.observe('mouseleave',function(ev)
	{
		timer = new PeriodicalExecuter(__move,4);
	});
	*/
});

function __move()
{
	if(slide_position == 0 && !mouse_over) dir = +step;
	else if(slide_position == (count - 1) && !mouse_over) dir = -step;

	slide_position = slide_position+dir;
	vCarousel.scrollTo(vCarousel.currentIndex()+dir);
}

