var Sliders = new Class({
    Implements: [Events, Options],
    options:{
        button:'.toggle',
        slideClass:'.slider',
        autoHide:'',
        openFirst:'',
        showImage:'',
        hideImage:'',
        showText:'',
        hideText:'',
        imageClass:'',
        textClass:''
    },
    initialize:function(options){
        this.setOptions(options);
       
        this.sliders = $$(this.options.slideClass).map(function(e){
           
           //if(Browser.Engine.gecko){
				//need to use FF hack so the slide doesn't flicker because it wraps around scrolling divs
				//return new Fx.Slide(e,{overflow:'auto'});
			//}else{
				//don't hack for others as causes scroll bars to appear during slide in IE
				
				return new Fx.Slide(e);
			//};			
        });
        
        $$(this.options.button).each(function(toggler,index){
			toggler.addEvent('click',function(){
				this.sliders[index].toggle();		
				//change show/hide image
				if(this.options.imageClass != ''){
					if($$(this.options.imageClass)[index]){
						var indicatorImage = $$(this.options.imageClass)[index];
						if(indicatorImage.get('src').indexOf(this.options.showImage) > -1){
							indicatorImage.set('src',this.options.hideImage);						
						}else if(indicatorImage.get('src').indexOf(this.options.hideImage) > -1){
							indicatorImage.set('src',this.options.showImage);
						}
					}
				}
				//change show/hide text
				if(this.options.textClass != ''){					
					if($$(this.options.textClass)[index]){
						var showHideText = $$(this.options.textClass)[index];
						if(showHideText.get('text').indexOf(this.options.showText) > -1){
							showHideText.set('text',this.options.hideText);						
						}else if(showHideText.get('text').indexOf(this.options.hideText) > -1){
							showHideText.set('text',this.options.showText);
						}
					}
				}
			}.bind(this));			
        },this);
        
        if(this.options.autoHide){					
			$$(this.options.button).each(function(e,index){
				if(!this.options.openFirst){
					e.fireEvent('click');
				} else if(this.options.openFirst && index != 0){
					e.fireEvent('click');
				}
			},this);
		};
		
		if(this.options.showFirst && !this.options.autoHide){$$(this.options.button)[0].fireEvent('click');}
        
    }
});
