function scrollbox() {

	var items = $('#scrollbox').html();
	$('#scrollbox').replaceWith('<div id="scrollbox-container"><div id="scrollbox-pane"><ul>'+items+'</ul></div><a class="prev" href="#">Prev</a><a class="next" href="#">Next</a></div>');
	
	$('#scrollbox-container a.prev').click(function() {
		var itemWidth = totalWidth('#scrollbox-pane li:first');	
		var scrollBoxWidth = $('#scrollbox-pane').width();
		var scrollPosition = parseInt($('#scrollbox-pane ul').css("margin-left"), 10);
				
		var countItems = $('#scrollbox-pane li').length;
		var maxItems = Math.floor(scrollBoxWidth / itemWidth);
		var scrolledItems = Math.abs(scrollPosition / itemWidth);
		var animation = scrollPosition / itemWidth;
		
		if(scrolledItems > 0 && animation == Math.floor(animation)) {
			var scrollPositionNew = scrollPosition + itemWidth;
			$('#scrollbox-pane ul').animate(
				{ marginLeft: scrollPositionNew },
				'normal',
				'swing'
			);
		}
		return false;								
	});
	
	$('#scrollbox-container a.next').click(function() {
		var itemWidth = totalWidth('#scrollbox-pane li:first');	
		var scrollBoxWidth = $('#scrollbox-pane').width();
		var scrollPosition = parseInt($('#scrollbox-pane ul').css("margin-left"), 10);
		
		var countItems = $('#scrollbox-pane li').length;
		var maxItems = Math.floor(scrollBoxWidth / itemWidth);
		var scrolledItems = Math.abs(scrollPosition / itemWidth);
		var animation = scrollPosition / itemWidth;
		
		if(scrolledItems < countItems - maxItems && animation == Math.floor(animation)) {
			var scrollPositionNew = scrollPosition - itemWidth;
			$('#scrollbox-pane ul').animate(
				{ marginLeft: scrollPositionNew },
				'normal',
				'swing'
			);
		}
		return false;								
	});
	
	return false;
}

function totalWidth(id) {
	var item = $(id);
	var itemWidth = item.width();
	itemWidth += parseInt(item.css('padding-left'), 10) + parseInt(item.css('padding-right'), 10);
	itemWidth += parseInt(item.css('margin-left'), 10) + parseInt(item.css('margin-right'), 10);
	itemWidth += parseInt(item.css('borderLeftWidth'), 10) + parseInt(item.css('borderRightWidth'), 10);
	return itemWidth;
}