

var NewsShow = new Class({
								
        Implements: [Options, Events],
        options: {
                slides: [],
				newsLinks: [],
                startIndex: 0,
                wrap: true
                //onShow: $empty
        },
        initialize: function(options){
                this.setOptions(options)
                this.addSlides(this.options.slides);
				this.addLinks(this.options.newsLinks);
                if(this.slides.length) this.showSlide(this.options.startIndex);
        },
		
        slides: [],
		
		newsLinks: [],
		
        addSlides: function(slides){
			
                $$(slides).each(function(slide){		
                        this.slides.include($(slide));
                        //slide.addEvent('click', this.cycleForward.bind(this));
                }, this);
        },
		
		addLinks: function(newsLinks){
                $$(newsLinks).each(function(newsLink){		
                        this.newsLinks.include($(newsLink));
                        //newsLink.addEvent('click', this.cycleForward.bind(this));
                }, this);
				
				//trace('newsLinks: ' + newsLinks);
        },
		
        addSlide: function(slide){
                this.addSlides($splat($(slide)));
        },
		
		
        cycleForward: function(){
			//trace("cycle forward");
			//trace("this.now: "+ this.now);
                if($chk(this.now) && this.now < this.slides.length-1) this.showSlide(this.now+1);
                else if ((this.now) && this.options.wrap) this.showSlide(0);
                else if(!$defined(this.now)) this.showSlide(this.options.startIndex);
        },
		
        cycleBack: function(){
                if(this.now > 0) this.showSlide(this.now-1);
                else if(this.options.wrap) this.showSlide(this.slides.length-1);
        },
		
		
        showSlide: function(iToShow){
			
				
			
				//trace("showSlide: "+ iToShow);
				
				if (this.fading) return;
				
                var now = this.now;
				//trace("showSlide this.now: "+ now);
				
                var currentSlide = this.slides[now];
				//trace("currentSlide this.slides[now]: " + now);
				
				var currentNewsLink = this.newsLinks[now];
				
				var NewsLinkToShow = this.newsLinks[iToShow]; 
				
                var slideToShow = this.slides[iToShow];
				//trace("slide iToShow: "+ iToShow);
				
				var fadeInFx = new Fx.Tween(slideToShow, 'opacity', {duration:1000, onComplete:function(){
						this.fading = false;
						//trace("fadeInFx onComplete");
						
						this.fireEvent('onShow', [slideToShow, iToShow], 8000);
						//this.cycleForward();
						
																										
				}.bind(this)});
				
				var fadeOutFx = new Fx.Tween(currentSlide, 'opacity', {duration:1000, onComplete:function(){
                        currentSlide.setStyle('display', 'none');
						//trace("fadeOutFx onComplete");
						
						//fadeIn(slideToShow);
																										
				}.bind(this)});
				
                var fadeIn = function (slideToFade){
						//trace("fadeIn");
                        this.fading = true;
                        slideToFade.setStyles({
                                display:'block',
                                visibility: 'visible',
                                opacity: 0,
								position:'absolute',
								top:'30px'
								
                        });
				
				
				
				NewsLinkToShow.tween('background-color', '#3c6217');
				
				fadeInFx.start(0, 1);
				
				
				
                }.bind(this);
				
				
                if(slideToShow) {
					
                        if($chk(now) && now != iToShow){
                                this.fading = true;
								fadeOutFx.start(1, 0);
								currentNewsLink.tween('background-color', '#84bb3c');
      
                        } else {
							this.now = iToShow;
							//trace("this.now: " + iToShow);
							//fadeIn(slideToShow);
							
						}
						fadeIn(slideToShow);
						this.now = iToShow;
						
                }
				
				
				
				
		
        }
						
});
