Timeline = new Class({
	Implements: [Events, Options, Chain],
	options: {
		leftBttClass:'.scrollBttL',
		rightBttClass:'.scrollBttR',
		bttOffOpacity:0.3,
		jumpWidth:115,
		scrollerTop:380,
		scrollVisibleCount:6,
		windowManager:null
	},
	initialize: function(el,options){
		this.setOptions(options);
		this.el = $(el);
		
		this.el.getElement(this.options.leftBttClass).addEvent('click',this.move.bindWithEvent(this,-1));
		this.el.getElement(this.options.rightBttClass).addEvent('click',this.move.bindWithEvent(this,1));
		
		this.oScroll = new Fx.Scroll(this.el.getElement('.timelinewrap'),{transition: Fx.Transitions.Sine.easeInOut,duration:500});
		
		this.windows = new Array();
		this.currOpen = null;
		this.currScrollPos = null;
		
		this.elScroll = this.el.getElement('.scroller');
		this.startPos = this.elScroll.getPosition();
		
		this.el.setStyle('height',this.el.getSize().y);
		
		this.el.getElements('.tlObj').each(function(oE,i){
			this.windows[i] = $('timelineDet'+oE.get('rel'));
			oE.addEvent('click', (function(e){
				new Event(e).stop();
				jQuery('.timeline_display').html(jQuery('#timelineDet' + oE.get('rel')).html());
				this.currOpen = i;
			}).bind(this));
		},this);
		
		this.renderArrows();
	},
	move: function(evnt,dir){
		if( this.oScroll.timer == null && (this.windows.length > this.currScrollPos + dir + this.options.scrollVisibleCount-1 ) && (this.currScrollPos + dir >= 0) ){
			this.currScrollPos += dir;
			var oCoor = this.el.getElement('.timelinewrap').getScroll();
			this.oScroll.start(oCoor.x + (this.options.jumpWidth * dir),0);
			this.renderArrows();
		}
		
	},
	renderArrows: function(){
		if(this.currScrollPos <= 0){
			this.el.getElement(this.options.leftBttClass).setStyle('opacity',this.options.bttOffOpacity);
			this.el.getElement(this.options.rightBttClass).setStyle('opacity',1);
		}else if(this.currScrollPos + this.options.scrollVisibleCount >= this.windows.length){
			this.el.getElement(this.options.leftBttClass).setStyle('opacity',1);
			this.el.getElement(this.options.rightBttClass).setStyle('opacity',this.options.bttOffOpacity);
		}else{
			this.el.getElement(this.options.leftBttClass).setStyle('opacity',1);
			this.el.getElement(this.options.rightBttClass).setStyle('opacity',1);
		}
	}
});
