
	var fadeClass= new Class({
		initialize: function(){
			this.leftButton=$('fade_move_left');
			this.rightButton=$('fade_move_right');

			this.elements=[];
			this.position=0;
		},

		run: function(e){
			this.leftButton.addEvent('click',this.leftButtonListener.bind(this))
			this.rightButton.addEvent('click',this.rightButtonListener.bind(this))

			$$('.fade_element_box').each(function(e){
				this.elements.push(new elementClass(e,this.elements.length,this));
			}.bind(this));
			
			if (this.elements.length) this.elements[0].select();
		},
		buttonListener: function(opt){
			opt.event.stop();
		},
		leftButtonListener: function(e){
			if(this.position>0) {
				this.elements[this.position-1].selectFade();
			}
			this.buttonListener({
				button:'previous',
				event:e
			});
		},
		rightButtonListener: function(e){
			if(this.position<this.elements.length-1) {
				this.elements[this.position+1].selectFade();
			}
			this.buttonListener({
				button:'next',
				event:e
			});
		}
	});

	var elementClass= new Class({
		initialize: function(element,position,fadeObj){
			this.element=element;
			this.id=element.getAttribute('rel');
			this.position=position,
			this.fadeObj=fadeObj;
			
			this.fadeTween=new Fx.Tween(this.element,{
				'property':'opacity',
				'duration':1000
			});
		},
		select: function(){
			this.fadeObj.elements.each(function(e){
				e.fadeTween.cancel();
				e.element.setStyles({opacity:'0',display:'none'});
			}.bind(this));
			this.fadeObj.elements[this.fadeObj['position']].element.setStyles({opacity:'0',display:'none'});
			this.element.setStyles({opacity:'1',display:'block'});
			this.fadeObj.position=this.position;
		},
		selectFade: function(){
			this.fadeTween.addEvent('complete',function(){
				this.fadeTween.removeEvents('complete');
				this.fadeObj['elements'][this.fadeObj['position']].element.setStyles({opacity:'0',display:'none'});
				this.element.setStyles({opacity:'1',display:'block'});
				this.fadeObj.position=this.position;
			}.bind(this));
			
			this.fadeObj['elements'][this.fadeObj['position']].fadeTween.start(1,0);
			this.element.setStyles({opacity:'0',display:'block'})
			this.fadeTween.start(0,1);
		}
	});

