function slideshow(id){
	this.TIMER_INTERVAL = 5;
	this.SLIDE_TIME = 500;
	this.SLIDE_EFFECT = 'slide';
	
	this.id = 'div#' + id;
	this.timer = null;
	this.currentSlide = null;
	this.totalSlides = null;
	this.interval = null;
	
	try{
		this.totalSlides = $(this.id + ' div.slide').length;
		if (this.totalSlides == 0){
			throw 'noSlides';
		}
	}
	catch (e){
		if (e == 'noSlides'){
			alert('Please add a teaser');
			return false;
		}
	}
	
	this.showSlide(1);
	this.setUpSlideNavigation();
	this.startSlideshow();
	this.initPauseButton();
}

slideshow.prototype = {
	showSlide: function(slideNumber){
		if (this.currentSlide != null){
			$(this. id + ' div#slide' + this.currentSlide).hide(this.SLIDE_EFFECT, {direction: 'left'}, this.SLIDE_TIME);
			$(this. id + ' div#slide' + slideNumber).show(this.SLIDE_EFFECT, {direction: 'right'}, this.SLIDE_TIME);
		}
		else{
			$(this. id + ' div#slide' + slideNumber).show();
		}
		
		this.highlightNav(slideNumber);
		this.currentSlide = slideNumber;
	},
	
	setUpSlideNavigation: function(){
		var instance = this;
		$(this.id + ' div.navBar a').click(function(){
			instance.showSlide($(this).attr('rel'));
			instance.stopSlideshow();
			$(instance.id + ' div.pause a').html('Resume');
			$(instance.id + ' div.pause a').addClass('resumeButton');
		});
	},
	
	startSlideshow: function(){
		var instance = this;
		
		this.interval = setInterval(function(){
			var nextSlide = ((parseInt(instance.currentSlide) + 1) > instance.totalSlides) ? 1 : parseInt(instance.currentSlide) + 1;
			instance.showSlide(nextSlide);
		}, 
		instance.TIMER_INTERVAL * 1000);
	},
	
	stopSlideshow: function(){
		clearInterval(this.interval);
	},
	
	initPauseButton: function(){
		var instance = this;
		$(this.id + ' div.pause a').click(function(){
			if ($(this).html() == 'Pause'){
				instance.stopSlideshow();
				$(this).html('Resume');
				$(this).addClass('resumeButton');
			}
			else{
				instance.startSlideshow();
				$(this).html('Pause');
				$(this).removeClass('resumeButton');
			}
		});
	},
	
	highlightNav: function(slideNumber){
		$(this.id + ' div.navBar a').removeClass('on');
		$(this.id + ' div.navBar a[rel=' + slideNumber + ']').addClass('on');
	}
}