 var RSlider = new Class({
 	options: {
		prop: 'top',
		duration: 1000,
		mode: 'y',
		init: 0,
		inside: false
	},
	initialize: function(el, options){
		this.options = options;
		this.finestra = el;
		this.scroller = this.finestra.getFirst();
		this.indicator = options.init;		
		if(this.options.mode=='x'){
			this.step = this.finestra.getSize().size.x;
			this.checkScroller = this.scroller.getSize().size.x;
		}else{
			this.step = this.finestra.getSize().size.y;
			this.checkScroller = this.scroller.getSize().size.y;
		}
		if(this.options.inside){
			this.button1 = new Element('div', {'class': 'button1'}).injectInside(this.finestra);
			this.button2 = new Element('div', {'class': 'button2'}).injectInside(this.finestra);
		}else{
			this.button1 = new Element('div', {'class': 'button1'}).injectBefore(this.finestra);
			this.button2 = new Element('div', {'class': 'button2'}).injectAfter(this.finestra);	
		}
		
		//this.step = 113;
		
		//alert(el.id+this.step);
		//alert(this.scroller.getStyle("width"));
		this.button1.setOpacity(1);
		this.button2.setOpacity(1);
		this.button1.onclick = this.move1.bind(this, [el]);
		this.button2.onclick = this.move2.bind(this, [el]);			
		//this.varChange = new Fx.Style(this.scroller, options.prop, {duration: options.duration, transition: Fx.Transitions.Back.easeInOut});		
		this.varChange = new Fx.Style(this.scroller, options.prop, {duration: options.duration, transition: Fx.Transitions.Quint.easeInOut});
		this.scroller.setStyle(options.prop, options.init);
		this.enable();
		//alert("ok");		
	},
	
	move1: function(el){
		if(!this.button1.hasClass('inactive')){
			if(this.indicator + this.step>0){
				this.varChange.start(0);
				this.indicator = 0;				
			}else{
				this.varChange.start(this.indicator, this.indicator + this.step);
				this.indicator = this.indicator + this.step;
			}			
			this.enable();
		}
	},
	
	move2: function(el){
		if(!this.button2.hasClass('inactive')){
			//alert(this.indicator + " & " + this.step + " & "+this.checkScroller);
			if(this.checkScroller - this.step < this.step ){
				this.varChange.start(this.indicator, this.step - this.checkScroller);
				this.indicator = this.step - this.checkScroller;
			}else{			
				this.varChange.start(this.indicator, this.indicator - this.step);
				this.indicator = this.indicator - this.step;
			}
			this.enable(); 
		}
	},
	
	enable:function(){
		//alert(this.finestra.getPosition().x + " x " + this.finestra.getPosition().y)
		//alert(this.step +" vs "+ this.checkScroller+ " vs "+ -(this.indicator - this.step));
		//alert("ind="+this.indicator);
		if(this.checkScroller <= -(this.indicator - this.step)){
			//alert("y");
			this.button2.addClass("inactive");
		}else{
			//alert("n:" + this.checkScroller + " x "+ (-(this.indicator - this.step)));
			this.button2.removeClass("inactive");
		}
		if(this.indicator == 0)
			this.button1.addClass("inactive");
		else
			this.button1.removeClass("inactive");
	}
});

RSlider.implement(new Events, new Options);

window.addEvent('load',function(){
	$$('.finestra').each(function(el){
		new RSlider(el,{'prop': 'left', 'duration': 1000, 'mode': 'x', init: 0});
	});
	viewThisGallery(-1);
	$$('.container').each(function(el){
		el.setStyle("visibility","visible");
	});	
});

//window.addEvent('load',function(){});

function viewThisGallery(idgallery){
	$$('.container').each(function(el){
		el.setStyle("display","none");
	});
	if(idgallery!=-1){
		if($("cont"+(idgallery))){
			$("links").setStyle("display","none");
			$("cont"+(idgallery)).setStyle("display","block");
		}
	}
}
