var SlideShow = new Class({	
	initialize:function(container,slides,nav,interval){

		this.container = $(container);
		this.container.set('tween', {duration: 'short'});
		
		this.slides = $$(slides);
		this.nav = $$(nav);

		this.interval = interval;
		this.currentIndex = 0;
		this.addEvents();

		// For a fade effect
		this.slides.set('opacity',0);
		
		// for a vertical slide effect
		//this.slides.setStyle('margin-top','440px');
		
		this.show(this.currentIndex);
		this.play();
	},	
	addEvents:function(){
		this.container.addEvent('mouseenter', function() {
			this.pause();
		}.bind(this));
		
		this.container.addEvent('mouseleave', function() {
			this.play();
		}.bind(this));	
		var ss = this;
		this.nav.each(function(el,index){
			/*
			el.addEvent('click',function(e){
				e.stop();
				ss.pause();
				ss.show(index);
			});
			*/
			el.addEvent('mouseenter',function(e){
				ss.pause();
				ss.show(index);
			});
			
			el.addEvent('mouseleave',function(e){
				ss.play();
			});
			
		}.bind(this));
	},	
	pause:function(){
		this.isPlaying = false;
		//this.playButton.set('class','play');
		$clear(this.timer);
	},
	play:function(){
		this.isPlaying = true;
		//this.playButton.set('class','pause');
		this.timer = this.showNext.periodical(this.interval, this);
	},
	toggle:function(){
		if(this.isPlaying){
			this.pause();
		}
		else{
			this.play();
		}
	},
	show:function(index){
		this.nav[this.currentIndex].removeClass('active');
		this.slides[this.currentIndex].fade('out');
		//this.slides[this.currentIndex].tween('margin-top','440px');
	
		this.currentIndex = index;
		this.nav[this.currentIndex].addClass('active');
		this.slides[this.currentIndex].fade('in');
		//this.slides[this.currentIndex].tween('margin-top','0px');
		
	},	
	showNext:function(){
		if(this.currentIndex < this.slides.length-1 )
		{
			this.show(this.currentIndex+1);
		}
		else
		{
			this.show(0);
		}
	}
});
var TabViewer = new Class({	
	initialize:function(container,slides,nav){

		this.container = $(container);
		this.slides = $$(slides);
		this.nav = $$(nav);

		this.currentIndex = 0;
		this.addEvents();

		// For a fade effect
		this.slides.set('opacity',0);
		
		// for a vertical slide effect
		//this.slides.setStyle('margin-top','440px');
		
		this.show(this.currentIndex);

	},	
	addEvents:function(){

		var ss = this;
		this.nav.each(function(el,index){
			el.addEvent('click',function(e){
				e.stop();
				ss.show(index);
			});
			
		}.bind(this));
	},	

	show:function(index){
		this.nav[this.currentIndex].removeClass('active');
		this.slides[this.currentIndex].fade('out');
		if(this.slides[this.currentIndex].get('class') == 'video')
		{
			$('flashmovie').StopPlay();
		}
		this.currentIndex = index;
		if(this.slides[this.currentIndex].get('class') == 'video')
		{
			$('flashmovie').Play();
		}
		this.nav[this.currentIndex].addClass('active');
		this.slides[this.currentIndex].fade('in');
		
	}

});