function OtSlideshow(options) {
	var self = this;
	
	this.container = (typeof(options['container']) != 'undefined' ? options['container'] : 'slider');
	this.delay = (typeof(options['delay']) != 'undefined' ? options['delay'] * 1000 : 3000);
	this.slideEffect = (typeof(options['effect'] != 'undefined') ? options['effect'] : 'cross');
	
	this.currentSlide = 0;
	this.maxSlideCount = 0;	
	
	$$('#' + this.container + ' .slide').each(function(slide) {
		self.maxSlideCount++;
	});
	
	this.timer = null;
	
	return this;
}

OtSlideshow.prototype.prev = function() {
	var pOld = $(this.container + '-slide-' + this.currentSlide);
	
	this.currentSlide--;
	if (this.currentSlide < 0) {
		this.currentSlide = this.maxSlideCount - 1;
	}
	var pNew = $(this.container + '-slide-' + this.currentSlide);
	
	if (!pOld || !pNew) {
		return;
	}	
	
	this.timerRefresh();
	this.changeSlide(pOld, pNew);
}

OtSlideshow.prototype.goTo = function(i) {
	var pOld = $(this.container + '-slide-' + this.currentSlide);
	var pNew = $(this.container + '-slide-' + i);

	if (!pOld || !pNew) {
		return;
	}
	
	this.currentSlide = i;
	
	this.timerRefresh();
	this.changeSlide(pOld, pNew);
}

OtSlideshow.prototype.next = function() {
	var pOld = $(this.container + '-slide-' + this.currentSlide);
	
	this.currentSlide++;
	if (this.currentSlide >= this.maxSlideCount) {
		this.currentSlide = 0;
	}
	var pNew = $(this.container + '-slide-' + this.currentSlide);
	
	if (!pOld || !pNew) {
		return;
	}	
	
	this.timerRefresh();
	this.changeSlide(pOld, pNew);
}

OtSlideshow.prototype.run = function() {
	var pOld = $(this.container + '-slide-' + this.currentSlide);
	
	this.currentSlide++;
	if (this.currentSlide >= this.maxSlideCount) {
		this.currentSlide = 0;
	}
	var pNew = $(this.container + '-slide-' + this.currentSlide);
	
	if (!pOld || !pNew) {
		return;
	}	
	
	this.changeSlide(pOld, pNew);
}

OtSlideshow.prototype.timerRefresh = function() {
	if (this.timer) {
		clearInterval(this.timer);
	}
	var self = this;
	this.timer = setInterval(function() { self.run(); }, this.delay);
}

OtSlideshow.prototype.start = function() {
	this.timerRefresh();
}

OtSlideshow.prototype.changeSlide = function(pOld, pNew) {
	var effect = this.slideEffect;
	
	if (effect == 'random') {
		var effectArray = ['cross', 'blinddown', 'blindup'];
		var random = Math.floor(Math.random()*effectArray.length);
		effect = effectArray[random];
	}
	
	switch (effect) {
		case 'blinddown':
			this.blindDown(pOld, pNew);
			break;
	
		case 'blindup':
			this.blindUp(pOld, pNew);
			break;
			
		case 'cross':
			this.crossFade(pOld, pNew);
			break;
			
		case 'none':
		default:
			this.noEffect(pOld, pNew);
			break;
	}
}

OtSlideshow.prototype.noEffect = function(pOld, pNew) {
	if (pOld){
		pOld.style.display='none';
	}
	if (pNew){
		pNew.style.display='block';	
	}
}

OtSlideshow.prototype.crossFade = function(pOld,pNew) {
	if (pNew){
		new Effect.Appear(pNew.id, {duration : 0.5});
	}
	if (pOld){
		new Effect.Fade(pOld.id, {duration : 0.5});
	}
}

OtSlideshow.prototype.blindDown = function(pOld,pNew) {
	if(pNew){
		pNew.style.zIndex='2';
	}
	if(pOld){
		pOld.style.zIndex='1';
	}
	if (pNew){
		new Effect.BlindDown(pNew.id, {duration : 0.5});
	}
	if (pOld){
		new Effect.Fade(pOld.id,{duration : 0.5});
	}
}

OtSlideshow.prototype.blindUp = function(pOld,pNew) {
	if(pNew){
		pNew.style.zIndex='1';
	}
	if(pOld){
		pOld.style.zIndex='2';
	}
	if (pNew){
		new Effect.Appear(pNew.id,{duration : 0.5});
	}
	if (pOld){
		new Effect.BlindUp(pOld.id, {duration : 0.5});
	}
}
