var moonscroller = new Class({

		initialize: function(pid, mid, options)
		{
			this.setOptions({
				autoDelay: 3000,
				fxDuration: 900
			}, options);
			this.player_timer = 0;
			this.cur_link = '';
			this.linkData = [];
			this.sh = $(pid);
			this.smh = $$( '#' + mid + ' a');
			this.srcdata = '';

			if(this.sh && this.smh)
			{
				this.slide = new Fx.Scroll(this.sh, {
						wait: true,
						duration: this.options.fxDuration,
						offset: {'x': 0, 'y': 0},
						transition: Fx.Transitions.Quad.easeInOut
					});

				for (i = 0; i < this.smh.length; i++) 
				{			
					var mrt = {
						link: this.smh[i],
						obj: this
					};
					mrt.link.addEvent('click', function(e)
					{ 
						
						if (!mrt.link.hasClass('nolinkstop')) 
						{
							new Event(e).stop();
							var newElement = $(this.link.get('rel'));
							if(newElement){
								this.obj.slide.toElement(newElement);							
							}
						}

					}.bind(mrt)); 
				}
				
				this.smh.addEvents({				
					'mouseenter': function(){
						if (this.player_timer != 0) 
							this.timer('stop');
					}.bind(this),
					
					'mouseleave': function(){
					if(this.player_timer==0)this.timer('start');
					}.bind(this)
				});
				
				this.timer('prepare');
				this.timer('start');
			}
		},
				
	    timer: function(mode)
		{
			if(mode=='prepare')
			{
				this.timerf = function()
				{
					var jumpToIndex = $random(0, this.smh.length - 1);
					var newElement = $(this.smh[jumpToIndex].get('rel'));
					if(newElement){			
						this.slide.toElement(newElement);	
					}
				};
			}
 			else if(mode=='start')
			{
				this.player_timer = this.timerf.periodical(this.options.autoDelay, this);
			}
			else if(mode=='stop')
			{
				 $clear(this.player_timer);
				 this.player_timer = 0;			
			}
		}
})
 moonscroller.implement(new Options,new Events);
