function Scroller(id) {
	this.container = document.getElementById(id),
	this.selector = document.createElement('div'),
	this.pages = this.container.children[0],
	this.scroller = this.pages.children[0],
	this.numOfPages = this.scroller.children.length,
	this.curPage = 0,
	this.speed = 50,		// in milliseconds
	this.smooth = 2,		// in milliseconds
	this.step = Math.round(this.speed / this.smooth),
	this.slideshowPause = 5000,		// in milliseconds
	this.slideshowTimeout,

	this.scroll = function(step, maxScroll, count) {
		if (typeof count === 'undefined') {
			count = 1;
		}

		if (count === this.step || Math.abs(maxScroll - this.pages.scrollLeft) < step) {
			this.pages.scrollLeft = maxScroll;
			return;
		} else if (this.pages.scrollLeft > maxScroll) {		// scroll left
			this.pages.scrollLeft = this.pages.scrollLeft - step;
		} else {		// scroll right
			this.pages.scrollLeft += step;
		}

		var thisScroller = this;
		setTimeout(function() { thisScroller.scroll(step, maxScroll, ++count); }, this.smooth);
	}

	this.showItem = function(num) {
		var newScrollLeft = (this.container.offsetWidth * num);

		clearTimeout(this.slideshowTimeout);		// stop the slideshow

		if (num < this.curPage) {		// scroll left
			this.scroll(Math.ceil(((this.pages.scrollLeft - newScrollLeft) / this.step)), newScrollLeft);
		} else {		// scroll right
			this.scroll(Math.ceil(((newScrollLeft - this.pages.scrollLeft) / this.step)), newScrollLeft);
		}

		// change the current page selector
		this.selector.children[this.curPage].className = 'selector';
		this.curPage = num;
		this.selector.children[this.curPage].className += ' current';

		/*// start slideshow
		var thisObj = this;
		this.slideshowTimeout = setTimeout(function() { thisObj.slideshow(); }, this.slideshowPause);*/
	}

	this.slideshow = function() {
		// stop highlighting the current page
		this.selector.children[this.curPage].className = 'selector';

		if (this.curPage === (this.numOfPages - 1)) {		// go back to first page
			this.curPage = 0;
			this.scroll(Math.ceil((this.pages.scrollLeft / this.step)), 0);
		} else {		// scroll right
			this.curPage++;
			var newScrollLeft = (this.container.offsetWidth * this.curPage);
			this.scroll(Math.ceil(((newScrollLeft - this.pages.scrollLeft) / this.step)), newScrollLeft);
		}

		// change the current page selector
		this.selector.children[this.curPage].className += ' current';

		// start the process all over again
		var thisObj = this;
		this.slideshowTimeout = setTimeout(function() { thisObj.slideshow(); }, this.slideshowPause);
	}

	// DO THE FOLLOWING WHEN A NEW SCROLLER IS CREATED
	var selectorElem;

	this.selector.setAttribute('class', 'selector_container');

	for (var i = 0; i < this.numOfPages; i++) {
		selectorElem = document.createElement('div');
		selectorElem.setAttribute('class', 'selector');
		selectorElem.scroller = this;
		selectorElem.page = i;
		selectorElem.onclick = function() { this.scroller.showItem(this.page); };

		this.selector.appendChild(selectorElem);
	}

	// change the size of the scroller to accomodate the pages
	this.scroller.style.width = (this.numOfPages * this.container.offsetWidth) + 'px';

	// make the first page the current page
	this.selector.children[0].className += ' current';

	// add page selectors to the container
	this.container.appendChild(this.selector);

	// start slideshow
	var thisObj = this;
	this.slideshowTimeout = setTimeout(function() { thisObj.slideshow(); }, this.slideshowPause);
}

