homeslideshow = Class.create();
homeslideshow.prototype = {
	initialize: function(){
		this.interval = 8000;
		this.container = $("homeslides");
		this.slides  = $A(this.container.getElementsByTagName("span"));
		this.number_of_slides = this.slides.length;
		if (this.number_of_slides == 0) return false;
		this.current_slide = 0;
		this.previous_slide = null;
		this.hideNews();
		this.showNews();
		this.timer = setInterval(this.showNews.bind(this), this.interval);
  	},
	showNews: function(){
		this.appearNews();
		setTimeout(this.fadeNews.bind(this), this.interval-1500);
		if (this.current_slide < this.number_of_slides-1){
			this.previous_slide = this.current_slide;
			this.current_slide = this.current_slide + 1;
		} else {
			this.current_slide = 0;
			this.previous_slide = this.number_of_slides - 1;
		}
	},
	appearNews: function(){
		Effect.Appear(this.slides[this.current_slide],{ duration: 1.0 , from: 0.0, to: 1.0});
	},
	fadeNews: function(){
		Effect.Fade(this.slides[this.previous_slide],{ duration: 1.0, from:1.0, to:0.0 });
	},
	hideNews: function(){
		Element.setStyle($("homeslides"), {display: "block"});
		this.slides.each(function(slide){
			Element.hide(slide);
		});
	}
}
Event.observe(window, "load", function(){new homeslideshow()}, false);

