var infoFader2 = new Class({
	initialize: function(options){
		this.options= $extend(
			{
				fxduration:	400,	// number of milliseconds for transition
				slideduration:	12000,	// number of milliseconds to show a slide
				startSlide:	1,	// number of the infopage to start with, "random" for a random one
				startNow:	'load',	// 0/false = start paused, 1/true = start started, load = show first slide asap then start show after page has finished loading
				setHeight: 	0,	// 0/false = no, 1/true = set the height of top div to height of tallest subDiv
				topDiv:		"infoFader",			// id of div containing all of the info pages
				subDiv:		"info"					// class of div for the info pages
			}, options || {}
		);
		
		this.periodical = "";
		this.started = 0;
		this.h = 0;
		
		this.topDiv = $(this.options.topDiv);
		this.topDiv.set('morph',{duration: this.options.fxduration, transition: Fx.Transitions.Circ.easeOut, link: "chain"});
		this.subDivs = this.topDiv.getElements('div.'+this.options.subDiv);
		this.subDivs.setStyles({display:'block',opacity:0});
		
		x=this.options.startSlide.toInt();
		if(this.options.startSlide=="random"){
			this.current = Math.floor(Math.random()*this.subDivs.length);
		}else if((x)&&(x<=(this.subDivs.length))){
			this.current = this.options.startSlide-1;
		}else{
			this.current = 0;
		}
	
		this.subDivs.each(function(sd,i){
			sd.set('morph',{duration: ""+this.options.fxduration+"", transition: Fx.Transitions.Sine.easeOut, link: "chain"});
			sdh = sd.getSize().y;
			if(sdh > this.h ) this.h = sdh;
		},this);
		
		this.topDiv.size = this.topDiv.getSize();
		
		this.clickButton(this.current);
		
		this.startOnLoad();
	},
	
	
	start: function(){
		this.next();
		this.periodical = this.next.periodical(this.options.slideduration,this);
		this.started = 1;
	},
	
	startOnLoad: function(){
		window.addEvent('load', function(){
			if(this.options.setHeight){
				this.topDiv.size.h=this.h;
				this.topDiv.morph({height:this.h});
				//this.topDiv.setStyle('height',this.h);
			}
			if(this.options.startNow=="load" && this.started==0) this.start();
		}.bind(this));
		if(Browser.Engine.trident && this.started==0) window.fireEvent('load');
	},
	
	stop: function(){
		$clear(this.periodical);
		this.started = 0;
	},
	
	next: function(){
		this.clearButton();
		this.current++;
		if(this.current>=this.subDivs.length) this.current=0;
		this.setButton();
	},
	
	clearButton: function(){
		this.subDivs[this.current].morph({opacity:0,zIndex:1});
	},
	
	setButton: function(){
		this.subDivs[this.current].morph({opacity:1,zIndex:100});
	},
	
	clickButton: function(i){
		this.stop();
		this.clearButton();
		this.current=i;
		this.setButton();
	}
	
});

