var ContentScroller = function (interval, scrollDirection, wrapperElement) {
	
	this.interval = interval;
	this.speed = 1;
	this.scrollDirection = scrollDirection;
	
	this.wrapperElement = PP.getElementById(wrapperElement);
	this.elementList = this.wrapperElement.getElementsByTagName('div');
	this.numUniqueElements = this.elementList.length;
	
	// Work out how many elements will show when it first loads the page
	this.firstElements = [];
	this.numOnFirstShowElements = Math.floor(PP.Util.getElementWidth(this.wrapperElement.parentNode) / PP.Util.getElementWidth(this.elementList.item(0)));
	
	// Take a copy of the first couple of child nodes so we can append to the end
	for(var i = 0; i < this.numOnFirstShowElements; i++)
		this.firstElements[i] = this.elementList.item(i).cloneNode(true);
	
	// Add in the taken child nodes to the end of the wrapper div
	for(var i = 0; i < this.firstElements.length; i++)
		this.wrapperElement.appendChild(this.firstElements[i]);
	
	// Repopulate the list again with the updated nodes
	this.elementList = this.wrapperElement.getElementsByTagName('div');
	
	// Set width of wrapper div by getting the width of all link tags
	this.wrapperElement.style.width = (PP.Util.getElementWidth(this.elementList.item(0)) * this.elementList.length) + 'px';
	
	// Add in pause and unpause events
	var _this = this;
	for(var i = 0; i < this.elementList.length; i++) {
		
		this.elementList.item(i).setAttribute('style', 'float:' + this.scrollDirection + ';');
		
		PP.Util.attachEvent(this.elementList.item(i), 'mouseover', function() {
			_this.pause();
		});
		
		PP.Util.attachEvent(this.elementList.item(i), 'mouseout', function() {
			_this.start();
		});
		
	}
	
	this.start = function() {
		
		var _this = this;
		this.intervalId = setInterval(function() {
			_this.move();
		}, this.interval);
		
	}
	
	this.move = function() {
		
		var singleElementWidth = PP.Util.getElementWidth(this.elementList.item(0));
		
		if(this.scrollDirection == 'right') {
			
			var startPosition = '-' + this.numUniqueElements * singleElementWidth + 'px';
			var endPosition = '0px';
			
			if(this.wrapperElement.style.left == '')
				this.wrapperElement.style.left = startPosition;
			
			if( this.wrapperElement.style.left == endPosition )
				this.wrapperElement.style.left = startPosition;
			else
				this.wrapperElement.style.left = (parseInt(this.wrapperElement.style.left) + this.speed) + 'px';
			
		}
		
		else if(this.scrollDirection == 'left') {
			
			var startPosition = '0px';
			var endPosition = this.numUniqueElements * singleElementWidth + 'px';
			
			if(this.wrapperElement.style.right == '')
				this.wrapperElement.style.right = startPosition;
			
			if( this.wrapperElement.style.right == endPosition )
				this.wrapperElement.style.right = startPosition;
			else
				this.wrapperElement.style.right = (parseInt(this.wrapperElement.style.right) + this.speed) + 'px';
			
		}
		
		
	}
	
	this.pause = function() {
		clearInterval(this.intervalId);
	}
	
}
