/*FULLY working with all features with out any jerk effect using cancel() */
window.addEvent('domready', function(){

	// time to read a li block
	timetoread = 2500;
	scrollDurt_click = 2000;
	scrollDurt_mleave = 1000;

	timeline_li_obj   = $('timeline_ul').getElements("li");
	timeline_li_count = timeline_li_obj.length;
	timeline_block_count = (Math.ceil(timeline_li_count/4)) ; // it holds value 4 if it got less than 16 li s val 5 for 18 li s
	timeline_contentWidth = 138*timeline_li_count;
	$('timeline_content').style.width = timeline_contentWidth+'px';
	
	stopAt 		= (timeline_li_count-4)*138;
	scrollDurt 	= timeline_li_count * timetoread;
	
			var scroll = new Fx.Scroll('timeline_frame', {
			wait: false,
			duration: scrollDurt
			});
			


	var startOnload = function() {
		$('timeline_frame').scrollTo(0,0);
		scroll.start(stopAt,0);
	}
	theOnload = startOnload();
	thePeriodic = startOnload.periodical(scrollDurt, this); 	

	$('timeline_1982').setStyle('cursor','pointer');
	$('timeline_1982').addEvents({
		'mouseenter':function() {
			scroll.cancel();
			$clear(theOnload);
			$clear(thePeriodic);
			
			var framexy = $('timeline_frame').getScroll();
			framex = framexy.x;
			
			on_li = Math.ceil(framex/138);
			scrollDurt_curr = on_li*timetoread;			
			scroll = new Fx.Scroll('timeline_frame', {
						wait:false,
						duration:scrollDurt_curr
			});
			
			scroll.start(0,0);
			
		}, 'mouseleave':function() {
			
			scroll.cancel();
			
			var framexy = $('timeline_frame').getScroll();
			framex = framexy.x;
			
			on_li = Math.floor(framex/138);
			
			scroll = new Fx.Scroll('timeline_frame', {
							wait:false,
							duration:scrollDurt_mleave
			});
			
			scroll.start((on_li*138),0);
		}, 'click':function() {
			
			scroll.cancel();

			scrollDurt_curr = 2000;
			scroll = new Fx.Scroll('timeline_frame',{
							wait:false,
							duration:scrollDurt_click
			});
			
			var framexy = $('timeline_frame').getScroll();
			framex = framexy.x;
			framey = framexy.y;
			
			if(timeline_li_count > 4) {
				for(i=((Math.ceil(timeline_li_count/4))-1); i > 0; i-- ) {
				  if( framex > ((552*(i-1))+1) && framex < ((552*i)+1) ) {
				  	advstop = (552*(i-1));
				  } // if limit
				} // for
			 } // if li count need to be more than 4
		 	scroll.start(advstop,framey);			
		}
								 
	}); // 1982
	
	$('timeline_2008').setStyle('cursor','pointer');
	$('timeline_2008').addEvents({
		'mouseenter':function() {

			scroll.cancel();
			$clear(theOnload);
			$clear(thePeriodic);
			
			var framexy = $('timeline_frame').getScroll();
			framex = framexy.x;
			
			on_li = Math.floor(framex/138);
			scrollDurt_curr = (timeline_li_count - on_li)*timetoread;			
			scroll = new Fx.Scroll('timeline_frame', {
						wait:false,
						duration:scrollDurt_curr
			});
			
			scroll.start(stopAt,0);
			
		}, 'mouseleave':function() {
			
			scroll.cancel();
			
			var framexy = $('timeline_frame').getScroll();
			framex = framexy.x;
			
			on_li = Math.ceil(framex/138);
			
			scroll = new Fx.Scroll('timeline_frame', {
							wait:false,
							duration:scrollDurt_mleave
			});
			
			scroll.start((on_li*138),0);
			
		}, 'click':function() {
			
			scroll.cancel();
			
			var framexy = $('timeline_frame').getScroll();
			framex = framexy.x;
			framey = framexy.y;			
			
			
			scroll = new Fx.Scroll('timeline_frame',{
							wait:false,
							duration:scrollDurt_click
			});
			
			if(timeline_li_count > 4) {
				for(i=0; i < ((Math.ceil(timeline_li_count/4))); i++ ) {
					if(framex > ((552*i)-1) && framex < ((552*(i+1))-1) ) {
						advstop = (552*(i+1));
					} // limit
				} // for
			} // li_count 4	
			
     	scroll.start(advstop,framey);

		}
								 
	}); // 2008
	
	
	

}); // DOM