function Timeline() {
	this.HTMLObject = document.getElementById('timeline');
	this.speed = 3;
	this.xPos = 0;
	this.viewportWidth = 508;
	this.singleObjWidth = 101;
	this.singleObjMargin = 3;
	this.width = this.getLength();
	this.minXPos = 0 - (this.width - this.viewportWidth);
	this.scrolling = null;
	this.leftButton = document.getElementById('time_left');
	this.leftButton.timeline = this;
	this.leftButton.onmouseover = this.scrollLeft;
	this.rightButton = document.getElementById('time_right');
	this.rightButton.timeline = this;
	this.rightButton.onmouseover = this.scrollRight;
	this.leftButton.onmouseout = this.rightButton.onmouseout = this.stopScrolling;
}

Timeline.prototype.init = function (currentActive) {
	var entries = this.HTMLObject.getElementsByTagName('div');
	for (var i = 0; i < entries.length; i++) {
		if ((i+1) == currentActive) {
			entries[i].className = 'selected';
		} else {
			entries[i].onmouseover = function () {this.className = 'selected'}
			entries[i].onmouseout = function () {this.className = ''}
			entries[i].href = entries[i].getElementsByTagName('a')[0];
			entries[i].onclick = function () {document.location.href = this.href}
		}
	}
	this.scrollTo(currentActive);
}

Timeline.prototype.getLength = function () {
	var entries = this.HTMLObject.getElementsByTagName('div');
	return (entries.length * this.singleObjWidth + this.singleObjMargin);
}

Timeline.prototype.scrollLeft = function () {
	scrollFunc = this.timeline.scrollLeftWrapper(this.timeline)
	this.timeline.scrolling = setInterval(scrollFunc, 10);
}

Timeline.prototype.scrollLeftWrapper = function (timeline) {
	return (function(){
		timeline.stepLeft();
    });
}

Timeline.prototype.scrollRight = function () {
	scrollFunc = this.timeline.scrollRightWrapper(this.timeline)
	this.timeline.scrolling = setInterval(scrollFunc, 10);
}

Timeline.prototype.scrollRightWrapper = function (timeline) {
	return (function(){
		timeline.stepRight();
    });
}

Timeline.prototype.stopScrolling = function () {
	clearInterval(this.timeline.scrolling)
}

Timeline.prototype.stepLeft = function () {
	if (this.xPos >= 0) {
		clearInterval(this.scrolling);
		return;
	}
	this.xPos += this.speed;
	this.HTMLObject.style.left = this.xPos + "px";	
}

Timeline.prototype.stepRight = function () {
	if (this.xPos <= this.minXPos) {
		clearInterval(this.scrolling);
		return;
	}
	this.xPos -= this.speed;
	this.HTMLObject.style.left = this.xPos + "px";
}

Timeline.prototype.scrollTo = function (element) {
	this.xPos = 0 - ((element - 1) * this.singleObjWidth) + (2 * this.singleObjWidth);
	if (this.xPos >= 0) this.xPos = 0;
	if (this.xPos <= this.minXPos) this.xPos = this.minXPos;
	this.HTMLObject.style.left = this.xPos + "px";
}

