var micSubpageScroll = new Class({

    options: {
		container: null,
		speed: 500,
		autoRotator:false,
		timedSwitch:5000
		
	},
	
	initialize: function(options) {
	
		
	
		this.setOptions(options);
		this.container = $(options['container']);
		this.speed = options['speed'];
		this.autoRotator = options['autoRotator'];
		this.slides =$$("#"+options['container']+ ' .bannerSubpage');
		
		this.timerTime =options['timedSwitch'];
		
		if (this.autoRotator) {
			this.delayTimer = this.timedSwitch.periodical(this.timerTime,this);
		}
		
		
		var randomSlide=Math.floor(Math.random()*this.slides.length);
				
		
		this.curSlide = randomSlide ;			
		this.slides[randomSlide].setStyle('visibility','visible');
		
	
	
		
				
	},
	
			
	
	showSlide: function(e,slideToGo) {
					
						
						
						
						
						var goSlideN = new Fx.Tween (this.slides[slideToGo], {transition:Fx.Transitions.linear, duration:800, wait:true});
						var goSlideO = new Fx.Tween (this.slides[this.curSlide], {transition:Fx.Transitions.linear, duration:500, wait:true});
						
						
						goSlideN.start('opacity',0,1);
						goSlideO.start('opacity',1,0);
						this.curSlide = slideToGo;
						
						if (this.autoRotator) {
							this.delayTimer = $clear(this.delayTimer);
							this.delayTimer = this.timedSwitch.periodical(this.timerTime,this);
						}
					
				
				
	},
	
	
	timedSwitch: function() {
				
				var randomSlide=Math.floor(Math.random()*this.slides.length);
				
				if (this.curSlide == randomSlide) {
							if (this.currentSlide == this.slides.length - 1) {
							randomSlide=0;
							}
							else {
							randomSlide = randomSlide+1;
							}
						}
				
				this.showSlide(this,randomSlide);
				
	}


	
	
	
			
				
});

micSubpageScroll.implement(new Options, new Events);


