function ThumbnailListInit(parent_id, width, height, margin, count, thumbnails)
{
	var parentWidth = ((width + (margin * 2)) * count);
	var containerWidth = ((width + (margin * 2)) * thumbnails.length);
	
	var parent = document.getElementById(parent_id);
	
	parent.style.width = parentWidth + 'px';
	parent.style.height = height + 'px';
	parent.style.display = 'block';
	parent.style.position = 'relative';
	parent.style.overflow = 'hidden';
	
	var container = document.createElement('div');
	
	container.style.width = ((width + (margin * 2)) * thumbnails.length) + 'px';
	container.style.height = height + 'px';
	container.style.display = 'block';
	container.style.position = 'relative';
	container.style.left = '0px';
	
	parent.appendChild(container);
	
	for (var i = 0; i < thumbnails.length; ++i)
	{
		var anchor = document.createElement('a');
		
		anchor.setAttribute('href', thumbnails[i]['href']);
		anchor.setAttribute('id', parent.id + 'Anchor' + i);
		
		anchor.style.width = width + 'px';
		anchor.style.height = height + 'px';
		anchor.style.margin = '0 ' + margin + 'px';
		//anchor.style.float = 'left';				
		
		var image = document.createElement('img');
		
		image.setAttribute('src', thumbnails[i]['img']);
		image.setAttribute('id', parent.id + 'Image' + i);
		
		image.style.width = width + 'px';
		image.style.height = height + 'px';
		image.style.border = 'none';
		//image.style.float = 'left';
	
		anchor.appendChild(image);
		container.appendChild(anchor);
	}
	
	
	var scrollRate = -4;
	
	EventRegister(parent, 'mouseover', MouseMove, false);
	EventRegister(parent, 'mouseout', MouseOut, false);
	EventRegister(parent, 'mousemove', MouseMove, false);
	
	parent.update = Update;
	
	window.setInterval("ThumbnailUpdate('" + parent_id + "')", 100);
	
	function MouseMove(theEvent)
	{
		var eventPositionX;
		
		if (theEvent.offsetX)
		{
			if (theEvent.target)
				eventPositionX = (theEvent.offsetX + PositionX(theEvent.target) - PositionX(parent));
			else
				eventPositionX = (theEvent.offsetX + PositionX(theEvent.srcElement) - PositionX(parent));
		}
		else
		{
			eventPositionX = theEvent.pageX - PositionX(parent);
		}

		if (eventPositionX < (parentWidth / 9))
			scrollRate = 4;
		else if (eventPositionX < ((parentWidth / 9) * 2))
			scrollRate = 3;
		else if (eventPositionX < ((parentWidth / 9) * 3))
			scrollRate = 2;
		else if (eventPositionX < ((parentWidth / 9) * 4))
			scrollRate = 1;
		else if (eventPositionX < ((parentWidth / 9) * 5))
			scrollRate = 0;
		else if (eventPositionX < ((parentWidth / 9) * 6))
			scrollRate = -1;
		else if (eventPositionX < ((parentWidth / 9) * 7))
			scrollRate = -2;
		else if (eventPositionX < ((parentWidth / 9) * 8))
			scrollRate = -3;
		else if (eventPositionX < parentWidth)
			scrollRate = -4;
	}
	
	function MouseOut(theEvent)
	{
		scrollRate = 0;
	}
	
	function Update()
	{
		var containerPosition = parseInt(container.style.left);
		
		containerPosition += (scrollRate * 2);
		
		if ((containerPosition + containerWidth) < parentWidth)
			containerPosition = (parentWidth - containerWidth);
		else if (containerPosition > 0)
			containerPosition = 0;
			
		container.style.left = containerPosition + 'px';
		
	}
}

function ThumbnailUpdate(parent_id)
{
	var parent = document.getElementById(parent_id);
	
	parent.update();
}

function EventRegister(object, eventName, handler, capture)
{
	if (object)
	{
		if (object.addEventListener)
			object.addEventListener(eventName, handler, capture);
		else if (object.attachEvent)
			object.attachEvent('on' + eventName, handler);
	}
}

function EventStopPropagation(theEvent)
{
	if (theEvent.stopPropagation)
		theEvent.stopPropagation();
	else
		theEvent.cancelBubbel = true;
	
	if (theEvent.preventDefault)
		theEvent.preventDefault();
	else
		theEvent.returnValue = false;
}

function PositionX(object)
{
	var positionX = 0;
	
	if (object.offsetParent)
	{
		while (1) 
		{
			positionX += object.offsetLeft;
			
			if(! object.offsetParent)
				break;
			
			object = object.offsetParent;
		}
	}
	else if (object.x)
	{
		positionX += object.x;
	}
	
	return positionX;
}

