var sldr;
var lastScroll = 1;

document.observe('dom:loaded', function(){
	$$('.pub_link').each(function(element){
		element.onclick = function(){
			faqObj = element.up().next();
			Effect.toggle(faqObj, 'blind', { duration: 0.5 });
			if (element.className == 'pub_link'){
				element.className = 'pub_link active_link';
			}else{
				element.className = 'pub_link';
			};
			return false;
		};
	});
	sldr = new Control.Slider('handle','track', {
		range: $R(1, 5),
		values: $R(1, 5),
		sliderValue: [1],
		onChange: function(value) { 
			if(value > lastScroll){
				lastScroll = value;
				gScroll('right',true);
			}else{
				lastScroll = value;
				gScroll('left',true);
			};
		}
	});
});

/*Блокировщик повторных нажатий*/
var unBlocked = true;
function unBlock(){
	unBlocked = true;
}
/*---*/

var gCounter = 1;
function gScroll(direct,isup){
	if(isup){
		gCounter = lastScroll;
	};
	if(direct == 'left' && unBlocked){
		unBlocked = false;
		if(!isup){
			gCounter--;
		};
		if(gCounter <= 0){
			gCounter = gSum;
		};
		if(!isup){
			sldr.setValue(gCounter);
		};
		new Effect.Move('scroll', {x: ((gCounter-1)*-880), y: 0, mode: 'absolute', duration: 0.7});
		unBlock.delay(0.8);
	};
	if(direct == 'right' && unBlocked){
		unBlocked = false;
		if(!isup){
			gCounter++;
		};
		if(gCounter >= gSum+1){
			gCounter = 1;
		};
		if(!isup){
			sldr.setValue(gCounter);
		};
		new Effect.Move('scroll', {x: ((gCounter-1)*-880), y: 0, mode: 'absolute', duration: 0.7});
		unBlock.delay(0.8);
	};
}


