
function SlideShow(id, width, height, type, delay, transdelay) {
	this.box = document.getElementById(id);
	this.index = 0;
	this.width = width;
	this.height = height;
	this.type = type;
	this.delay = delay;
	this.transdelay = transdelay;
	this.transinterval = 20;
	if(this.box) addEvent(window, 'load', this.startAnim.bind(this));
}

SlideShow.prototype.startAnim = function() {
	this.index = 0;
	this.images = this.box.getElementsByTagName('img');
	setTimeout(this.startTransition.bind(this), this.delay);
}

SlideShow.prototype.startTransition = function() {
	this.step = 0;
	this.starttime = new Date().getTime();
	this.next = (this.index + 1) % this.images.length;
	this.images[this.next].style.visibility = 'visible';
	this.setTransition(this.images[this.next], this.step);
	this.timer = setInterval(this.transition.bind(this), this.transinterval);
}

SlideShow.prototype.transition = function() {
	var delta = new Date().getTime() - this.starttime;
	this.step = delta / this.transdelay;
	if(this.step<1) {
		this.setTransition(this.images[this.index], this.step + 1);
		this.setTransition(this.images[this.next], this.step);
	}
	else {
		clearInterval(this.timer);
		this.images[this.index].style.visibility = 'hidden';
		this.images[this.next].style.visibility = 'visible';
		this.setTransition(this.images[this.next], 1);
		this.index = this.next;
		setTimeout(this.startTransition.bind(this), this.delay);
	}
}

SlideShow.prototype.setTransition = function(e, step) {
	if(this.type=='v') e.style.top = this.height - Math.round(this.height * step) + 'px';
	else if(this.type=='h') e.style.left = this.width - Math.round(this.width * step) + 'px';
	else if(this.type=='o') {
		var opc = Math.round(100 * (step>1 ? 2-step : step));
		if(!!(window.attachEvent && !window.opera)) {
			e.style.zoom = 1;
			e.style.filter = "alpha(opacity=" + opc + ")";
		}
  		else {
			e.style.opacity = opc/100;
  		}
	}
}