var amerScroller = new Class({
    Implements: Options,
    options: {
		duration: 1000,
		delay: 7000,
		fxtype: 'fade',
		transition: Fx.Transitions.Linear
	},
    zInterval:null, 
    pause:false, 
    csIndex:0, 
    nsIndex:0,
    fadeInterval:0, 
    backCourse:false, 
    totSlides:0,
    slides:[],
    display:'',
    top:0,
    btm:0,
    rit:0,
    lft:0,
	initialize: function(wrapper,slideSelectors,slideamount,direction,options) {
        this.setOptions(options);
        this.wrapper = $(wrapper);
        switch(direction){
        	case 'up'   : this.top=slideamount; break;
        	case 'down' : this.btm=slideamount; break;
        	case 'right': this.rit=slideamount; break;
        	case 'left' : this.lft=slideamount; break;
        }
        if(direction=='up' || direction=='down'){
        	this.display='block';
        }else{
        	this.display='inline-block';
        }
        if(this.wrapper){
        	this.slides = this.wrapper.getChildren(slideSelectors)
	        this.totSlides=this.slides.length;
	        if(this.totSlides>1){
	        	var fxtype=this.options.fxtype;
				this.slides.each(function(el,i){			
		        	if(fxtype=='slide'){
		        		el.setStyles({position:'relative','margin':0});
		        	}
		        	if(fxtype=='scroll'){
		        		el.setStyles({position:'relative',display:'none','margin':this.top+''+this.rit+''+this.btm+''+this.lft});
		        	}
		        	if(fxtype=='fade'){
		        		el.fade('hide');
		        		el.setStyles({position:'absolute',display:'block'});
		        	}        	
				});
				if(fxtype=='slide'){
					this.slides[0].setStyles({display:this.display,'margin':0});
		    	}
		    	if(fxtype=='scroll'){
					this.slides[0].setStyles({display:'block','margin':0});
		    	}
				if(fxtype=='fade'){
		    		this.slides[0].fade('show');
		    	}     
				
		        this.csIndex = 0;
		        this.iniCross();
	        }
        }
	},
    iniCross:function(prev_next){
    	this.nsIndex = this.csIndex +1;
    	if(this.nsIndex>=this.totSlides) this.nsIndex=0
    	if(!this.pause){
    		clearTimeout(this.zInterval);
    		this.zInterval = this.so_xfade.delay(this.options.delay,this);
    	}
    	if(prev_next=='Next'){		
    		this.so_xfade();
    	}
    	else if(prev_next=='Previous'){																			
    		this.nsIndex = this.csIndex -1;
    		if(this.nsIndex<0) this.nsIndex=this.totSlides-1;
    		this.backCourse = true;
    		this.so_xfade();
    	}
    },    
    so_xfade:function() {
	    this.slides[this.nsIndex].set('tween', {duration: this.options.duration});
    	this.slides[this.csIndex].set('tween', {duration: this.options.duration});
    	if(this.options.fxtype=='fade'){
			this.slides[this.nsIndex].tween('opacity',1);
	    	this.slides[this.csIndex].tween('opacity',0);
	    	this.csIndex=this.nsIndex;
    		this.iniCross();
    	}
		if(this.options.fxtype=='scroll'){
            this.slides[this.csIndex].setStyle('background-position','100% -30');
            this.slides[this.csIndex].fade('out');
    		this.slides[this.nsIndex].fade('show');
	    	this.vScroll.delay(this.options.duration,this);
    	}
		if(this.options.fxtype=='slide'){
            this.slides[this.nsIndex].setStyles({'display':this.display,'margin':0,'background-position':'100% 0px'});
    		this.slides[this.csIndex].set('morph', {duration: this.options.duration,'transition':this.options.transition});
    		this.slides[this.csIndex].morph({'margin-top':this.top,'margin-bottom':this.btm,'margin-right':this.rit,'margin-left':this.lft});
	    	this.vSlide.delay(this.options.duration+200,this);
    	}
    	
    },
    vSlide:function(){
    	this.slides[this.csIndex].setStyles({'display':this.display,'margin':0,'background-position':'100% 0px'});
    	this.slides[this.csIndex].inject(this.wrapper,'bottom');
    	this.slides[this.csIndex].setStyle('display','none');
   	this.csIndex=this.nsIndex;
    	this.iniCross();
    },
    vScroll:function(){
    	this.slides[this.nsIndex].setStyles({'display':'block','margin':this.top+''+this.rit+''+this.btm+''+this.lft,'background-position':'100% 0px'});
    	this.slides[this.nsIndex].set('morph', {duration: this.options.duration,'transition':this.options.transition});
    	this.slides[this.csIndex].setStyle('display','none');
   		this.slides[this.nsIndex].morph({'margin-top':this.top,'margin-bottom':this.btm,'margin-right':this.rit,'margin-left':this.lft});
   		this.csIndex=this.nsIndex;
    	this.iniCross();
    },
    Start:function(){	
    	this.pause = false;	
    	this.iniCross('');
    },
    Stop:function(){	
    	clearTimeout(this.zInterval);
    	this.pause = true;
    	this.iniCross('');
    }
});
