// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
SlideShow = {
	fadeTime: 3,
	duration: 5,
	start: function(duration) {
		if(!duration) duration = this.duration;
		if(!this.number) this.number = 1;
		this.ta = window.setInterval(SlideShow.next, duration*1000);
		return this;
	},
	stop: function() {
		window.clearInterval(this.ta);
		return this;
	},
	next: function() {
		if(!SlideShow.number) {
			SlideShow.stop();
			return SlideShow;
		}

		return SlideShow.show(SlideShow.number + 1);
	},
	click: function(nr) {
		this.stop();
		if(!this.number) this.number = 1;
		var showEl = this.get(nr).show();
		Element.addClassName(showEl.id+"_link","slideActive");

		var hideEl = this.get(this.number).hide();
		Element.removeClassName(hideEl.id+"_link","slideActive");

		try {$('tabBox_'+nr).show();} catch(e) {};
		try {$('tabBox_'+this.number).hide();} catch(e) {};
		this.number = nr;
		return this;
	},
	show: function(nr) {
		var showEl = this.get(nr);
		var hideEl = this.get(this.number);
		var effects = [new Effect.Appear(showEl,{sync: true})];
		if(this.number) {
			effects.push(new Effect.Fade(hideEl,{sync: true}));
		}
		new Effect.Parallel(effects,{
				duration: this.fadeTime
		});
		Element.addClassName(showEl.id+"_link","slideActive");
		Element.removeClassName(hideEl.id+"_link","slideActive");
		this.number = parseInt(showEl.id.replace(/\D*/,""));
		return this;
	},
	get: function(nr) {
		var slide = $("Slide"+nr);
		if(!slide) slide = $("Slide1");
		return slide;
	}
}

