// JavaScript Document
(function($){
	$.fn.RunPages = function(options){
		
		options =  $.extend(
		{ 
			direction:'left',
			x:15 ,
			time:5,
			timer:false, 
			width:100 
		},options);
		
		$('table:first',this).css("table-layout","fixed");
		 var target = this;
		 
		var innerWidth = target.children(0).width();
		 
		stopInt();
		var sLeft = target.scrollLeft(); 
			if(options.direction == "left"){
			
		    var w = Math.max(sLeft - options.width , 0 );
	        options.timer = setInterval( run2left  ,options.time);
		}else{
		   var w= Math.min( sLeft + options.width  ,innerWidth); 
		    
		   options.timer = setInterval( run2right  ,options.time);
		}
		
		
		function stopInt(){
		  if(options.timer != false){
		     clearInterval(options.timer);
			 
		  }
		  options.timer = false;
		}
		
		function run2left(){
		    
			var sLeft = target.scrollLeft();
			if(sLeft <= w ){
			   stopInt();
			}else{
			   target.scrollLeft(sLeft-options.x);
			}
		}
		
		function run2right(){
		   
		   
		   var sLeft = target.scrollLeft();
		   
		   if( sLeft >= w || sLeft + options.width >= innerWidth){
		     stopInt();
		   }else{
		     target.scrollLeft(sLeft+options.x);
		   }
		}
		
	
		
		
	}
})(jQuery)
