function Slide(containerId, prevBtnId, nextBtnId) {
    this.currentOffset = 0;
    this.targetOffset = 0;
    this.animTimer = null;

    // Init
    this.ie6 = (navigator.userAgent.indexOf('MSIE 6') != -1);
    this.prev = document.getElementById(prevBtnId);
    this.next = document.getElementById(nextBtnId);
    var container = document.getElementById(containerId);
    this.slides = container.children[0];
    this.slideWidth = container.clientWidth;
    this.slides.style.width = (this.slides.children.length * container.clientWidth) + "px";
    this.slides.style.height = container.clientHeight + "px";
    this.slides.style.left = "0px";
    if (this.ie6) {
	for(var c = 1; c < this.slides.children.length; c++) {
	    this.slides.children[c].style.display = 'none';
	}
    } else {
	this.slides.style.position = 'relative';
    }
    this.slideIndex = 0;
    this.lastSlide = this.slides.children.length - 1;
    this.checkButtonStates();
    // setTimeout use
    if (window._slides === undefined) {
	window._slides = new Array();
    }
    window._slides.push(this);
    this.slideNum = window._slides.length - 1;
}

Slide.animSlide = function(num) {
    // Called by setTimeout, so 'this' is a window object
    // use _slides array to retrieve the Slide object referred to by num
    var slide;
    slide = window._slides[num];
    if (slide.currentOffset < slide.targetOffset) {
	slide.currentOffset += (slide.targetOffset - slide.currentOffset)/3;
	slide.currentOffset = Math.ceil(slide.currentOffset);
	if (slide.currentOffset >= slide.targetOffset) {
	    slide.currentOffset = slide.targetOffset;
	} else {
	    slide.animTimer = setTimeout("Slide.animSlide("+slide.slideNum+");", 50);
	}
    }
    if (slide.currentOffset > slide.targetOffset) {
	slide.currentOffset -= (slide.currentOffset - slide.targetOffset)/3;
	slide.currentOffset = Math.floor(slide.currentOffset);
	if (slide.currentOffset <= slide.targetOffset) {
	    slide.currentOffset = slide.targetOffset;
	} else {
	    slide.animTimer = setTimeout("Slide.animSlide("+slide.slideNum+");", 50);
	}
    }
    slide.slides.style.left = slide.currentOffset + "px";
}
Slide.prototype.showSlide = function(num) {
    if (this.ie6) {
	for(var c = 0; c < this.slides.children.length; c++) {
	    if (c == num) {
		this.slides.children[c].style.display = 'block';
	    } else {
		this.slides.children[c].style.display = 'none';
	    }
	}
    } else {
	clearTimeout(this.animTimer);
	this.targetOffset = -this.slideWidth * num;
	this.animTimer = setTimeout("Slide.animSlide("+slide.slideNum+");", 50);
    }
    this.checkButtonStates();
}
Slide.prototype.showNext = function() {
    if (this.slideIndex < this.lastSlide) {
	this.slideIndex++;
	this.showSlide(this.slideIndex);
    }
}
Slide.prototype.showPrev = function() {
    if (this.slideIndex > 0) {
	this.slideIndex--;
	this.showSlide(this.slideIndex);
    }
}
Slide.prototype.checkButtonStates = function() {
    if (this.slideIndex == 0) {
	this.prev.style.visibility = 'hidden';
    } else if (this.slideIndex == this.lastSlide) {
	this.next.style.visibility = 'hidden';
    } else {
	this.prev.style.visibility = 'visible'
	this.next.style.visibility = 'visible';
    }
}

