var vFlag=false;
var vRollScroll = function(e){
	var e = new Event(e);
	e.stop();

	var vDir = (this.id == 'vRollPrev')?1:-1;
	var vWhere = (vDir > 0)?'top':'bottom';
	var vStep = 657;
	var vMax = vStep * 2;
	var myUl = $$('#vRollCnt ul')[0];

	var vPos = vDir*vStep + myUl.getStyle('left').toInt();
	if(vPos > 0) vPos = -1 * vMax;
	if(vPos < (-1 * vMax)) vPos = 0;

	var Toggle = new Fx.Tween(myUl, {
						property: 'left',
						duration: 2000,
						transition: Fx.Transitions.Cubic.easeOut,
						onComplete: function(a){
							vIndex = 3 + 3 * vDir;

							var vMoving = a.getElements('li').filter(function(item,index){return (index >= vIndex && index <= (vIndex + 2));});
							
							if(vDir > 0)  {
								vMoving = vMoving.reverse();
							}
							vMoving.each(
								function(li){
									li.inject(myUl,vWhere);
								}
							);
							
							myUl.setStyle('left', '-657px');
							
							vFlag = false;

						}
					});

	if(!vFlag){
		vFlag = true;
		Toggle.start(vPos + "px");
	}

}


var vRollScrollStriscia = function(e){
	var e = new Event(e);
	e.stop();
	var vDir = (this.id == 'vRollPrevStriscia')?1:-1;
	var vWhere = (vDir > 0)?'top':'bottom';
	
	var vStep = 640;
	var vMax = 5760;
	var myUl = $$('#vRollCntStriscia ul')[0];
	var vPos = vDir*vStep + myUl.getStyle('left').toInt();
	if(vPos > 0) 
		vPos = -1 * vMax;
	if(vPos < (-1 * vMax)) 
		vPos = 0;
	//vPos = (this.id == 'vRollPrevStriscia')?3200:-3200;
	var Toggle = new Fx.Tween(myUl, {
		property: 'left',
		duration: 2000,
		transition: Fx.Transitions.Cubic.easeOut,
		onComplete: function(a){
			//vIndex = -1*vPos/vStep;
		
			
			var vMoving = a.getElements('li').filter(
				function(item,index){
					if(vDir>0)
						return (index==8);
					else	
						return (index==0);
				}
			);
			if(vDir > 0) { 
				salto=vPos-vStep;
			}
			else
				salto=vPos+vStep;

			vMoving.each(
				function(li){
					li.inject(myUl,vWhere);
				}
			);
			
			myUl.setStyle('left', salto+'px');
							
			vFlag = false;
		}
	});
	if(!vFlag){
		vFlag = true;
		Toggle.start(vPos + "px");
	}

}


var vInit = function(){

	$$('#vRoll a.vRollArrow').each(
		function(a){
			a.addEvent('click',vRollScroll);
		}
	);
	
	$$('#vRollStriscia a.vRollArrowStriscia').each(
		function(a){
			a.addEvent('click',vRollScrollStriscia);
		}
	);
	
	if(window.location.pathname == '/' || window.location.pathname == '/index.php'){
		$$('ul.vSwitcher a').each(function(a){
			a.addEvent('click', vChartSwitch);
		});
		$$('div#vLastUploaded h2.vTitle a').each(function(a){
			a.addEvent('click', vEditorialSwitch);
		});
	}
}

window.addEvents({
	'domready':vInit
});
