function HorizontalScroller(scrollerId, scrollerWidth, frameWidth)
{

	// Properties
	this.timerId;					
	this.scroller;  				
	this.scrollerId		= scrollerId;		// id of scroller
	this.scrollerWidth 	= scrollerWidth; 	// viewable width of scroller

	this.scrollTable;				// scroll <table> that holds all the frames
	this.scrollTablePosition = 0;
	this.totalFrames	= 0;		 		// total number of frames in table
	this.frameWidth 	= frameWidth; 		// width per frame
	this.wholeFramesInView;				// num of whole frames seen in the scroller at init
	this.partialFramesInView;			// num of partial frames seen in scroller at init (zero or one)
	this.wholeFramesNotInView;			// num of whoel frames not seen in scroller at init

	this.scrollableWidth;				// num of pixels scrolled before trigger frame swapping
	this.scrollSpeed	= 1;			// number of milliseconds;
	this.incrementPixels	= frameWidth;			// number of pixels to move a frame every this.scrollSpeed ms

	// Object methods
	this.initScroller 	= initScroller;
	this.scrollLeft		= scrollLeft;
	this.scrollRight	= scrollRight;
	//this.stop		= stop;
	this.swapFramesLeftToRight = swapFramesLeftToRight;
	this.swapFramesRightToLeft = swapFramesRightToLeft;
}


function initScroller()
{


	this.scroller = document.getElementById(this.scrollerId);
	this.scroller.style.width = this.scrollerWidth+'px';
	this.scroller.style.overflow = 'hidden';
	this.scroller.style.position = 'relative';

 	nodeList = document.getElementById(this.scroller.id).getElementsByTagName('ul');
	for(var c=0; c<nodeList.length; c++)
		if(nodeList[c].nodeType ==1)
			if(nodeList[c].nodeName.toLowerCase() == 'ul')
			{
				this.scrollTable = nodeList[c];
				c = nodeList.length+1;
			}

	this.scrollTable.style.position = 'relative';
    this.scrollTable.style.left = this.scrollTablePosition+'px';


	nodeList = this.scrollTable.getElementsByTagName('li');
	for(var d=nodeList.length-1; d>=0; d--)
		if(nodeList[d].nodeType==1)
			if(nodeList[d].nodeName.toLowerCase() == 'li')
			{
				nodeList[d].style.width = this.frameWidth;
				this.totalFrames++;
			}

    w = this.frameWidth*this.totalFrames;
	this.scrollTable.style.width = w+'px';

	this.wholeFramesInView = Math.floor(this.scrollerWidth/this.frameWidth);
	this.partialFramesInView = Math.ceil(this.scrollerWidth/this.frameWidth) - this.wholeFramesInView;
	this.wholeFramesNotInView = this.totalFrames - this.wholeFramesInView - this.partialFramesInView;

	this.scrollableWidth = this.wholeFramesNotInView*this.frameWidth;  

}


function scrollLeft(param){

	if(this.scrollTablePosition <0)
	{
		this.scrollTablePosition += this.incrementPixels;
	}
	else
	{
		this.scrollTablePosition = -1*this.scrollableWidth;
		this.scrollTablePosition += this.incrementPixels;
		this.swapFramesRightToLeft(this.wholeFramesNotInView);
	}

	this.scrollTable.style.left = this.scrollTablePosition + 'px';

}


function scrollRight(param)
{
	
	if(this.scrollTablePosition > -1*this.scrollableWidth)
	{
		this.scrollTablePosition -= this.incrementPixels;
	}
	else
	{
		this.scrollTablePosition = 0;
		this.scrollTablePosition -= this.incrementPixels;
		this.swapFramesLeftToRight(this.wholeFramesNotInView);
	}
	this.scrollTable.style.left = this.scrollTablePosition + 'px';

}



function swapFramesLeftToRight(numFrames)
{
	nodeList = this.scrollTable.getElementsByTagName('li');

	tempList = new Array();

	for(var d=0; d<nodeList.length; d++)
		if(nodeList[d].nodeType==1)
			if(nodeList[d].nodeName.toLowerCase() == 'li')
			{
				tempList[tempList.length] = nodeList[d];

				if(tempList.length >= numFrames) d = nodeList.length;
			}

	for(var c=0; c<numFrames; c++)
		tempList[c].parentNode.appendChild(tempList[c]);

}


function swapFramesRightToLeft(numFrames){

	nodeList = this.scrollTable.getElementsByTagName('li');

	tempList = new Array();

	for(var d=nodeList.length-1; d>=0; d--)
		if(nodeList[d].nodeType==1)
			if(nodeList[d].nodeName.toLowerCase() == 'li')
			{
				tempList[tempList.length] = nodeList[d];
				if(tempList.length >= numFrames) d= -1;
			}

	for(var c=0; c<numFrames; c++)
		tempList[c].parentNode.insertBefore(tempList[c], tempList[c].parentNode.firstChild);

}


//Instantiated HorizontalScroller Function
var scroll = new HorizontalScroller('scroller',259,259);

